1 /* Copyright (C) 2006, 2007  Free Software Foundation.
2 
3    Test things that should block GCC from optimizing compile-time
4    constants passed to a builtin transcendental function.
5 
6    Origin: Kaveh R. Ghazi,  October 22, 2006.  */
7 
8 /* { dg-do compile } */
9 /* { dg-require-effective-target inf } */
10 /* { dg-options "-fdump-tree-original" } */
11 
12 extern void foof (float);
13 extern void foo (double);
14 extern void fool (long double);
15 
16 #define TESTIT(FUNC, ARG) do { \
17   foof (__builtin_##FUNC##f (ARG##F)); \
18   foo (__builtin_##FUNC (ARG)); \
19   fool (__builtin_##FUNC##l (ARG##L)); \
20 } while (0)
21 
22 #define TESTIT2(FUNC, ARG1, ARG2) do { \
23   foof (__builtin_##FUNC##f (ARG1##F, ARG2##F)); \
24   foo (__builtin_##FUNC (ARG1, ARG2)); \
25   fool (__builtin_##FUNC##l (ARG1##L, ARG2##L)); \
26 } while (0)
27 
28 #define TESTIT2_I1(FUNC, ARG1, ARG2) do { \
29   foof (__builtin_##FUNC##f (ARG1, ARG2##F)); \
30   foo (__builtin_##FUNC (ARG1, ARG2)); \
31   fool (__builtin_##FUNC##l (ARG1, ARG2##L)); \
32 } while (0)
33 
34 #define TESTIT2_I2ALL(FUNC, ARGF, MAXF, ARGD, MAXD, ARGLD, MAXLD) do { \
35   foof (__builtin_##FUNC##f (ARGF, MAXF)); \
36   foo (__builtin_##FUNC (ARGD, MAXD)); \
37   fool (__builtin_##FUNC##l (ARGLD, MAXLD)); \
38 } while (0)
39 
40 #define TESTIT2_I2(FUNC, ARG1, ARG2) do { \
41   foof (__builtin_##FUNC##f (ARG1##F, ARG2)); \
42   foo (__builtin_##FUNC (ARG1, ARG2)); \
43   fool (__builtin_##FUNC##l (ARG1##L, ARG2)); \
44 } while (0)
45 
46 #define TESTIT_REMQUO(ARG1, ARG2) do { \
47   int quo; \
48   foof (__builtin_remquof (ARG1##F, ARG2##F, &quo)); \
49   foo (__builtin_remquo (ARG1, ARG2, &quo)); \
50   fool (__builtin_remquol (ARG1##L, ARG2##L, &quo)); \
51 } while (0)
52 
53 #define TESTIT_REENT(FUNC,ARG1) do { \
54   int sg; \
55   foof (__builtin_##FUNC##f_r (ARG1##F, &sg)); \
56   foo (__builtin_##FUNC##_r (ARG1, &sg)); \
57   fool (__builtin_##FUNC##l_r (ARG1##L, &sg)); \
58 } while (0)
59 
bar()60 void bar()
61 {
62   /* An argument of NaN is not evaluated at compile-time.  */
63 #ifndef __SPU__
64   foof (__builtin_exp2f (__builtin_nanf("")));
65 #endif
66   foo (__builtin_exp2 (__builtin_nan("")));
67   fool (__builtin_exp2l (__builtin_nanl("")));
68 
69   /* An argument of Inf/-Inf is not evaluated at compile-time.  */
70 #ifndef __SPU__
71   foof (__builtin_exp2f (__builtin_inff()));
72 #endif
73   foo (__builtin_exp2 (__builtin_inf()));
74   fool (__builtin_exp2l (__builtin_infl()));
75 #ifndef __SPU__
76   foof (__builtin_exp2f (-__builtin_inff()));
77 #endif
78   foo (__builtin_exp2 (-__builtin_inf()));
79   fool (__builtin_exp2l (-__builtin_infl()));
80 
81   /* Result overflows MPFR, which in version 2.2.x has 30 exponent bits.  */
82   TESTIT (exp2, 0x1p50);
83   /* Result underflows MPFR, which in version 2.2.x has 30 exponent bits.  */
84   TESTIT (exp2, -0x1p50);
85 
86   /* Result overflows GCC's REAL_VALUE_TYPE, which has 26 exponent bits.  */
87   TESTIT (exp2, 0x1p28);
88   /* Result underflows GCC's REAL_VALUE_TYPE, which has 26 exponent bits.  */
89   TESTIT (exp2, -0x1p28);
90 
91   /* Result overflows (even an extended) C double's mode.  */
92   TESTIT (exp2, 0x1p24);
93   /* Result underflows (even an extended) C double's mode.  */
94   TESTIT (exp2, -0x1p24);
95 
96   /* Ensure that normal arguments/results are folded.  */
97   TESTIT (exp2, 1.5);
98   TESTIT (exp2, -1.5);
99 
100   /* The asin arg must be [-1 ... 1] inclusive.  */
101   TESTIT (asin, -1.5);
102   TESTIT (asin, 1.5);
103 
104   /* The acos arg must be [-1 ... 1] inclusive.  */
105   TESTIT (acos, -1.5);
106   TESTIT (acos, 1.5);
107 
108   /* The acosh arg must be [1 ... Inf] inclusive.  */
109   TESTIT (acosh, 0.5);
110 
111   /* The atanh arg must be [-1 ... 1] EXclusive.  */
112   TESTIT (atanh, -1.0);
113   TESTIT (atanh, 1.0);
114 
115   /* The log* arg must be [0 ... Inf] EXclusive.  */
116   TESTIT (log, -1.0);
117   TESTIT (log, 0.0);
118   TESTIT (log, -0.0);
119 
120   TESTIT (log2, -1.0);
121   TESTIT (log2, 0.0);
122   TESTIT (log2, -0.0);
123 
124   TESTIT (log10, -1.0);
125   TESTIT (log10, 0.0);
126   TESTIT (log10, -0.0);
127 
128   /* The log1p arg must be [-1 ... Inf] EXclusive.  */
129   TESTIT (log1p, -2.0);
130   TESTIT (log1p, -1.0);
131 
132   /* The tgamma arg errors with zero or negative integers.  */
133   TESTIT (tgamma, 0.0);
134   TESTIT (tgamma, -0.0);
135   TESTIT (tgamma, -1.0);
136   TESTIT (tgamma, -2.0);
137   TESTIT (tgamma, -3.0);
138 
139   /* An argument of NaN is not evaluated at compile-time.  */
140 #ifndef __SPU__
141   foof (__builtin_powf (__builtin_nanf(""), 2.5F));
142 #endif
143   foo (__builtin_pow (__builtin_nan(""), 2.5));
144   fool (__builtin_powl (__builtin_nanl(""), 2.5L));
145 #ifndef __SPU__
146   foof (__builtin_powf (2.5F, __builtin_nanf("")));
147 #endif
148   foo (__builtin_pow (2.5, __builtin_nan("")));
149   fool (__builtin_powl (2.5L, __builtin_nanl("")));
150 
151   /* An argument of Inf/-Inf is not evaluated at compile-time.  */
152 #ifndef __SPU__
153   foof (__builtin_powf (__builtin_inff(), 2.5F));
154 #endif
155   foo (__builtin_pow (__builtin_inf(), 2.5));
156   fool (__builtin_powl (__builtin_infl(), 2.5L));
157 #ifndef __SPU__
158   foof (__builtin_powf (-__builtin_inff(), 2.5F));
159 #endif
160   foo (__builtin_pow (-__builtin_inf(), 2.5));
161   fool (__builtin_powl (-__builtin_infl(), 2.5L));
162 #ifndef __SPU__
163   foof (__builtin_powf (2.5F, __builtin_inff()));
164 #endif
165   foo (__builtin_pow (2.5, __builtin_inf()));
166   fool (__builtin_powl (2.5L, __builtin_infl()));
167 #ifndef __SPU__
168   foof (__builtin_powf (2.5F, -__builtin_inff()));
169 #endif
170   foo (__builtin_pow (2.5, -__builtin_inf()));
171   fool (__builtin_powl (2.5L, -__builtin_infl()));
172 
173   /* Check for Inv/NaN return values.  */
174   TESTIT2 (pow, -0.0, -4.5); /* Returns Inf */
175   TESTIT2 (pow, 0.0, -4.5); /* Returns Inf */
176   TESTIT2 (pow, -3.0, -4.5); /* Returns NaN */
177 
178   /* Check for overflow/underflow.  */
179   foof (__builtin_powf (__FLT_MAX__, 3.5F));
180   foo (__builtin_pow (__DBL_MAX__, 3.5));
181   fool (__builtin_powl (__LDBL_MAX__, 3.5L));
182   TESTIT2 (pow, 2.0, 0x1p50);
183   foof (__builtin_powf (__FLT_MAX__, -3.5F));
184   foo (__builtin_pow (__DBL_MAX__, -3.5));
185   fool (__builtin_powl (__LDBL_MAX__, -3.5L));
186   TESTIT2 (pow, 2.0, -0x1p50);
187 
188   /* The sqrt arg must be [0 ... Inf] inclusive.  */
189   TESTIT (sqrt, -0.5);
190   TESTIT (sqrt, -0.0);
191   TESTIT (sqrt, 0.0);
192 
193   /* Check for overflow/underflow.  */
194 
195   /* These adjustments are too big.  */
196 #define FLT_EXP_ADJ (2*(__FLT_MAX_EXP__-__FLT_MIN_EXP__)+1)
197 #define DBL_EXP_ADJ (2*(__DBL_MAX_EXP__-__DBL_MIN_EXP__)+1)
198 #define LDBL_EXP_ADJ (2*(__LDBL_MAX_EXP__-__LDBL_MIN_EXP__)+1)
199 
200   TESTIT2_I2 (ldexp, 1.0, __INT_MAX__);
201   TESTIT2_I2 (ldexp, 1.0, -__INT_MAX__-1);
202   TESTIT2_I2 (ldexp, -1.0, __INT_MAX__);
203   TESTIT2_I2 (ldexp, -1.0, -__INT_MAX__-1);
204   TESTIT2_I2ALL (ldexp, __FLT_MIN__, FLT_EXP_ADJ, __DBL_MIN__,
205 		 DBL_EXP_ADJ, __LDBL_MIN__, LDBL_EXP_ADJ);
206   TESTIT2_I2ALL (ldexp, __FLT_MAX__, -FLT_EXP_ADJ, __DBL_MAX__,
207 		 -DBL_EXP_ADJ, __LDBL_MAX__, -LDBL_EXP_ADJ);
208   TESTIT2_I2ALL (ldexp, __FLT_MIN__, __FLT_MIN_EXP__, __DBL_MIN__,
209 		 __DBL_MIN_EXP__, __LDBL_MIN__, __LDBL_MIN_EXP__);
210   TESTIT2_I2ALL (ldexp, __FLT_MAX__, __FLT_MAX_EXP__, __DBL_MAX__,
211 		 __DBL_MAX_EXP__, __LDBL_MAX__, __LDBL_MAX_EXP__);
212 
213   TESTIT2_I2 (scalbn, 1.0, __INT_MAX__);
214   TESTIT2_I2 (scalbn, 1.0, -__INT_MAX__-1);
215   TESTIT2_I2 (scalbn, -1.0, __INT_MAX__);
216   TESTIT2_I2 (scalbn, -1.0, -__INT_MAX__-1);
217   TESTIT2_I2ALL (scalbn, __FLT_MIN__, FLT_EXP_ADJ, __DBL_MIN__,
218 		 DBL_EXP_ADJ, __LDBL_MIN__, LDBL_EXP_ADJ);
219   TESTIT2_I2ALL (scalbn, __FLT_MAX__, -FLT_EXP_ADJ, __DBL_MAX__,
220 		 -DBL_EXP_ADJ, __LDBL_MAX__, -LDBL_EXP_ADJ);
221   TESTIT2_I2ALL (scalbn, __FLT_MIN__, __FLT_MIN_EXP__, __DBL_MIN__,
222 		 __DBL_MIN_EXP__, __LDBL_MIN__, __LDBL_MIN_EXP__);
223   TESTIT2_I2ALL (scalbn, __FLT_MAX__, __FLT_MAX_EXP__, __DBL_MAX__,
224 		 __DBL_MAX_EXP__, __LDBL_MAX__, __LDBL_MAX_EXP__);
225 
226   TESTIT2_I2 (scalbln, 1.0, __LONG_MAX__);
227   TESTIT2_I2 (scalbln, 1.0, -__LONG_MAX__-1);
228   TESTIT2_I2 (scalbln, -1.0, __LONG_MAX__);
229   TESTIT2_I2 (scalbln, -1.0, -__LONG_MAX__-1);
230   TESTIT2_I2ALL (scalbln, __FLT_MIN__, FLT_EXP_ADJ, __DBL_MIN__,
231 		 DBL_EXP_ADJ, __LDBL_MIN__, LDBL_EXP_ADJ);
232   TESTIT2_I2ALL (scalbln, __FLT_MAX__, -FLT_EXP_ADJ, __DBL_MAX__,
233 		 -DBL_EXP_ADJ, __LDBL_MAX__, -LDBL_EXP_ADJ);
234   TESTIT2_I2ALL (scalbln, __FLT_MIN__, __FLT_MIN_EXP__, __DBL_MIN__,
235 		 __DBL_MIN_EXP__, __LDBL_MIN__, __LDBL_MIN_EXP__);
236   TESTIT2_I2ALL (scalbln, __FLT_MAX__, __FLT_MAX_EXP__, __DBL_MAX__,
237 		 __DBL_MAX_EXP__, __LDBL_MAX__, __LDBL_MAX_EXP__);
238 
239   TESTIT (logb, 0.0);
240   TESTIT (logb, -0.0);
241 
242   TESTIT (ilogb, 0.0);
243   TESTIT (ilogb, -0.0);
244 
245 #ifndef __SPU__
246   foof (__builtin_ilogbf (__builtin_inff()));
247 #endif
248   foo (__builtin_ilogb (__builtin_inf()));
249   fool (__builtin_ilogbl (__builtin_infl()));
250 #ifndef __SPU__
251   foof (__builtin_ilogbf (-__builtin_inff()));
252 #endif
253   foo (__builtin_ilogb (-__builtin_inf()));
254   fool (__builtin_ilogbl (-__builtin_infl()));
255 
256 #ifndef __SPU__
257   foof (__builtin_ilogbf (__builtin_nanf("")));
258 #endif
259   foo (__builtin_ilogb (__builtin_nan("")));
260   fool (__builtin_ilogbl (__builtin_nanl("")));
261 #ifndef __SPU__
262   foof (__builtin_ilogbf (-__builtin_nanf("")));
263 #endif
264   foo (__builtin_ilogb (-__builtin_nan("")));
265   fool (__builtin_ilogbl (-__builtin_nanl("")));
266 
267   /* The y* arg must be [0 ... Inf] EXclusive.  */
268   TESTIT (y0, -1.0);
269   TESTIT (y0, 0.0);
270   TESTIT (y0, -0.0);
271 
272   TESTIT (y1, -1.0);
273   TESTIT (y1, 0.0);
274   TESTIT (y1, -0.0);
275 
276   TESTIT2_I1 (yn, 2, -1.0);
277   TESTIT2_I1 (yn, 2, 0.0);
278   TESTIT2_I1 (yn, 2, -0.0);
279 
280   TESTIT2_I1 (yn, -3, -1.0);
281   TESTIT2_I1 (yn, -3, 0.0);
282   TESTIT2_I1 (yn, -3, -0.0);
283 
284   /* The second argument of remquo/remainder/drem must not be 0.  */
285   TESTIT_REMQUO (1.0, 0.0);
286   TESTIT_REMQUO (1.0, -0.0);
287   TESTIT2 (remainder, 1.0, 0.0);
288   TESTIT2 (remainder, 1.0, -0.0);
289   TESTIT2 (drem, 1.0, 0.0);
290   TESTIT2 (drem, 1.0, -0.0);
291 
292   /* The argument to lgamma* cannot be zero or a negative integer.  */
293   TESTIT_REENT (lgamma, -4.0); /* lgamma_r */
294   TESTIT_REENT (lgamma, -3.0); /* lgamma_r */
295   TESTIT_REENT (lgamma, -2.0); /* lgamma_r */
296   TESTIT_REENT (lgamma, -1.0); /* lgamma_r */
297   TESTIT_REENT (lgamma, -0.0); /* lgamma_r */
298   TESTIT_REENT (lgamma, 0.0); /* lgamma_r */
299 
300   TESTIT_REENT (gamma, -4.0); /* gamma_r */
301   TESTIT_REENT (gamma, -3.0); /* gamma_r */
302   TESTIT_REENT (gamma, -2.0); /* gamma_r */
303   TESTIT_REENT (gamma, -1.0); /* gamma_r */
304   TESTIT_REENT (gamma, -0.0); /* gamma_r */
305   TESTIT_REENT (gamma, 0.0); /* gamma_r */
306 }
307 
308 /* { dg-final { scan-tree-dump-times "exp2 " 9 "original" } } */
309 /* { dg-final { scan-tree-dump-times "exp2f" 9 "original" { target { ! { spu*-*-* } } } } } */
310 /* { dg-final { scan-tree-dump-times "exp2f" 6 "original" { target { spu*-*-* } } } } */
311 /* { dg-final { scan-tree-dump-times "exp2l" 9 "original" } } */
312 /* { dg-final { scan-tree-dump-times "asin " 2 "original" } } */
313 /* { dg-final { scan-tree-dump-times "asinf" 2 "original" } } */
314 /* { dg-final { scan-tree-dump-times "asinl" 2 "original" } } */
315 /* { dg-final { scan-tree-dump-times "acos " 2 "original" } } */
316 /* { dg-final { scan-tree-dump-times "acosf" 2 "original" } } */
317 /* { dg-final { scan-tree-dump-times "acosl" 2 "original" } } */
318 /* { dg-final { scan-tree-dump-times "acosh " 1 "original" } } */
319 /* { dg-final { scan-tree-dump-times "acoshf" 1 "original" } } */
320 /* { dg-final { scan-tree-dump-times "acoshl" 1 "original" } } */
321 /* { dg-final { scan-tree-dump-times "atanh " 2 "original" } } */
322 /* { dg-final { scan-tree-dump-times "atanhf" 2 "original" } } */
323 /* { dg-final { scan-tree-dump-times "atanhl" 2 "original" } } */
324 /* { dg-final { scan-tree-dump-times "log " 3 "original" } } */
325 /* { dg-final { scan-tree-dump-times "logf" 3 "original" } } */
326 /* { dg-final { scan-tree-dump-times "logl" 3 "original" } } */
327 /* { dg-final { scan-tree-dump-times "log2 " 3 "original" } } */
328 /* { dg-final { scan-tree-dump-times "log2f" 3 "original" } } */
329 /* { dg-final { scan-tree-dump-times "log2l" 3 "original" } } */
330 /* { dg-final { scan-tree-dump-times "log10 " 3 "original" } } */
331 /* { dg-final { scan-tree-dump-times "log10f" 3 "original" } } */
332 /* { dg-final { scan-tree-dump-times "log10l" 3 "original" } } */
333 /* { dg-final { scan-tree-dump-times "log1p " 2 "original" } } */
334 /* { dg-final { scan-tree-dump-times "log1pf" 2 "original" } } */
335 /* { dg-final { scan-tree-dump-times "log1pl" 2 "original" } } */
336 /* { dg-final { scan-tree-dump-times "tgamma " 5 "original" } } */
337 /* { dg-final { scan-tree-dump-times "tgammaf" 5 "original" } } */
338 /* { dg-final { scan-tree-dump-times "tgammal" 5 "original" } } */
339 /* { dg-final { scan-tree-dump-times "pow " 13 "original" } } */
340 /* { dg-final { scan-tree-dump-times "powf" 13 "original" { target { ! { spu*-*-* } } } } } */
341 /* { dg-final { scan-tree-dump-times "powf" 7 "original" { target { spu*-*-* } } } } */
342 /* { dg-final { scan-tree-dump-times "powl" 13 "original" } } */
343 /* { dg-final { scan-tree-dump-times "sqrt " 1 "original" } } */
344 /* { dg-final { scan-tree-dump-times "sqrtf" 1 "original" } } */
345 /* { dg-final { scan-tree-dump-times "sqrtl" 1 "original" } } */
346 /* { dg-final { scan-tree-dump-times "ldexp " 8 "original" } } */
347 /* { dg-final { scan-tree-dump-times "ldexpf" 8 "original" } } */
348 /* { dg-final { scan-tree-dump-times "ldexpl" 8 "original" } } */
349 /* { dg-final { scan-tree-dump-times "scalbn " 8 "original" } } */
350 /* { dg-final { scan-tree-dump-times "scalbnf" 8 "original" } } */
351 /* { dg-final { scan-tree-dump-times "scalbnl" 8 "original" } } */
352 /* { dg-final { scan-tree-dump-times "scalbln " 8 "original" } } */
353 /* { dg-final { scan-tree-dump-times "scalblnf" 8 "original" } } */
354 /* { dg-final { scan-tree-dump-times "scalblnl" 8 "original" } } */
355 /* { dg-final { scan-tree-dump-times "_logb " 2 "original" } } */
356 /* { dg-final { scan-tree-dump-times "_logbf" 2 "original" } } */
357 /* { dg-final { scan-tree-dump-times "_logbl" 2 "original" } } */
358 /* { dg-final { scan-tree-dump-times "ilogb " 6 "original" } } */
359 /* { dg-final { scan-tree-dump-times "ilogbf" 6 "original" { target { ! { spu*-*-* } } } } } */
360 /* { dg-final { scan-tree-dump-times "ilogbf" 2 "original" { target { spu*-*-* } } } } */
361 /* { dg-final { scan-tree-dump-times "ilogbl" 6 "original" } } */
362 /* { dg-final { scan-tree-dump-times "y0 " 3 "original" } } */
363 /* { dg-final { scan-tree-dump-times "y0f" 3 "original" } } */
364 /* { dg-final { scan-tree-dump-times "y0l" 3 "original" } } */
365 /* { dg-final { scan-tree-dump-times "y1 " 3 "original" } } */
366 /* { dg-final { scan-tree-dump-times "y1f" 3 "original" } } */
367 /* { dg-final { scan-tree-dump-times "y1l" 3 "original" } } */
368 /* { dg-final { scan-tree-dump-times "yn " 6 "original" } } */
369 /* { dg-final { scan-tree-dump-times "ynf" 6 "original" } } */
370 /* { dg-final { scan-tree-dump-times "ynl" 6 "original" } } */
371 /* { dg-final { scan-tree-dump-times "remquo " 2 "original" } } */
372 /* { dg-final { scan-tree-dump-times "remquof" 2 "original" } } */
373 /* { dg-final { scan-tree-dump-times "remquol" 2 "original" } } */
374 /* { dg-final { scan-tree-dump-times "remainder " 2 "original" } } */
375 /* { dg-final { scan-tree-dump-times "remainderf" 2 "original" } } */
376 /* { dg-final { scan-tree-dump-times "remainderl" 2 "original" } } */
377 /* { dg-final { scan-tree-dump-times "drem " 2 "original" } } */
378 /* { dg-final { scan-tree-dump-times "dremf" 2 "original" } } */
379 /* { dg-final { scan-tree-dump-times "dreml" 2 "original" } } */
380 /* { dg-final { scan-tree-dump-times "lgamma_r " 6 "original" } } */
381 /* { dg-final { scan-tree-dump-times "lgammaf_r" 6 "original" } } */
382 /* { dg-final { scan-tree-dump-times "lgammal_r" 6 "original" } } */
383 /* { dg-final { scan-tree-dump-times "_gamma_r " 6 "original" } } */
384 /* { dg-final { scan-tree-dump-times "_gammaf_r" 6 "original" } } */
385 /* { dg-final { scan-tree-dump-times "_gammal_r" 6 "original" } } */
386