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