https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129046
Bug ID: 129046
Summary: [15/16/17 Regression] [vect] SIGSEGV at -O3
-march=x86-64-v3 -fno-vect-cost-model: reversed load
of a single-element interleaving group with gaps is
emitted as aligned vmovdqa at a misaligned address
after alignment peeling
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 (17.0.0 20261110): SIGSEGV at -O3 -march=x86-64-v3
-fno-vect-cost-model
* (also -O2 -march=x86-64-v3 -fno-vect-cost-model, -O3 -mavx2
-fno-vect-cost-model,
* -march=haswell / znver2, and with --param vect-epilogues-nomask=0).
* Correct at -O0, at -O3 -march=x86-64-v3 with the default cost model, at -O3
(SSE2),
* with -fno-ipa-cp (trip count must be a known constant), and with gcc 11 and
clang.
* The loop runs i = 63..1 (63 iterations). S[2*i] is a single-element
interleaving group
* with a negative step (-16 bytes). Alignment peeling by 1 is chosen. After
the peel, the vector
* loads for S[2*i] start at &S[2*i - 3] (S+968, 8 mod 32), but they are
emitted as aligned
* vmovdqa, so the program faults.
* Godbolt: x86-64 gcc (trunk), flags: -O3 -march=x86-64-v3
-fno-vect-cost-model
* EXPECTED: prints "0 126 2", exit 0. BUGGY: SIGSEGV.
*/
#include <stdio.h>
unsigned long S[480] __attribute__((aligned(64)));
long D[480] __attribute__((aligned(64)));
__attribute__((noinline)) static unsigned f(long n, long s) {
unsigned r = 0;
for (unsigned long i = n; i-- > (unsigned long)s; ) {
r ^= (unsigned)S[i];
D[419 - 3 * i] = S[2 * i];
D[417 - 3 * i] = S[i + 3];
}
return r;
}
int main(void) {
for (int q = 0; q < 480; q++) S[q] = q;
unsigned r = f(64, 1);
printf("%u %ld %ld\n", r, D[230], D[416]);
return !(r == 0 && D[230] == 126 && D[416] == 2);
}
```
Resulted in this output:
```
$ gcc -O3 -march=x86-64-v3 -fno-vect-cost-model repro.c && ./a.out
Segmentation fault
(also -O2 -march=x86-64-v3 -fno-vect-cost-model, -O3 -mavx2
-fno-vect-cost-model, -march=haswell/znver2;
gcc -O0, the default cost model, -fno-ipa-cp, GCC 14.2 and clang print "0 126
2")
```
Trunk: https://godbolt.org/z/EMxExxeYc (x86-64 gcc trunk, -O3 -march=x86-64-v3
-fno-vect-cost-model, executed; reproduces as of 2026-11-12; also GCC 15.2, not
GCC 14.2)