Issue 117677
Summary [RISC-V] Clang Miscompiles Segment RVV Intrinsics
Labels clang
Assignees
Reporter rvismith-project
    Reduced test case:
```
#include <riscv_vector.h>
#define dataLen 12*8
int8_t a[dataLen]; int8_t b[dataLen];
int8_t c[dataLen]; int8_t d[dataLen];

int main(){
  for (int i = 0; i < dataLen; ++i) { a[i] = -i; }
  for (int i = 0; i < dataLen; ++i) { b[i] = i; }
  for (int i = 0; i < dataLen; ++i) { c[i] = 0; d[i] = 0; }
  int avl = dataLen;
  int8_t* ptr_a = a; int8_t* ptr_b = b;
  int8_t* ptr_c = c; int8_t* ptr_d = d;
  for (size_t vl; avl > 0; avl -= vl * 8){
    vl = __riscv_vsetvl_e8mf2(avl);
    vint8mf2_t va = __riscv_vle8_v_i8mf2(ptr_a, vl);
    __riscv_vse8_v_i8mf2(ptr_c, va, vl);
 vint8mf2x8_t vb = __riscv_vlseg8e8_v_i8mf2x8(ptr_b, vl);
    vint8mf2_t vd = __riscv_vget_v_i8mf2x8_i8mf2(vb, 0);
    __riscv_vse8_v_i8mf2(ptr_d, vd, vl);
    ptr_a += vl; ptr_c += vl; ptr_d += vl;
    ptr_b += vl * 8;
  }
 for(int i=0; i<dataLen; ++i) { __builtin_printf("%d ", d[i]); } __builtin_printf("\n");
  return 0;
}
```

Result:
```
$ clang -march=rv64gcv_zvfh -mabi=lp64d -Wno-psabi -static -O0 1.c -o a.out && qemu-riscv64 a.out
0 8 16 24 32 40 48 56 64 72 80 88 0 -8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

$ clang -march=rv64gcv_zvfh -mabi=lp64d -Wno-psabi -static -O3 1.c -o a.out && qemu-riscv64 a.out
0 8 16 24 32 40 48 56 64 72 80 88 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

```

Clang version under test: ["17.0.6", "18-init", "18.1.8", "19-init", "19.1.4", "20-init"]
QEMU version: 9.1.0
```
$ clang --version
clang version 19.1.4 (https://github.com/llvm/llvm-project.git aadaa00de76ed0c4987b97450dd638f63a385bed)
Target: riscv64-unknown-unknown-elf
Thread model: posix
InstalledDir: /home/compiler/llvm/19.1.4/bin
$ qemu-riscv64 --version
qemu-riscv64 version 9.1.0
Copyright (c) 2003-2024 Fabrice Bellard and the QEMU Project developers
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to