This code produces this output: struct s { unsigned x : 16; };
int f(struct s *node) { int a = 0; do a++; while ((--node)->x == a); return a; } li r2,0 L2: lhzu r0,-4(r3) addi r2,r2,1 rlwinm r0,r0,0,0xffff cmpw cr7,r0,r2 beq+ cr7,L2 mr r3,r2 blr If I change unsigned x : 16 to unsigned short x, instead I get the better code: _f: mr r2,r3 li r3,0 L2: lhzu r0,-2(r2) addi r3,r3,1 cmpw cr7,r0,r3 beq+ cr7,L2 blr (I don't care about the register allocation, the important point is that the rlwinm instruction, which clears the left 16 bits as is clear from the simplified mnemonic "clrlwi r0,r0,16", is useless). -- Summary: useless clrlwi instruction produced for 16-bit bitfield Product: gcc Version: 4.2.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: target AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: bonzini at gnu dot org GCC target triplet: powerpc-*-* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29083