https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129299
Bug ID: 129299
Summary: [16/17 Regression] wrong code at -O3 -march=x86-64-v4
--param vect-partial-vector-usage=2: fully-masked
early-break loop picks the mask IV precision from the
early-exit bound and truncates the main-exit niters
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 (derived from gcc.dg/vect/vect-early-break_117-pr113734.c):
```c
#include <stdio.h>
int table[306];
__attribute__ ((noipa)) int
foo (int i, unsigned short n)
{
n >>= 9;
n += 11; /* n <= 138 */
while (i < 306 && n--)
table[i++] = 0;
return table[136];
}
int
main ()
{
for (int j = 0; j < 306; j++)
table[j] = -1;
int r = foo (0, 0xFFFF);
printf ("%d\n", r);
return r != 0;
}
```
Resulted in this output:
```
$ gcc -O0 repro.c && sde64 -spr -- ./a.out
0
$ gcc -O3 -march=x86-64-v4 --param vect-partial-vector-usage=2 repro.c && sde64
-spr -- ./a.out
-1
(also with -mprefer-vector-width=256/128; vect-partial-vector-usage=1 or 0 exit
0; with `n >>= 7` it is OK)
```
Trunk: https://godbolt.org/z/cGKqMEexs
- Needs AVX-512; reproduced under Intel SDE (-spr). The trunk and GCC 16.2 asm
(assembled and run under SDE) aborts; the GCC 15.2, 14.2 and 13.2 asm exits 0.
GCC 16 started fully masking early-break loops on x86.