https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129084
Bug ID: 129084
Summary: Conditional in-order FP reduction loses its condition
with --param vect-partial-vector-usage=0
(vect-pr127152.c fails again)
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: frederic.mahe at cirad dot fr
Target Milestone: ---
Target: riscv64-unknown-linux-gnu
gcc.dg/vect/vect-pr127152.c, added with the fix for PR127152, fails
again at execution on current trunk:
- aarch64-suse-linux, in the gcc-testresults posts for r17-6479 and
r17-6541;
- riscv64 with RVV, natively on a SpacemiT K1 (VLEN=256) and in the
RISE CI (qemu).
On riscv64 the testcase below also fails with GCC 14.2, so the RISC-V
failure is older than r17-3692 and has another cause than PR127152.
Testcase (the PR127152 testcase from Dhruv Chawla, with a printf):
__attribute__((noipa)) float
f (float *a, int n)
{
float s = 0.0f;
for (int i = 0; i < n; i++)
if (a[i] > 0.0f)
s += a[i];
return s;
}
int main (void)
{
float a[16];
for (int i = 0; i < 16; i++)
a[i] = (i & 1) ? 1.0f : -1.0f;
__builtin_printf ("%g\n", f (a, 16));
return f (a, 16) != 8.0f;
}
$ gcc -O2 -march=rv64gcv_zvl256b -ftree-vectorize \
--param vect-partial-vector-usage=0 t.c && ./a.out
0 (expected 8)
The riscv64 vector loop sums every element. It has no compare and no
mask, so the `a[i] > 0.0f` condition is dropped:
.L4:
vl1re32.v v1,0(a3)
vsetvli t0,zero,e32,m1,ta,ma
vfmv.s.f v2,fa0
addw t3,t3,a2
add a3,a3,a6
vfredosum.vs v0,v1,v2
vfmv.f.s fa0,v0
bgeu a7,t3,.L4
riscv64:
- Fails: -O2/-O3 with --param vect-partial-vector-usage=0, at LMUL m1
(default), with or without -mrvv-vector-bits=zvl and
-fno-vect-cost-model.
- Passes: the default partial-vector usage, -mrvv-max-lmul=m2, and
-march=rv64gc.
I could not test aarch64 myself; that failure is from the posted
results.
The testcase is clean with -Wall -Wextra, still fails with
-fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations, and
-fsanitize=undefined reports nothing (it prints 8 at -O0).
Compiler (native riscv64, gcc -v):
Target: riscv64-unknown-linux-gnu
Configured with: /srv/gcc/src/configure --enable-languages=c,c++
--disable-multilib
--with-arch=rv64gcv_zba_zbb_zbc_zbs_zicond_zfh_zvfh_zvl256b
--with-abi=lp64d
gcc version 17.0.0 20261120 (experimental) (GCC) [728d0bebb85]
Found and reduced with help from Claude (Anthropic); checked by hand on
hardware.