Skip to content

[RISC-V] Miscompile on rv64gcv with -O[23] #132071

@ewlu

Description

@ewlu

Testcase:

short a[12];
short b[12];
long long al;
int f;
short m = 31554;
long long q[12];
int main() {
  for (int i = 0; i < 2; ++i)
    q[i] = 6;
  for (short i = 0; i < 12; i += m - 31553) {
    a[i] = q[i];
    b[i] = f > q[i];
  }
  for (int i = 0; i < 12; ++i)
    al += a[i];
  for (int i = 0; i < 2; ++i)
    al += b[i];
  __builtin_printf("%llu\n", al);
}

Commands:

# riscv
$ ./bin/clang -march=rv64gcv_zvl256b -flto -O2 red.c -o user-config.out
$ QEMU_CPU=rv64,vlen=256,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 ./bin/qemu-riscv64 user-config.out 1
10

$ ./bin/clang -march=rv64gcv_zvl256b -flto -O3 red.c -o user-config.out
$ QEMU_CPU=rv64,vlen=256,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 ./bin/qemu-riscv64 user-config.out 1
10

# x86
$ ./native.out 1
12

Godbolt: https://godbolt.org/z/7hMW6eerT

Tried changing m - 31553 to 1 and the error disappears

Bisected to 9b7282e as the first bad commit

Found via fuzzer

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions