(root)/
gcc-13.2.0/
gcc/
testsuite/
c-c++-common/
builtin-assoc-barrier-1.c
       1  // { dg-options "-O2 -ffast-math" }
       2  /* { dg-do run } */
       3  
       4  float a = 1.f;
       5  float b = 1.e20f;
       6  
       7  float
       8  fast()
       9  {
      10    return __builtin_assoc_barrier (a + b) - b;
      11  }
      12  
      13  __attribute__((optimize("-fno-associative-math")))
      14  float
      15  normal()
      16  {
      17    return a + b - b;
      18  }
      19  
      20  void test0()
      21  {
      22    if (fast() != normal())
      23      __builtin_abort();
      24  }
      25  
      26  #ifdef __cplusplus
      27  #ifdef __cpp_constexpr
      28  constexpr float
      29  pm(float x, float y)
      30  {
      31    return __builtin_assoc_barrier(x + y) - y;
      32  }
      33  
      34  template <int x>
      35    constexpr int
      36    f()
      37    {
      38      return x;
      39    }
      40  #endif
      41  
      42  template <class T>
      43    T
      44    pm(T x, T y)
      45    {
      46      return __builtin_assoc_barrier(x + y) - y;
      47    }
      48  
      49  void test1()
      50  {
      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
      61  }
      62  #else
      63  void test1() {}
      64  #endif
      65  
      66  int main()
      67  {
      68    test0();
      69    test1();
      70    return 0;
      71  }