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