2018-02-09 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / gcc / testsuite / gcc.target / sh / pr59533-1.c
blobb0469859df5b79d60a893c3f5bca490a7d65a1ae
1 /* Check that the cmp/pz instruction is generated as expected. */
2 /* { dg-do compile } */
3 /* { dg-options "-O1" } */
5 /* { dg-final { scan-assembler-times "shll" 1 } } */
6 /* { dg-final { scan-assembler-times "movt" 5 } } */
7 /* { dg-final { scan-assembler-times "rotcl" 1 } } */
8 /* { dg-final { scan-assembler-times "and" 3 } } */
9 /* { dg-final { scan-assembler-times "extu.b" 5 } } */
11 /* { dg-final { scan-assembler-times "cmp/pz" 27 { target { ! sh2a } } } } */
12 /* { dg-final { scan-assembler-times "addc" 4 { target { ! sh2a } } } } */
13 /* { dg-final { scan-assembler-times "subc" 16 { target { ! sh2a } } } } */
15 /* { dg-final { scan-assembler-times "cmp/pz" 25 { target { sh2a } } } } */
16 /* { dg-final { scan-assembler-times "addc" 6 { target { sh2a } } } } */
17 /* { dg-final { scan-assembler-times "subc" 14 { target { sh2a } } } } */
18 /* { dg-final { scan-assembler-times "bld" 2 { target { sh2a } } } } */
20 int
21 test_00 (unsigned char* a)
23 /* 1x cmp/pz, 1x movt */
24 return a[0] < 128;
27 int
28 test_01 (unsigned char* a)
30 /* 1x cmp/pz, 1x addc */
31 return a[0] + (a[0] < 128);
34 int
35 test_02 (unsigned char* a)
37 /* 1x cmp/pz, 1x addc */
38 return a[0] + ((a[0] & 0x80) == 0);
41 int
42 test_03 (unsigned char* a)
44 /* 1x cmp/pz, 1x subc
45 SH2A: 1x bld, 1x addc */
46 return a[0] + (a[0] > 127);
49 int
50 test_04 (unsigned char* a)
52 /* 1x cmp/pz, 1x subc
53 SH2A: 1x bld, 1x addc */
54 return a[0] + ((a[0] & 0x80) != 0);
57 int
58 test_05 (unsigned char* a, int b, int c)
60 /* 1x cmp/pz */
61 if (a[0] < 128)
62 return c;
63 else
64 return b + 50;
67 unsigned int
68 test_06 (unsigned int a)
70 /* 1x cmp/pz, 1x movt */
71 return ~a >> 31;
74 int
75 test_07 (unsigned short* a)
77 /* 1x cmp/pz */
78 return a[0] < 32768;
81 int
82 test_08 (unsigned short* a)
84 /* 1x cmp/pz, 1x addc */
85 return a[0] + (a[0] < 32768);
88 unsigned int
89 test_09 (unsigned int a)
91 /* 1x cmp/pz, 1x movt */
92 return (a >> 31) ^ 1;
95 unsigned int
96 test_10 (unsigned int a, unsigned int b)
98 /* 1x cmp/pz, 1x rotcl */
99 return (a << 1) | ((a >> 31) ^ 1);
102 unsigned int
103 test_11 (int x)
105 /* 1x cmp/pz, 1x subc */
106 return ~(x >> 31);
109 unsigned int
110 test_12 (int x)
112 /* 1x cmp/pz, 1x subc */
113 return 0xFFFFFFFF - (x >> 31);
116 unsigned int
117 test_13 (int x)
119 /* 1x cmp/pz, 1x subc, 1x add */
120 return ~(x >> 31) << 1;
123 unsigned int
124 test_14 (int x)
126 /* 1x cmp/pz, 1x subc */
127 return ~(x >> 31) >> 1;
130 unsigned int
131 test_15 (int x)
133 /* 1x cmp/pz, 1x subc */
134 return ~(x >> 31) >> 31;
137 unsigned int
138 test_16 (int x)
140 /* 1x cmp/pz, 1x subc, 1x and */
141 return ~(x >> 31) & 0xFF000000;
144 unsigned int
145 test_17 (int x)
147 /* 1x cmp/pz, 1x subc, 1x and */
148 return ~(x >> 31) & 0x00FF0000;
151 unsigned int
152 test_18 (int x)
154 /* 1x cmp/pz, 1x subc, 1x and */
155 return ~(x >> 31) & 0x0000FF00;
158 unsigned int
159 test_19 (int x)
161 /* 1x cmp/pz, 1x subc, 1x extu.b */
162 return ~(x >> 31) & 0x000000FF;
165 unsigned int
166 test_20 (int x, unsigned int y, unsigned int z)
168 /* 1x shll */
169 return ~(x >> 31) ? y : z;
173 test_21 (int x)
175 /* 1x cmp/pz, 1x subc */
176 return x >= 0 ? 0xFFFFFFFF : 0;
180 test_22 (int x)
182 /* 1x cmp/pz, 1x movt */
183 return (x >> 31) + 1;
187 test_23 (int x)
189 /* 1x cmp/pz, 1x subc */
190 return x < 0 ? x + 1 : x;
193 unsigned int
194 test_24 (unsigned int x)
196 /* 1x cmp/pz, 1x subc */
197 return x & 0x80000000 ? x + 1 : x;
200 unsigned int
201 test_25 (unsigned int x)
203 /* 1x cmp/pz, 1x subc */
204 return x >> 31 ? x + 1 : x;
208 test_26 (int x)
210 /* 1x cmp/pz, 1x subc */
211 return x >> 31 ? x + 1 : x;
215 test_27 (int x, int y, int z)
217 /* 1x cmp/pz, 1x addc */
218 return 1 - ((x >> 4) < 0) + z;