https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127364

            Bug ID: 127364
           Summary: __builtin_assoc_barrier does not works in arm neon
           Product: gcc
           Version: 16.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: z00823823 at outlook dot com
  Target Milestone: ---

```c++
#include <arm_neon.h>

float32x4_t round_values(float32x4_t x) {
    const float32x4_t big = vdupq_n_f32(0x1p24f);
    const float32x4_t sum = __builtin_assoc_barrier(vaddq_f32(x, big));
    return vsubq_f32(sum, big);
}
```

compile with `-O2 -ffast-math`, it compiles to nothing, meaning gcc incorrectly
re-associates the add and sub operation.

however, on x86_64, similar code:

```c++
#include <immintrin.h>

__m128 with_barrier(__m128 x) {
    const __m128 big = _mm_set1_ps(0x1p24f);
    const __m128 sum =
        __builtin_assoc_barrier(_mm_add_ps(x, big));
    return _mm_sub_ps(sum, big);
}
```

compile with `-O2 -ffast-math`, it compiles to

```asm
"with_barrier(float vector[4])":
        movss   xmm1, DWORD PTR .LC1[rip]
        shufps  xmm1, xmm1, 0
        addps   xmm0, xmm1
        movss   xmm1, DWORD PTR .LC3[rip]
        shufps  xmm1, xmm1, 0
        addps   xmm0, xmm1
        ret
```

the add and sub operation is retained, correctly.

https://gcc.godbolt.org/z/YrY3bdaE7

Reply via email to