https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116997
Bug ID: 116997 Summary: [13/14/15 Regression] Wrong bitfield accesses since r13-3219-g25413fdb2ac249 Product: gcc Version: unknown Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: stefansf at gcc dot gnu.org Target Milestone: --- Target: s390x-*-* struct S0 { unsigned f0; signed f2 : 11; signed : 6; } GlobS, *Ptr = &GlobS; const struct S0 Initializer = {7, 3}; int main (void) { for (unsigned i = 0; i <= 2; i++) *Ptr = Initializer; if (GlobS.f2 != 3) __builtin_abort (); return 0; } gcc -march=z13 -O2 t.c (should fail for any arch which supports vector extensions) During ifcvt we have Start lowering bitfields Lowering: Ptr.0_1->f2 = 3; to: _ifc__24 = Ptr.0_1->D.2918; _ifc__25 = BIT_INSERT_EXPR <_ifc__24, 3, 0 (11 bits)>; Ptr.0_1->D.2918 = _ifc__25; Done lowering bitfields ... Match-and-simplified BIT_INSERT_EXPR <_ifc__24, 3, 0 (11 bits)> to 3 RHS BIT_INSERT_EXPR <_ifc__24, 3, 0 (11 bits)> simplified to 3 Setting value number of _ifc__25 to 3 (changed) Replaced BIT_INSERT_EXPR <_ifc__24, 3, 0 (11 bits)> with 3 in all uses of _ifc__25 = BIT_INSERT_EXPR <_ifc__24, 3, 0 (11 bits)>; Value numbering stmt = Ptr.0_1->D.2918 = _ifc__25; which in the end leads to the optimized tree output int main () { struct S0 * Ptr.0_1; unsigned int _2; unsigned int _3; <bb 2> [local count: 268435458]: Ptr.0_1 = Ptr; MEM <vector(2) unsigned int> [(void *)Ptr.0_1] = { 7, 3 }; _2 = BIT_FIELD_REF <GlobS, 32, 32>; _3 = _2 & 4292870144; if (_3 != 6291456) goto <bb 3>; [0.00%] else goto <bb 4>; [100.00%] <bb 3> [count: 0]: __builtin_abort (); <bb 4> [local count: 268435456]: return 0; } Since bitfields are left aligned on s390, constant 3 is wrong and should rather be 0x600000.