https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126426
Bug ID: 126426
Summary: riscv rvv: Incorrect result with -march=rva23u64 -O2
in libgav1
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: joel at jms dot id.au
CC: bergner at gcc dot gnu.org, law at gcc dot gnu.org,
rdapp at gcc dot gnu.org
Target Milestone: ---
Target: riscv64-*-linux-gnu
Created attachment 65137
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65137&action=edit
reduced test case
I was rebuilding some packages with Debian's GCC 16.1 and -march=rva23u64 -O2
and found a test suite failure in libgav1:
BitstreamUtils.GetMvProjection
projection_mv.mv32: 0 spec_projection_mv.mv32: 1073676288
(0x3FFF0000)
projection_mv.mv32: 0 spec_projection_mv.mv32: 3221291008
(0xC0010000)
projection_mv.mv32: 4249419304 spec_projection_mv.mv32: 4294966824
(0xFFFFFE28)
Attached is a reduce test case derived from libgav1 (manual hacking + cvise).
To reproduce build with vector and -O2 (the static is there to simplify running
under qemu-user). -march=rva32u64 and -march=rv64gcv both are sufficient.
$ riscv64-unknown-linux-gnu-gcc -O2 -march=rv64gcv -static repro.c
$ qemu-riscv64 -cpu rv64,v=true ./a.out ; echo $?
BAD: fffd0000
255
Some experimentation showed it goes away with -fno-tree-loop-vectorize, or just
-fno-ext-dce.
$ riscv64-unknown-linux-gnu-gcc -O2 -march=rv64gcv -static -fno-ext-dce
repro.c
$ qemu-riscv64 -cpu rv64,v=true ./a.out ; echo $?
OK
0
Initially discovered with Debian 16.1.0-2, reproduces with gcc 16 6afcc4f6d and
master f6b00aefc25a (from 2026-07-25).