https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99068
Brian Grayson <brian.grayson at sifive dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|INVALID |--- Status|RESOLVED |UNCONFIRMED --- Comment #4 from Brian Grayson <brian.grayson at sifive dot com> --- (In reply to Segher Boessenkool from comment #3) > Then you get > > addi 9,9,-2 > lhau 10,2(9) > addi 9,9,2 > > which is worse than just > > lha 10,0(9) > addi 9,9,2 Why is the second addi needed, in your example? And note that if a pre-decrement "addi 9,9,-2" is needed to pre-bias the pointer, it is done once outside the loop, and not in every iteration of the loop. When I alter the code some (to loop via index, instead of via pointer), the lhau gets emitted, and I get this: .LC0: .quad a-2 ... addis 8,2,.LC0@toc@ha ld 8,.LC0@toc@l(8) ... .L8: blt 7,.L4 .L3: lhau 9,2(8) <-- r8 is loaded from a TOC entry that is pre-decremented by 2 addi 10,10,1 cmpd 7,7,10 cmpwi 0,9,0 bne 0,.L8 li 3,1 blr The TOC entry is already pre-decremented, so that's not a concern. And there is no need for an addi because the lhau does the job. I'm not sure I see your reason for closing the bug. GCC is capable of emitting the code above, and it's correct, without any extra instructions. I'm only asking gcc to emit the same code when it is coded via pointers, instead of only when coded via indexing.