2018-02-09 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / gcc / testsuite / gcc.target / sh / pr52933-1.c
blob81aa94fc8f0de4ee42ca0fca06a1f62d0f137e3c
1 /* Check that the div0s instruction is used for integer sign comparisons.
2 Each test case is expected to emit at least one div0s insn.
3 Problems when combining the div0s comparison result with surrounding
4 logic usually show up as redundant tst insns. */
5 /* { dg-do compile } */
6 /* { dg-options "-O2" } */
7 /* { dg-final { scan-assembler-times "div0s" 42 } } */
8 /* { dg-final { scan-assembler-not "tst" } } */
9 /* { dg-final { scan-assembler-not "not\t" } } */
10 /* { dg-final { scan-assembler-not "nott" } } */
12 /* { dg-final { scan-assembler-times "negc" 10 { target { ! sh2a } } } } */
13 /* { dg-final { scan-assembler-times "movrt" 10 { target { sh2a } } } } */
15 typedef unsigned char bool;
17 int other_func_a (int, int);
18 int other_func_b (int, int);
20 bool
21 test_00 (int a, int b)
23 return (a ^ b) >= 0;
26 bool
27 test_01 (int a, int b)
29 return (a ^ b) < 0;
32 int
33 test_02 (int a, int b, int c, int d)
35 if ((a ^ b) < 0)
36 return other_func_a (a, c);
37 else
38 return other_func_b (d, b);
41 int
42 test_03 (int a, int b, int c, int d)
44 if ((a ^ b) >= 0)
45 return other_func_a (a, c);
46 else
47 return other_func_b (d, b);
50 int
51 test_04 (int a, int b)
53 return (a ^ b) >= 0 ? -20 : -40;
56 bool
57 test_05 (int a, int b)
59 return (a ^ b) < 0;
62 int
63 test_06 (int a, int b)
65 return (a ^ b) < 0 ? -20 : -40;
68 bool
69 test_07 (int a, int b)
71 return (a < 0) == (b < 0);
74 int
75 test_08 (int a, int b)
77 return (a < 0) == (b < 0) ? -20 : -40;
80 bool
81 test_09 (int a, int b)
83 return (a < 0) != (b < 0);
86 int
87 test_10 (int a, int b)
89 return (a < 0) != (b < 0) ? -20 : -40;
92 bool
93 test_11 (int a, int b)
95 return (a >= 0) ^ (b < 0);
98 int
99 test_12 (int a, int b)
101 return (a >= 0) ^ (b < 0) ? -20 : -40;
104 bool
105 test_13 (int a, int b)
107 return !((a >= 0) ^ (b < 0));
111 test_14 (int a, int b)
113 return !((a >= 0) ^ (b < 0)) ? -20 : -40;
116 bool
117 test_15 (int a, int b)
119 return (a & 0x80000000) == (b & 0x80000000);
123 test_16 (int a, int b)
125 return (a & 0x80000000) == (b & 0x80000000) ? -20 : -40;
128 bool
129 test_17 (int a, int b)
131 return (a & 0x80000000) != (b & 0x80000000);
135 test_18 (int a, int b)
137 return (a & 0x80000000) != (b & 0x80000000) ? -20 : -40;
141 test_19 (unsigned int a, unsigned int b)
143 return (a ^ b) >> 31;
147 test_20 (unsigned int a, unsigned int b)
149 return (a >> 31) ^ (b >> 31);
153 test_21 (int a, int b)
155 return ((a & 0x80000000) ^ (b & 0x80000000)) >> 31 ? -30 : -10;
159 test_22 (int a, int b, int c, int d)
161 if ((a < 0) == (b < 0))
162 return other_func_a (a, b);
163 else
164 return other_func_b (c, d);
167 bool
168 test_23 (int a, int b, int c, int d)
170 /* Should emit 2x div0s. */
171 return ((a < 0) == (b < 0)) | ((c < 0) == (d < 0));
174 bool
175 test_24 (int a, int b)
177 return a >= 0 != b >= 0;
180 bool
181 test_25 (int a, int b)
183 return !(a < 0 != b < 0);
187 test_26 (int a, int b, int c, int d)
189 return a >= 0 != b >= 0 ? c : d;
193 test_27 (int a, int b)
195 return a >= 0 == b >= 0;
199 test_28 (int a, int b, int c, int d)
201 return a >= 0 == b >= 0 ? c : d;
205 test_29 (int a, int b)
207 return ((a >> 31) ^ (b >= 0)) & 1;
211 test_30 (int a, int b)
213 return ((a >> 31) ^ (b >> 31)) & 1;
216 // -------------------------------------------------------
218 bool
219 test_31 (int a, int b)
221 /* 2x exts.w, div0s */
222 return ((a & 0x8000) ^ (b & 0x8000)) != 0;
225 bool
226 test_32 (int a, int b)
228 /* 2x exts.w, div0s */
229 return (a & 0x8000) != (b & 0x8000);
232 bool
233 test_33 (int a, int b)
235 /* 2x add/shll, div0s */
236 return ((a & (1<<30)) ^ (b & (1<<30))) != 0;
239 bool
240 test_34 (int a, int b)
242 /* 2x exts.b, div0s */
243 return (a & 0x80) != (b & 0x80);
246 bool
247 test_35 (signed char a, signed char b)
249 /* 2x exts.b, div0s */
250 return (a < 0) != (b < 0);
253 bool
254 test_36 (short a, short b)
256 /* 2x exts.w, div0s */
257 return (a < 0) != (b < 0);
261 test_37 (short a, short b)
263 /* 2x exts.w, div0s */
264 return (a < 0) != (b < 0) ? 40 : -10;
267 bool
268 test_38 (int a, int b)
270 /* 2x shll8, div0s */
271 return ((a & (1<<23)) ^ (b & (1<<23))) != 0;
274 bool
275 test_39 (int a, int b)
277 /* 2x shll2, div0s */
278 return ((a & (1<<29)) ^ (b & (1<<29))) != 0;
281 bool
282 test_40 (short a, short b)
284 /* 2x exts.w, div0s, negc */
285 return (a < 0) == (b < 0);