Debian Codegraph @

gcc/testsuite/gcc.target/sh/pr52933-1.c

raw
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" } } */
11
12 /* { dg-final { scan-assembler-times "negc" 10 { target { ! sh2a } } } } */
13 /* { dg-final { scan-assembler-times "movrt" 10 { target { sh2a } } } } */
14
15 typedef unsigned char mybool;
16
17 int other_func_a (int, int);
18 int other_func_b (int, int);
19
20 mybool
21 test_00 (int a, int b)
22 {
23 return (a ^ b) >= 0;
24 }
25
26 mybool
27 test_01 (int a, int b)
28 {
29 return (a ^ b) < 0;
30 }
31
32 int
33 test_02 (int a, int b, int c, int d)
34 {
35 if ((a ^ b) < 0)
36 return other_func_a (a, c);
37 else
38 return other_func_b (d, b);
39 }
40
41 int
42 test_03 (int a, int b, int c, int d)
43 {
44 if ((a ^ b) >= 0)
45 return other_func_a (a, c);
46 else
47 return other_func_b (d, b);
48 }
49
50 int
51 test_04 (int a, int b)
52 {
53 return (a ^ b) >= 0 ? -20 : -40;
54 }
55
56 mybool
57 test_05 (int a, int b)
58 {
59 return (a ^ b) < 0;
60 }
61
62 int
63 test_06 (int a, int b)
64 {
65 return (a ^ b) < 0 ? -20 : -40;
66 }
67
68 mybool
69 test_07 (int a, int b)
70 {
71 return (a < 0) == (b < 0);
72 }
73
74 int
75 test_08 (int a, int b)
76 {
77 return (a < 0) == (b < 0) ? -20 : -40;
78 }
79
80 mybool
81 test_09 (int a, int b)
82 {
83 return (a < 0) != (b < 0);
84 }
85
86 int
87 test_10 (int a, int b)
88 {
89 return (a < 0) != (b < 0) ? -20 : -40;
90 }
91
92 mybool
93 test_11 (int a, int b)
94 {
95 return (a >= 0) ^ (b < 0);
96 }
97
98 int
99 test_12 (int a, int b)
100 {
101 return (a >= 0) ^ (b < 0) ? -20 : -40;
102 }
103
104 mybool
105 test_13 (int a, int b)
106 {
107 return !((a >= 0) ^ (b < 0));
108 }
109
110 int
111 test_14 (int a, int b)
112 {
113 return !((a >= 0) ^ (b < 0)) ? -20 : -40;
114 }
115
116 mybool
117 test_15 (int a, int b)
118 {
119 return (a & 0x80000000) == (b & 0x80000000);
120 }
121
122 int
123 test_16 (int a, int b)
124 {
125 return (a & 0x80000000) == (b & 0x80000000) ? -20 : -40;
126 }
127
128 mybool
129 test_17 (int a, int b)
130 {
131 return (a & 0x80000000) != (b & 0x80000000);
132 }
133
134 int
135 test_18 (int a, int b)
136 {
137 return (a & 0x80000000) != (b & 0x80000000) ? -20 : -40;
138 }
139
140 int
141 test_19 (unsigned int a, unsigned int b)
142 {
143 return (a ^ b) >> 31;
144 }
145
146 int
147 test_20 (unsigned int a, unsigned int b)
148 {
149 return (a >> 31) ^ (b >> 31);
150 }
151
152 int
153 test_21 (int a, int b)
154 {
155 return ((a & 0x80000000) ^ (b & 0x80000000)) >> 31 ? -30 : -10;
156 }
157
158 int
159 test_22 (int a, int b, int c, int d)
160 {
161 if ((a < 0) == (b < 0))
162 return other_func_a (a, b);
163 else
164 return other_func_b (c, d);
165 }
166
167 mybool
168 test_23 (int a, int b, int c, int d)
169 {
170 /* Should emit 2x div0s. */
171 return ((a < 0) == (b < 0)) | ((c < 0) == (d < 0));
172 }
173
174 mybool
175 test_24 (int a, int b)
176 {
177 return a >= 0 != b >= 0;
178 }
179
180 mybool
181 test_25 (int a, int b)
182 {
183 return !(a < 0 != b < 0);
184 }
185
186 int
187 test_26 (int a, int b, int c, int d)
188 {
189 return a >= 0 != b >= 0 ? c : d;
190 }
191
192 int
193 test_27 (int a, int b)
194 {
195 return a >= 0 == b >= 0;
196 }
197
198 int
199 test_28 (int a, int b, int c, int d)
200 {
201 return a >= 0 == b >= 0 ? c : d;
202 }
203
204 int
205 test_29 (int a, int b)
206 {
207 return ((a >> 31) ^ (b >= 0)) & 1;
208 }
209
210 int
211 test_30 (int a, int b)
212 {
213 return ((a >> 31) ^ (b >> 31)) & 1;
214 }
215
216 // -------------------------------------------------------
217
218 mybool
219 test_31 (int a, int b)
220 {
221 /* 2x exts.w, div0s */
222 return ((a & 0x8000) ^ (b & 0x8000)) != 0;
223 }
224
225 mybool
226 test_32 (int a, int b)
227 {
228 /* 2x exts.w, div0s */
229 return (a & 0x8000) != (b & 0x8000);
230 }
231
232 mybool
233 test_33 (int a, int b)
234 {
235 /* 2x add/shll, div0s */
236 return ((a & (1<<30)) ^ (b & (1<<30))) != 0;
237 }
238
239 mybool
240 test_34 (int a, int b)
241 {
242 /* 2x exts.b, div0s */
243 return (a & 0x80) != (b & 0x80);
244 }
245
246 mybool
247 test_35 (signed char a, signed char b)
248 {
249 /* 2x exts.b, div0s */
250 return (a < 0) != (b < 0);
251 }
252
253 mybool
254 test_36 (short a, short b)
255 {
256 /* 2x exts.w, div0s */
257 return (a < 0) != (b < 0);
258 }
259
260 int
261 test_37 (short a, short b)
262 {
263 /* 2x exts.w, div0s */
264 return (a < 0) != (b < 0) ? 40 : -10;
265 }
266
267 mybool
268 test_38 (int a, int b)
269 {
270 /* 2x shll8, div0s */
271 return ((a & (1<<23)) ^ (b & (1<<23))) != 0;
272 }
273
274 mybool
275 test_39 (int a, int b)
276 {
277 /* 2x shll2, div0s */
278 return ((a & (1<<29)) ^ (b & (1<<29))) != 0;
279 }
280
281 mybool
282 test_40 (short a, short b)
283 {
284 /* 2x exts.w, div0s, negc */
285 return (a < 0) == (b < 0);
286 }