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

            Bug ID: 117314
           Summary: [RISC-V] Miscompilation triggered by segment
                    load-store, GCC 14.2.0 at `-O0`.
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yibohe at pku dot edu.cn
  Target Milestone: ---

Created attachment 59455
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59455&action=edit
reduced testcase

For the following code with rvv intrinsics, I load data from a to c.
However, GCC 14.2.0 (-O0) seems to change the data in d.
```
#include <riscv_vector.h>
#define dataLen 10
uint8_t a[dataLen]; uint8_t b[dataLen]; uint8_t c[dataLen];
uint16_t d[dataLen];

int main(){
  uint8_t tmp_a[dataLen] = {100, 190, 114, 140, 221, 89, 187, 126, 23, 111, };
  uint8_t tmp_b[dataLen] = {156, 34, 101, 205, 99, 78, 193, 205, 220, 3, };
  for (int i = 0; i < dataLen; ++i) { a[i] = tmp_a[i]; }
  for (int i = 0; i < dataLen; ++i) { b[i] = tmp_b[i]; }
  for (int i = 0; i < dataLen; ++i) { d[i] = 0; }
  for (int i = 0; i < dataLen; ++i) { c[i] = 0; }
  int placeholder0 = dataLen;
  uint8_t* ptr_a = a; uint8_t* ptr_b = b; uint8_t* ptr_c = c;
  for (size_t vl; placeholder0 > 0; placeholder0 -= vl * 7){
    vl = __riscv_vsetvl_e8m1(placeholder0);
    vuint8m1x7_t vreg_memory_10 = __riscv_vlseg7e8_v_u8m1x7(ptr_a, vl);
    __riscv_vsseg7e8_v_u8m1x7(ptr_c, vreg_memory_10, vl);
    ptr_a += vl * 7; ptr_b += vl * 7; ptr_c += vl * 7;
  }
  for(int i=0; i<dataLen; ++i) if(d[i]!=0) { __builtin_printf("fail: d[%d](%d)
!= 0\n", i, d[i]); }
  return 0;
}
```

The code failed on GCC 14.2.0 and qemu 9.1.0.
```
$ riscv64-unknown-elf-gcc --version
riscv64-unknown-elf-gcc () 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ qemu-riscv64 --version
qemu-riscv64 version 9.1.0
Copyright (c) 2003-2024 Fabrice Bellard and the QEMU Project developers
```

Link to the Compiler Explorer: https://godbolt.org/z/vWo7nfxvM

Reply via email to