https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62233
Bug ID: 62233 Summary: unnecessary shift instructions to prepare loop counter Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: carrot at google dot com Target: powerpc64le Compile following source code with options -m64 -mcpu=power8 -O2 typedef struct { int l; int b[258]; } S; void clear (S* s ) { int i; int len = s->l; for (i = 0; i <= len; i++) s->b[i] = 0; } Trunk gcc generates: clear: lwz 9,0(3) cmpwi 7,9,0 extsw 9,9 bltlr- 7 sldi 9,9,2 // A li 10,0 srdi 9,9,2 // B addi 9,9,1 mtctr 9 .p2align 4,,15 .L3: stwu 10,4(3) bdnz .L3 blr Instruction A shift loop counter left by 2 bits, instruction B shift loop counter right by 2 bits, so they do nothing when combined together, and should be removed.