llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[RISC-V] Miscompile in rv64gcv with -O3 -flto

Open ewlu opened this issue 1 year ago • 2 comments

Testcase:

short a;
long long q;
short d = 22032;
char h = 88;
char k[25];
int main() {
  for (int l = 0; l < 25; ++l)
    k[l] = 9;
  for (int l = 0; l < d - 22007; l += 4)
    for (short m = 0; m < h - 63; m += 3)
      a += k[m] != k[l];
  q = a;
  __builtin_printf("%llu\n", q);
}

Commands:

# riscv
$ /scratch/ewlu/daily-upstream-build/build-gcv/bin/clang -march=rv64gcv -flto -O3 red.c -o user-config.out
$ QEMU_CPU=rv64,vlen=128,rvv_ta_all_1s=true,rvv_ma_all_1s=true,v=true,vext_spec=v1.0,zve32f=true,zve64f=true timeout --verbose -k 0.1 4 /scratch/ewlu/daily-upstream-build/build-gcv/bin/qemu-riscv64 user-config.out 1
9

$ /scratch/ewlu/daily-upstream-build/build-gcv/bin/clang -march=rv64gcv -flto -O2 red.c -o user-config.out 
$ QEMU_CPU=rv64,vlen=128,rvv_ta_all_1s=true,rvv_ma_all_1s=true,v=true,vext_spec=v1.0,zve32f=true,zve64f=true timeout --verbose -k 0.1 4 /scratch/ewlu/daily-upstream-build/build-gcv/bin/qemu-riscv64 user-config.out 1
0

# x86
$ ./native.out
0

Bisected to ff8f6abe20a9dfbb1de8d978f865092413d3416c as first bad commit.

Replacing d - 22007 with 25 or h - 63 with 25 prevents the error from occurring. -flto also appears to be mandatory here too

I don't know if this is could also be related to #134126? Both the commit messages seem to be lowering shuffles for vla code.

Found via fuzzer

ewlu avatar Apr 07 '25 18:04 ewlu

@llvm/issue-subscribers-backend-risc-v

Author: Edwin Lu (ewlu)

Testcase: ```c short a; long long q; short d = 22032; char h = 88; char k[25]; int main() { for (int l = 0; l < 25; ++l) k[l] = 9; for (int l = 0; l < d - 22007; l += 4) for (short m = 0; m < h - 63; m += 3) a += k[m] != k[l]; q = a; __builtin_printf("%llu\n", q); } ```

Commands:

# riscv
$ /scratch/ewlu/daily-upstream-build/build-gcv/bin/clang -march=rv64gcv -flto -O3 red.c -o user-config.out
$ QEMU_CPU=rv64,vlen=128,rvv_ta_all_1s=true,rvv_ma_all_1s=true,v=true,vext_spec=v1.0,zve32f=true,zve64f=true timeout --verbose -k 0.1 4 /scratch/ewlu/daily-upstream-build/build-gcv/bin/qemu-riscv64 user-config.out 1
9

$ /scratch/ewlu/daily-upstream-build/build-gcv/bin/clang -march=rv64gcv -flto -O2 red.c -o user-config.out 
$ QEMU_CPU=rv64,vlen=128,rvv_ta_all_1s=true,rvv_ma_all_1s=true,v=true,vext_spec=v1.0,zve32f=true,zve64f=true timeout --verbose -k 0.1 4 /scratch/ewlu/daily-upstream-build/build-gcv/bin/qemu-riscv64 user-config.out 1
0

# x86
$ ./native.out
0

Bisected to ff8f6abe20a9dfbb1de8d978f865092413d3416c as first bad commit.

Replacing d - 22007 with 25 or h - 63 with 25 prevents the error from occurring. -flto also appears to be mandatory here too

I don't know if this is could also be related to #134126? Both the commit messages seem to be lowering shuffles for vla code.

Found via fuzzer

llvmbot avatar Apr 07 '25 19:04 llvmbot

This is very likely to be fixed by https://github.com/llvm/llvm-project/pull/134750. Please reopen if not.

preames avatar Apr 08 '25 14:04 preames