Issue 115446
Summary [RISC-V] Possible Miscompilation by Indexed Segment Load-Store Intrinsics
Labels
Assignees
Reporter Yibo-He
    In the following code with rvv intrinsics, I load data from a to b.
The index of `__riscv_vsoxseg5ei8_v_f64m1x5` is obtained from the result of `__riscv_vid_v_u8mf8`(*=8), and i think the result should be the same with `__riscv_vsseg5e64_v_f64m1x5` (if this is a misunderstanding, please tell me).
However, values of vector a are not equal to values in vector b after the for loop.
```
#include <riscv_vector.h>
#define dataLen 20
uint8_t idx[dataLen];
double a[dataLen]; double b[dataLen];
int main(){
  for (int i = 0; i < dataLen; ++i) { a[i] = i * 10.0; }
  for (int i = 0; i < dataLen; ++i) { b[i] = 0; }
  int placeholder0 = dataLen;
  double* ptr_a = a;
  double* ptr_b = b;
  for (size_t vl; placeholder0 > 0; placeholder0 -= vl * 5){
    vl = __riscv_vsetvl_e64m1(placeholder0);
    vfloat64m1x5_t va = __riscv_vlseg5e64_v_f64m1x5(ptr_a, vl);
    vuint8mf8_t vidx = __riscv_vsll_vx_u8mf8(__riscv_vid_v_u8mf8(vl), 3, vl);
 __riscv_vsoxseg5ei8_v_f64m1x5(ptr_b, vidx, va, vl);
    ptr_a += vl * 5;
    ptr_b += vl * 5;
  }
  for(int i=0; i<dataLen; ++i){ if(a[i]!=b[i]){ __builtin_printf("a[%d]=%lf, b[%d]=%lf\n", i, a[i], i, b[i]); } }
  return 0;
}
```

Result:
```
a[1]=10.000000, b[1]=50.000000
a[2]=20.000000, b[2]=60.000000
a[3]=30.000000, b[3]=70.000000
a[4]=40.000000, b[4]=80.000000
a[5]=50.000000, b[5]=90.000000
a[6]=60.000000, b[6]=0.000000
a[7]=70.000000, b[7]=0.000000
a[8]=80.000000, b[8]=0.000000
a[9]=90.000000, b[9]=0.000000
a[11]=110.000000, b[11]=150.000000
a[12]=120.000000, b[12]=160.000000
a[13]=130.000000, b[13]=170.000000
a[14]=140.000000, b[14]=180.000000
a[15]=150.000000, b[15]=190.000000
a[16]=160.000000, b[16]=0.000000
a[17]=170.000000, b[17]=0.000000
a[18]=180.000000, b[18]=0.000000
a[19]=190.000000, b[19]=0.000000
```

The above results appear in LLVM 18.1.8 and 19.1.0 (with qemu 9.1.0).
```
$ clang --version
clang version 19.1.0
Target: riscv64-unknown-linux-gnu
Thread model: posix
InstalledDir: ...
$ qemu-riscv64 --version
qemu-riscv64 version 9.1.0
Copyright (c) 2003-2024 Fabrice Bellard and the QEMU Project developers
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to