https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129015
Bug ID: 129015
Summary: [vect] wrong code with -march=x86-64-v4: even/odd
widening multiply feeding a masked .COND_ADD reduction
uses the lo/hi-split mask, adding products under the
wrong lanes
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: 0599jiangyc at gmail dot com
Target Milestone: ---
The following code:
```c
/* GCC trunk wrong code: masked (if-converted, .COND_ADD) reduction of a
widening
int*int->u64 multiply is vectorized with even/odd widening multiplies
(vpmuldq) but the lane mask is still split lo/hi, so the wrong lanes are
masked.
Flags: -O2 -march=x86-64-v4 (also -O3 -march=x86-64-v4,
-mprefer-vector-width=256)
Run AVX-512 binary under Intel SDE: sde64 -spr -- ./a.out
Expected: exit 0 (prints "64 64"). Trunk: prints "68 64", exits 1.
OK: -O0, -O3 -march=x86-64-v3, GCC 11.4 -O3 -march=x86-64-v4. */
#include <stdio.h>
#define N 16
int X[N], Z[N], Y[N];
__attribute__((noipa)) unsigned long long f(void) {
unsigned long long acc = 0;
for (int i = 0; i < N; i++)
if (Y[i])
acc += (unsigned long long)X[i] * Z[i];
return acc;
}
int main(void) {
unsigned long long e = 0;
for (int i = 0; i < N; i++) {
X[i] = 1; Z[i] = i; Y[i] = i & 1;
if (Y[i]) e += (unsigned long long)X[i] * Z[i];
}
unsigned long long r = f();
printf("%llu %llu\n", r, e);
return r != e;
}
```
Resulted in this output:
```
$ gcc -O2 -march=x86-64-v4 repro.c && sde64 -spr -- ./a.out (also -O3,
-mprefer-vector-width=256)
68 64
(exit 1; -O0, -O3 -march=x86-64-v3, GCC 11.4 -O3 -march=x86-64-v4 and clang
print 64 64)
```
Trunk: https://godbolt.org/z/9dK4jxMsM (x86-64 gcc trunk, -O2 -march=x86-64-v4;
compile only: the Godbolt runner has no AVX-512, run locally under Intel SDE;
reproduces as of 2026-11-12)