https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121781
Bug ID: 121781 Summary: [Trunk] RISC-V rv64gcv: miscompile at -O1/O2 Product: gcc Version: 16.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: xxs_chy at outlook dot com Target Milestone: --- GCC version: gcc version 16.0.0 20250903 (experimental) (gbda76b479) Testcase: #include <stdint.h> #include <stdio.h> typedef int16_t a; typedef uint16_t b; typedef b c __attribute__((vector_size(8))); typedef a d __attribute__((vector_size(8))); typedef b e __attribute__((vector_size(16))); int f[10]; uint16_t g, l, k; int32_t j; int32_t m(uint32_t, const uint32_t *); int32_t *n(uint64_t, uint8_t); uint8_t o() { int p = 7; m(p, 0); return 0; } int32_t m(uint32_t, const uint32_t *) { int32_t q = l; n(q, 0); return k; } int32_t *n(uint64_t, uint8_t) { c r = {1, 6, 8, 30}; d s = {}; e u; int *t = &f[7]; for (j = 9; j; j--) { *t ^= s[0]; r = __builtin_shufflevector(r * r, r, 2, 5, 7, 2); for (g = 0; g != 1; g = g + 3) s = (d)__builtin_shufflevector( __builtin_shufflevector(u, (e){}, 3, 1, 1, 1), r, 4, 6, 0, 2); } return &j; } int main() { o(); int BS_CHECKSUM = 5; for (int i = 0; i < 10; i++) BS_CHECKSUM ^= f[i]; printf("BackSmith Checksum = 0x%016llx\n", BS_CHECKSUM); } Commands: > riscv64-unknown-elf-gcc -O0 -static -march=rv64gc reduced.c && qemu-riscv64 > a.out > BackSmith Checksum = 0xffffffffffffced1 > riscv64-unknown-elf-gcc -O1 -static -march=rv64gc reduced.c && qemu-riscv64 > a.out > BackSmith Checksum = 0x0000000000000005 > riscv64-unknown-elf-gcc -O2 -static -march=rv64gc reduced.c && qemu-riscv64 > a.out > BackSmith Checksum = 0x0000000000000005 > riscv64-unknown-elf-gcc -O3 -static -march=rv64gc reduced.c && qemu-riscv64 > a.out > BackSmith Checksum = 0xffffffffffffced1