https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121393
HUANG Huihui <hhhuang at smu dot edu.sg> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |hhhuang at smu dot edu.sg
--- Comment #9 from HUANG Huihui <hhhuang at smu dot edu.sg> ---
This also happens on aarch64 with SVE, from plain C without OpenMP. It fails at
-O3 with 14.1 to trunk (17.0.0 20261122); -fno-aggressive-loop-optimizations
hides it. 13.4 vectorizes the loop too, but gathers from &b with the offsets i
* 4, and is fine.
$ aarch64-linux-gnu-gcc-17 -O3 -march=armv8.2-a+sve -static t.c
$ qemu-aarch64 -cpu max ./a.out
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
Segmentation fault (core dumped)
$ cat t.c
unsigned a[100], b[400];
__attribute__((noipa)) void
f (unsigned n)
{
for (unsigned i = n; i-- > 0;)
a[i] = b[i * 4];
}
int
main (void)
{
for (unsigned i = 0; i < 400; i++)
b[i] = i;
f (100); /* a[i] = b[4 * i] for i = 99 .. 0 */
for (unsigned i = 0; i < 100; i++)
if (a[i] != 4 * i)
__builtin_abort ();
return 0;
}
The optimized dump has the same unsigned offsets as in comment 4, and the load
zero-extends them. The base is the address of the first access, as Richard
describes in
https://gcc.gnu.org/pipermail/gcc-patches/2025-October/696532.html:
vect__2.10_31 = .GATHER_LOAD (vectp_b.8_29, 64B, { 0, 4294967292, 4294967288,
... }, 4, { 0, ... });
ld1w z30.s, p7/z, [x1, z31.s, uxtw 2]
The scatter form, b[i * 4] = a[i], fails the same way.
Since this is wrong code on aarch64 from plain C, going back to GCC 14, could
the summary, component and target be updated and wrong-code added? Or I can
open a separate tree-optimization PR if that is preferred.
Compiler Explorer (assembly only): https://godbolt.org/z/f8fqfcs5r