1 /* { dg-do compile } */
2 /* { dg-options "-O2 -fdump-tree-original" } */
3 
4 #include <limits.h>
5 
6 /* Original testcase from PR.  */
7 
foo1(short x)8 int foo1 (short x) {
9   return (double) x != 0;
10   /* { dg-final { scan-tree-dump "return (<retval> = )?x != 0" "original" } } */
11 }
12 
foo2(short x)13 int foo2 (short x) {
14   return (float) x != 0;
15   /* { dg-final { scan-tree-dump "return (<retval> = )?x != 0" "original" } } */
16 }
17 
foo3(int x)18 int foo3 (int x) {
19   return (double) x != 0;
20   /* { dg-final { scan-tree-dump "return (<retval> = )?x != 0" "original" } } */
21 }
22 
23 /* Tests when RHS is within range of integer type.  */
24 
in_range(unsigned short x)25 void in_range (unsigned short x)
26 {
27   {
28     volatile int in_range_1;
29     in_range_1 = (float) x > 100.0f;
30     /* { dg-final { scan-tree-dump "in_range_1 = x > 100" "original" } } */
31   }
32 
33   {
34     volatile int in_range_2;
35     in_range_2 = (float) x < 100.0f;
36     /* { dg-final { scan-tree-dump "in_range_2 = x <= 99" "original" } } */
37   }
38 
39   {
40     volatile int in_range_3;
41     in_range_3 = (float) x > 100.5f;
42     /* { dg-final { scan-tree-dump "in_range_3 = x (>= 101|> 100)" "original" } } */
43   }
44 
45   {
46     volatile int in_range_4;
47     in_range_4 = (float) x < 100.5f;
48     /* { dg-final { scan-tree-dump "in_range_4 = x <= 100" "original" } } */
49   }
50 
51   {
52     volatile int in_range_5;
53     in_range_5 = (float) x == 100.0f;
54     /* { dg-final { scan-tree-dump "in_range_5 = x == 100" "original" } } */
55   }
56 
57   {
58     volatile int in_range_6;
59     in_range_6 = (float) x != 100.0f;
60     /* { dg-final { scan-tree-dump "in_range_6 = x != 100" "original" } } */
61   }
62 
63   {
64     volatile int in_range_7;
65     in_range_7 = (float) x == 100.5f;
66     /* { dg-final { scan-tree-dump "in_range_7 = 0" "original" } } */
67   }
68 
69   {
70     volatile int in_range_8;
71     in_range_8 = (float) x != 100.5f;
72     /* { dg-final { scan-tree-dump "in_range_8 = 1" "original" } } */
73   }
74 }
75 
76 /* Tests for cases where RHS is out of range of integer type.  */
77 
out_range(unsigned short x)78 void out_range (unsigned short x)
79 {
80   {
81     volatile int out_range_1;
82     out_range_1 = (float) x > -100.5f;
83     /* { dg-final { scan-tree-dump "out_range_1 = 1" "original" } } */
84   }
85 
86   {
87     volatile int out_range_2;
88     out_range_2 = (float) x >= -100.5f;
89     /* { dg-final { scan-tree-dump "out_range_2 = 1" "original" } } */
90   }
91 
92   {
93     volatile int out_range_3;
94     out_range_3 = (float) x < -100.5f;
95     /* { dg-final { scan-tree-dump "out_range_3 = 0" "original" } } */
96   }
97 
98   {
99     volatile int out_range_4;
100     out_range_4 = (float) x <= -100.5f;
101     /* { dg-final { scan-tree-dump "out_range_4 = 0" "original" } } */
102   }
103 
104   {
105     volatile int out_range_5;
106     out_range_5 = (float) x == -100.5f;
107     /* { dg-final { scan-tree-dump "out_range_5 = 0" "original" } } */
108   }
109 
110   {
111     volatile int out_range_6;
112     out_range_6 = (float) x != -100.5f;
113     /* { dg-final { scan-tree-dump "out_range_6 = 1" "original" } } */
114   }
115 }
116 
117 /* Tests when RHS is at boundary of integer type.  */
118 
lo_bounds(unsigned short x)119 void lo_bounds (unsigned short x)
120 {
121   {
122     volatile int lo_bounds_1;
123     lo_bounds_1 = (float) x > 0x0;
124     /* { dg-final { scan-tree-dump "lo_bounds_1 = x (>|!=) 0" "original" } } */
125   }
126 
127   {
128     volatile int lo_bounds_2;
129     lo_bounds_2 = (float) x >= 0x0;
130     /* { dg-final { scan-tree-dump "lo_bounds_2 = 1" "original" } } */
131   }
132 
133   {
134     volatile int lo_bounds_3;
135     lo_bounds_3 = (float) x < 0x0;
136     /* { dg-final { scan-tree-dump "lo_bounds_3 = 0" "original" } } */
137   }
138 
139   {
140     volatile int lo_bounds_4;
141     lo_bounds_4 = (float) x <= 0x0;
142     /* { dg-final { scan-tree-dump "lo_bounds_4 = x (<=|==) 0" "original" } } */
143   }
144 
145   {
146     volatile int lo_bounds_5;
147     lo_bounds_5 = (float) x > 0x0 - 0.5f;
148     /* { dg-final { scan-tree-dump "lo_bounds_5 = 1" "original" } } */
149   }
150 
151   {
152     volatile int lo_bounds_6;
153     lo_bounds_6 = (float) x >= 0x0 - 0.5f;
154     /* { dg-final { scan-tree-dump "lo_bounds_6 = 1" "original" } } */
155   }
156 
157   {
158     volatile int lo_bounds_7;
159     lo_bounds_7 = (float) x < 0x0 - 0.5f;
160     /* { dg-final { scan-tree-dump "lo_bounds_7 = 0" "original" } } */
161   }
162 
163   {
164     volatile int lo_bounds_8;
165     lo_bounds_8 = (float) x <= 0x0 - 0.5f;
166     /* { dg-final { scan-tree-dump "lo_bounds_8 = 0" "original" } } */
167   }
168 
169   {
170     volatile int lo_bounds_9;
171     lo_bounds_9 = (float) x > 0x0 + 0.5f;
172     /* { dg-final { scan-tree-dump "lo_bounds_9 = x (>= 1|!= 0)" "original" } } */
173   }
174 
175   {
176     volatile int lo_bounds_10;
177     lo_bounds_10 = (float) x >= 0x0 + 0.5f;
178     /* { dg-final { scan-tree-dump "lo_bounds_10 = x (>= 1|!= 0)" "original" } } */
179   }
180 
181   {
182     volatile int lo_bounds_11;
183     lo_bounds_11 = (float) x < 0x0 + 0.5f;
184     /* { dg-final { scan-tree-dump "lo_bounds_11 = x (<=|==) 0" "original" } } */
185   }
186 
187   {
188     volatile int lo_bounds_12;
189     lo_bounds_12 = (float) x <= 0x0 + 0.5f;
190     /* { dg-final { scan-tree-dump "lo_bounds_12 = x (<=|==) 0" "original" } } */
191   }
192 }
193 
hi_bounds(unsigned short x)194 void hi_bounds (unsigned short x)
195 {
196   {
197     volatile int hi_bounds_1;
198     hi_bounds_1 = (float) x > USHRT_MAX;
199     /* { dg-final { scan-tree-dump "hi_bounds_1 = 0" "original" } } */
200   }
201 
202   {
203     volatile int hi_bounds_2;
204     hi_bounds_2 = (float) x >= USHRT_MAX;
205     /* { dg-final { scan-tree-dump "hi_bounds_2 = x (>=|==) 65535" "original" } } */
206   }
207 
208   {
209     volatile int hi_bounds_3;
210     hi_bounds_3 = (float) x < USHRT_MAX;
211     /* { dg-final { scan-tree-dump "hi_bounds_3 = x (<|!=) 65535" "original" } } */
212   }
213 
214   {
215     volatile int hi_bounds_4;
216     hi_bounds_4 = (float) x <= USHRT_MAX;
217     /* { dg-final { scan-tree-dump "hi_bounds_4 = 1" "original" } } */
218   }
219 
220   {
221     volatile int hi_bounds_5;
222     hi_bounds_5 = (float) x > USHRT_MAX - 0.5f;
223     /* { dg-final { scan-tree-dump "hi_bounds_5 = x (>=|==) 65535" "original" } } */
224   }
225 
226   {
227     volatile int hi_bounds_6;
228     hi_bounds_6 = (float) x >= USHRT_MAX - 0.5f;
229     /* { dg-final { scan-tree-dump "hi_bounds_6 = x (>=|==) 65535" "original" } } */
230   }
231 
232   {
233     volatile int hi_bounds_7;
234     hi_bounds_7 = (float) x < USHRT_MAX - 0.5f;
235     /* { dg-final { scan-tree-dump "hi_bounds_7 = x (<= 65534|!= 65535)" "original" } } */
236   }
237 
238   {
239     volatile int hi_bounds_8;
240     hi_bounds_8 = (float) x <= USHRT_MAX - 0.5f;
241     /* { dg-final { scan-tree-dump "hi_bounds_8 = x (<= 65534|!= 65535)" "original" } } */
242   }
243 
244   {
245     volatile int hi_bounds_9;
246     hi_bounds_9 = (float) x > USHRT_MAX + 0.5f;
247     /* { dg-final { scan-tree-dump "hi_bounds_9 = 0" "original" } } */
248   }
249 
250   {
251     volatile int hi_bounds_10;
252     hi_bounds_10 = (float) x >= USHRT_MAX + 0.5f;
253     /* { dg-final { scan-tree-dump "hi_bounds_10 = 0" "original" } } */
254   }
255 
256   {
257     volatile int hi_bounds_11;
258     hi_bounds_11 = (float) x < USHRT_MAX + 0.5f;
259     /* { dg-final { scan-tree-dump "hi_bounds_11 = 1" "original" } } */
260   }
261 
262   {
263     volatile int hi_bounds_12;
264     hi_bounds_12 = (float) x <= USHRT_MAX + 0.5f;
265     /* { dg-final { scan-tree-dump "hi_bounds_12 = 1" "original" } } */
266   }
267 }
268 
269 /* Tests with non-finite float consts.  */
270 
nonfinite(unsigned short x)271 void nonfinite (unsigned short x)
272 {
273 #define INFINITY __builtin_inff ()
274 
275   {
276     volatile int nonfinite_1;
277     nonfinite_1 = (float) x > INFINITY;
278     /* { dg-final { scan-tree-dump "nonfinite_1 = 0" "original" } } */
279   }
280 
281   {
282     volatile int nonfinite_2;
283     nonfinite_2 = (float) x >= INFINITY;
284     /* { dg-final { scan-tree-dump "nonfinite_2 = 0" "original" } } */
285   }
286 
287   {
288     volatile int nonfinite_3;
289     nonfinite_3 = (float) x < INFINITY;
290     /* { dg-final { scan-tree-dump "nonfinite_3 = 1" "original" } } */
291   }
292 
293   {
294     volatile int nonfinite_4;
295     nonfinite_4 = (float) x <= INFINITY;
296     /* { dg-final { scan-tree-dump "nonfinite_4 = 1" "original" } } */
297   }
298 
299   {
300     volatile int nonfinite_5;
301     nonfinite_5 = (float) x > -INFINITY;
302     /* { dg-final { scan-tree-dump "nonfinite_5 = 1" "original" } } */
303   }
304 
305   {
306     volatile int nonfinite_6;
307     nonfinite_6 = (float) x >= -INFINITY;
308     /* { dg-final { scan-tree-dump "nonfinite_6 = 1" "original" } } */
309   }
310 
311   {
312     volatile int nonfinite_7;
313     nonfinite_7 = (float) x < -INFINITY;
314     /* { dg-final { scan-tree-dump "nonfinite_7 = 0" "original" } } */
315   }
316 
317   {
318     volatile int nonfinite_8;
319     nonfinite_8 = (float) x <= -INFINITY;
320     /* { dg-final { scan-tree-dump "nonfinite_8 = 0" "original" } } */
321   }
322 
323 #define QNAN __builtin_nanf ("0")
324 
325   /* Even for qNaNs, only == and != are quiet.  */
326 
327   {
328     volatile int nonfinite_9;
329     nonfinite_9 = (float) x == QNAN;
330     /* { dg-final { scan-tree-dump "nonfinite_9 = 0" "original" } } */
331   }
332 
333   {
334     volatile int nonfinite_10;
335     nonfinite_10 = (float) x != QNAN;
336     /* { dg-final { scan-tree-dump "nonfinite_10 = 1" "original" } } */
337   }
338 }
339 
340 /* { dg-final { scan-tree-dump-not "\\(float\\)" "original" } } */
341 /* { dg-final { scan-tree-dump-not "\\(double\\)" "original" } } */
342