https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128053
Bug ID: 128053
Summary: wrong code at -O2 and -O3 for a vectorized read of an
unsigned bit-field that contains the sign bit of a
union's int member
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: kyuwoncho18 at gmail dot com
Target Milestone: ---
Target: x86_64-pc-linux-gnu
union U { int i; struct { unsigned lo : 24; unsigned hi : 8; } s; };
int in[8] = { (int) 0xff000000u };
unsigned out[8];
int main(void) {
for (int k = 0; k < 8; k++) {
union U u;
u.i = in[k];
out[k] = u.s.hi;
}
if (out[0] != 255)
__builtin_abort();
}
godbolt: https://godbolt.org/z/95zTzhser
u.s.hi is bits 24-31 of 0xff000000, so out[0] must be 255; -O0, -O1 and -O2
-fno-tree-vectorize get that, but -O2 and -O3 give 4294967295 and abort.