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

            Bug ID: 124870
           Summary: arm: MVE load/store with writeback intrinsics do not
                    model memory accesses
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: clyon at gcc dot gnu.org
          Reporter: clyon at gcc dot gnu.org
  Target Milestone: ---
            Target: arm

Since the *_gather_base_wb_* (load) and *_scatter_base_wb_* (store) MVE
intrinsics have been re-implemented using the new framework, they do not
implement call_properties() correctly.

Indeed, since they both read and write their first parameter (__addr).

This leads to wrong code, because instructions can be reordered incorrectly.

For instance:
#include <arm_mve.h>

void fn (int n, uint32_t *strides, float32_t *f)
{
    uint32x4_t vecScGathAddr = vld1q_u32(strides);
    float32x4_t vecA = vldrwq_gather_base_wb_f32(&vecScGathAddr, 64);
    float32x4_t vecB = vecA;
    for (int i = 0; i < n; ++i)
    {
        vecA = vldrwq_gather_base_wb_f32(&vecScGathAddr, 64);
        vecB = vaddq_f32 (vecB, vecA);
    }
    vstrwq_f32 (f, vecB);
}

generates with GCC trunk (compiled with -mcpu=cortex-m55 -mfloat-abi=hard -O2):
fn:
  vldrw.32 q3, [r1]
  push {lr}
  sub sp, sp, #20
  vstrw.32 q3, [sp]
  vldrw.u32 q2, [q3, #64]!
  cmp r0, #0
  vstrw.32 q3, [sp]
  ble .L2
  cmp r0, #1
  vadd.f32 q2, q2, q2        ; <====================
  beq .L2
  add lr, r0, #-1
  dls lr, lr
.L3:
  vldrw.32 q3, [sp]
  vldrw.u32 q1, [q3, #64]!  ; <====================
  vstrw.32 q3, [sp]
  vadd.f32 q2, q2, q1
  le lr, .L3
.L2:
  vstrw.32 q2, [r2]
  add sp, sp, #20
  pop {pc}

where the vadd.f32 instruction is incorrectly re-ordered before vldrw.u32

Reply via email to