https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121845

            Bug ID: 121845
           Summary: [Trunk] RISC-V rv64gcv: miscompile at -O0
           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: ---

Testcase:
#include <stdint.h>
#include <stdio.h>
typedef uint32_t a;
typedef uint64_t uint64;
uint64 b;
__attribute__((__vector_size__(4 * sizeof(a)))) a f = {504339, 7, 3};
uint64 *g = &b;
int32_t *c(uint8_t, int32_t *, uint32_t, uint32_t, int64_t);
int8_t d() {
  int32_t e;
  c(0, &e, 0, 0, 1);
  return 0;
}
int32_t *c(uint8_t, int32_t *j, uint32_t, uint32_t, int64_t) {
  f = __builtin_shufflevector(f, f, 0, 3, 2, 1);
  *g = f[2];
  return j;
}
int main() {
  d();
  printf("0x%016llx\n", b);
}

Command:
> riscv64-unknown-elf-gcc =march=rv64gcv -O0 -static reduced.c && qemu-riscv64 
> 0x0000000000000000

> riscv64-unknown-elf-gcc =march=rv64gcv -O1/O2/O3 -static reduced.c && 
> qemu-riscv64 
> 0x0000000000000003

The GCC version is after patching
https://gcc.gnu.org/cgit/gcc/commit/?id=e3d5e9f0c8c6f27bf59d321d5082be7b3bb39f8a.
Maybe related to some shuffle bugs before:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121780
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121742

Reply via email to