public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/112801] New: [14] RISC-V vector: failure to mask top bits during type conversion
@ 2023-12-01  2:41 patrick at rivosinc dot com
  2023-12-01  2:49 ` [Bug target/112801] " juzhe.zhong at rivai dot ai
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: patrick at rivosinc dot com @ 2023-12-01  2:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112801
           Summary: [14] RISC-V vector: failure to mask top bits during
                    type conversion
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: patrick at rivosinc dot com
  Target Milestone: ---

This testcase is correctly handled on rv64gc but fails on rv64gcv -O2

> ./bin/riscv64-unknown-linux-gnu-gcc -march=rv64gcv -mabi=lp64d -O2 red.c -o rv64gcv.out

Creduced testcase:
int printf(char *, ...);
int a;
void c(int b) { a = b; }
char d;
char *const e = &d;
long f = 66483309998;
unsigned long g[2];
short h;
int k;
void l() {
  int i = 0;
  for (; i < 2; i++) {
    {
      unsigned long *m = &g[0];
      *m &= 2;
      if (f && *e)
        for (;;)
          ;
    }
    k = f;
    g[1] = k;
    for (; h;)
      ;
  }
}
int main() {
  l();
  c(g[1] >> 32);
  printf("%X\n", a);
}

Here's my analysis:
Focusing on the stack of operations that lead to a:
long f = 66483309998; // hex: F7AB6CDAE
int k = f; // Should mask off the top bits: 7AB6CDAE
unsigned long g[1] = k; // 7AB6CDAE
int arg to c() = g[1]; >> 32 // 0
int a = arg; // 0
print(a); // 0

0 is expected but rv64gcv fails to mask the top bits and ends up printing F

Tested using qemu with these commands:
> ./bin/riscv64-unknown-linux-gnu-gcc -march=rv64gcv -mabi=lp64d -O2 red.c -o rv64gcv.out

> ./bin/riscv64-unknown-linux-gnu-gcc -march=rv64gc -mabi=lp64d -O2 red.c -o rv64gc.out

> QEMU_CPU="rv64,vlen=128,v=true,vext_spec=v1.0,Zve32f=true,Zve64f=true" ./bin/qemu-riscv64 rv64gc.out
0

> QEMU_CPU="rv64,vlen=128,v=true,vext_spec=v1.0,Zve32f=true,Zve64f=true" ./bin/qemu-riscv64 rv64gcv.out
F

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-12-04 17:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-01  2:41 [Bug target/112801] New: [14] RISC-V vector: failure to mask top bits during type conversion patrick at rivosinc dot com
2023-12-01  2:49 ` [Bug target/112801] " juzhe.zhong at rivai dot ai
2023-12-01  7:57 ` rguenth at gcc dot gnu.org
2023-12-01  8:26 ` juzhe.zhong at rivai dot ai
2023-12-02  3:38 ` cvs-commit at gcc dot gnu.org
2023-12-02  3:38 ` juzhe.zhong at rivai dot ai
2023-12-04 17:25 ` patrick at rivosinc dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).