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