1 /* Copyright (C) 2009  Free Software Foundation.
2 
3    Test things that should block GCC from optimizing compile-time
4    constants passed to a builtin complex transcendental functions.
5 
6    Origin: Kaveh R. Ghazi,  January 28, 2009.  */
7 
8 /* { dg-do compile } */
9 /* { dg-options "-fdump-tree-original" } */
10 
11 extern void foof (_Complex float);
12 extern void foo (_Complex double);
13 extern void fool (_Complex 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, ARG0, ARG1) do { \
22   foof (__builtin_##FUNC##f (ARG0##F, ARG1##F)); \
23   foo (__builtin_##FUNC (ARG0, ARG1)); \
24   fool (__builtin_##FUNC##l (ARG0##L, ARG1##L)); \
25 } while (0)
26 
bar()27 void bar()
28 {
29   /* An argument of NaN is not evaluated at compile-time.  */
30 #ifndef __SPU__
31   foof (__builtin_csqrtf (__builtin_nanf("")));
32 #endif
33   foo (__builtin_csqrt (__builtin_nan("")));
34   fool (__builtin_csqrtl (__builtin_nanl("")));
35 
36   /* An argument of Inf/-Inf is not evaluated at compile-time.  */
37 #ifndef __SPU__
38   foof (__builtin_csqrtf (__builtin_inff()));
39 #endif
40   foo (__builtin_csqrt (__builtin_inf()));
41   fool (__builtin_csqrtl (__builtin_infl()));
42 #ifndef __SPU__
43   foof (__builtin_csqrtf (-__builtin_inff()));
44 #endif
45   foo (__builtin_csqrt (-__builtin_inf()));
46   fool (__builtin_csqrtl (-__builtin_infl()));
47 
48   /* Check for overflow/underflow.  */
49   TESTIT (cexp, 1e20);
50   TESTIT (cexp, -1e20);
51 
52   /* An argument of NaN is not evaluated at compile-time.  */
53 #ifndef __SPU__
54   foof (__builtin_cpowf (__builtin_nanf(""), 2.5F));
55 #endif
56   foo (__builtin_cpow (__builtin_nan(""), 2.5));
57   fool (__builtin_cpowl (__builtin_nanl(""), 2.5L));
58 #ifndef __SPU__
59   foof (__builtin_cpowf (2.5F, __builtin_nanf("")));
60 #endif
61   foo (__builtin_cpow (2.5, __builtin_nan("")));
62   fool (__builtin_cpowl (2.5L, __builtin_nanl("")));
63 
64   /* An argument of Inf/-Inf is not evaluated at compile-time.  */
65 #ifndef __SPU__
66   foof (__builtin_cpowf (__builtin_inff(), 2.5F));
67 #endif
68   foo (__builtin_cpow (__builtin_inf(), 2.5));
69   fool (__builtin_cpowl (__builtin_infl(), 2.5L));
70 #ifndef __SPU__
71   foof (__builtin_cpowf (-__builtin_inff(), 2.5F));
72 #endif
73   foo (__builtin_cpow (-__builtin_inf(), 2.5));
74   fool (__builtin_cpowl (-__builtin_infl(), 2.5L));
75 #ifndef __SPU__
76   foof (__builtin_cpowf (2.5F, __builtin_inff()));
77 #endif
78   foo (__builtin_cpow (2.5, __builtin_inf()));
79   fool (__builtin_cpowl (2.5L, __builtin_infl()));
80 #ifndef __SPU__
81   foof (__builtin_cpowf (2.5F, -__builtin_inff()));
82 #endif
83   foo (__builtin_cpow (2.5, -__builtin_inf()));
84   fool (__builtin_cpowl (2.5L, -__builtin_infl()));
85 
86   /* Check for Inv/NaN return values.  */
87   TESTIT2 (cpow, -0.0, -4.5); /* Returns Inf */
88   TESTIT2 (cpow, 0.0, -4.5); /* Returns Inf */
89 
90   /* Check for overflow/underflow.  */
91   foof (__builtin_cpowf (__FLT_MAX__, 3.5F));
92   foof (__builtin_cpowf (__FLT_MAX__ * 1.FI, 3.5F));
93   foo (__builtin_cpow (__DBL_MAX__, 3.5));
94   foo (__builtin_cpow (__DBL_MAX__ * 1.I, 3.5));
95   fool (__builtin_cpowl (__LDBL_MAX__, 3.5L));
96   fool (__builtin_cpowl (__LDBL_MAX__ * 1.LI, 3.5L));
97   TESTIT2 (cpow, 2.0, 0x1p50);
98   TESTIT2 (cpow, 2.0, 0x1p28);
99   TESTIT2 (cpow, 2.0, 0x1p24);
100   foof (__builtin_cpowf (__FLT_MAX__, -3.5F));
101   foof (__builtin_cpowf (__FLT_MAX__ * 1.FI, -3.5F));
102   foo (__builtin_cpow (__DBL_MAX__, -3.5));
103   foo (__builtin_cpow (__DBL_MAX__ * 1.I, -3.5));
104   fool (__builtin_cpowl (__LDBL_MAX__, -3.5L));
105   fool (__builtin_cpowl (__LDBL_MAX__ * 1.LI, -3.5L));
106   TESTIT2 (cpow, 2.0, -0x1p50);
107   TESTIT2 (cpow, 2.0, -0x1p28);
108   TESTIT2 (cpow, 2.0, -0x1p24);
109 
110 }
111 
112 /* { dg-final { scan-tree-dump-times "csqrtf" 3 "original" { target { ! { spu*-*-* } } } } } */
113 /* { dg-final { scan-tree-dump-times "csqrtf" 0 "original" { target { spu*-*-* } } } } */
114 /* { dg-final { scan-tree-dump-times "csqrt " 3 "original" } } */
115 /* { dg-final { scan-tree-dump-times "csqrtl" 3 "original" } } */
116 /* { dg-final { scan-tree-dump-times "cexpf" 2 "original" } } */
117 /* { dg-final { scan-tree-dump-times "cexp " 2 "original" } } */
118 /* { dg-final { scan-tree-dump-times "cexpl" 2 "original" } } */
119 /* { dg-final { scan-tree-dump-times "cpowf" 18 "original" { target { ! { spu*-*-* } } } } } */
120 /* { dg-final { scan-tree-dump-times "cpowf" 12 "original" { target { spu*-*-* } } } } */
121 /* { dg-final { scan-tree-dump-times "cpow " 18 "original" } } */
122 /* { dg-final { scan-tree-dump-times "cpowl" 18 "original" } } */
123 /* { dg-final { cleanup-tree-dump "original" } } */
124