Require target lra in gcc.dg/pr108095.c
[official-gcc.git] / gcc / testsuite / c-c++-common / builtin-assoc-barrier-1.c
blob3ff324982cfd1c914f7a2760b42d1d419c9e7ffa
1 // { dg-options "-O2 -ffast-math" }
2 /* { dg-do run } */
4 float a = 1.f;
5 float b = 1.e20f;
7 float
8 fast()
10 return __builtin_assoc_barrier (a + b) - b;
13 __attribute__((optimize("-fno-associative-math")))
14 float
15 normal()
17 return a + b - b;
20 void test0()
22 if (fast() != normal())
23 __builtin_abort();
26 #ifdef __cplusplus
27 #ifdef __cpp_constexpr
28 constexpr float
29 pm(float x, float y)
31 return __builtin_assoc_barrier(x + y) - y;
34 template <int x>
35 constexpr int
36 f()
38 return x;
40 #endif
42 template <class T>
44 pm(T x, T y)
46 return __builtin_assoc_barrier(x + y) - y;
49 void test1()
51 if (pm(a, b) != normal())
52 __builtin_abort();
53 #ifdef __cpp_constexpr
54 constexpr float x = pm(1.f, 1.e20f);
55 constexpr int y = f<int(pm(1.f, 1.e20f))>();
56 if (x != normal())
57 __builtin_abort();
58 if (y != 0)
59 __builtin_abort();
60 #endif
62 #else
63 void test1() {}
64 #endif
66 int main()
68 test0();
69 test1();
70 return 0;