https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84626
Bug ID: 84626 Summary: powerpc toc register is reloaded unnecessarily Product: gcc Version: 8.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: npiggin at gmail dot com Target Milestone: --- gcc version 8.0.1 20180207 (experimental) [trunk revision 257435] (Debian 8-20180207-2): Test case: void test(void (*fn)(void), unsigned long i) { while (i--) fn(); } Generates code: 2c: 18 00 41 f8 std r2,24(r1) 30: 00 00 00 60 nop 34: 00 00 00 60 nop 38: 00 00 00 60 nop 3c: 00 00 42 60 ori r2,r2,0 40: 78 f3 cc 7f mr r12,r30 44: a6 03 c9 7f mtctr r30 48: ff ff ff 3b addi r31,r31,-1 4c: 21 04 80 4e bctrl 50: 18 00 41 e8 ld r2,24(r1) 54: ff ff bf 2f cmpdi cr7,r31,-1 58: e8 ff 9e 40 bne cr7,40 <test+0x40> The r2 load could be moved out of the loop.