https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129170
Bug ID: 129170
Summary: [15/16/17 Regression] wrong code at -O2 with
vectorized store of signed _BitInt(17) array (sign
extension lost)
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: jeffchen006 at gmail dot com
Target Milestone: ---
$ cat t.c
#include <stdint.h>
#include <stdio.h>
_BitInt(7) a;
_BitInt(4) b;
_BitInt(2) c;
uint64_t d(_BitInt(7) e, _BitInt(4), _BitInt(2)) {
_BitInt(7) f = e;
_BitInt(32) g;
_BitInt(17) j[4];
for (int i = 0; i < 4; i++) {
j[i] = f - 5;
g ^= i;
}
for (int i = 0; i < 4; i++)
g = j[i];
uint64_t h = g;
return h;
}
int main() { printf("f1 %llu\n", (long long)d(a, b, c)); }
$ gcc -std=c23 -O0 t.c -lm && ./a.out
f1 18446744073709551611
$ gcc -std=c23 -O2 t.c -lm && ./a.out
f1 131067
Trunk (r17-5981-g78124a426ab, x86_64-pc-linux-gnu): wrong at -O2, -O3; -O0, -O1
correct.
Releases: 10.5: -O2 n/a, -O3 n/a; 12.5: -O2 n/a, -O3 n/a; 13.4: -O2 n/a, -O3
n/a; 14.3: -O2 ok, -O3 ok; 15.2: -O2 wrong, -O3 wrong; 16.2: -O2 wrong, -O3
wrong.
Each of these makes it go away at -O3: -fwrapv -fno-tree-vectorize
-fdisable-tree-ch2 -fdisable-tree-cunroll.
Started with r15-3509-gd34cda72098867 ("Handle non-grouped stores as
single-lane SLP").
-fsanitize=undefined,address is clean at -O0; -ftrivial-auto-var-init=pattern
does not change the -O0 output.