https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66248
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Target|arm, mips, sparc |*-*-* Last reconfirmed| |2025-01-07 Ever confirmed|0 |1 --- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Confirmed. Some targets have this fixed on the trunk though. For aarch64, GCC 14 produces: .L3: ldrh w1, [x2], 2 add w0, w0, w1 sxth w0, w0 cmp x3, x2 bne .L3 while the trunk now does: .L3: ldrh w0, [x2], 2 add w3, w3, w0 cmp x1, x2 bne .L3 But arm still produces: .L3: ldrsh r2, [r3], #2 add r0, r0, r2 cmp r1, r3 sxth r0, r0 bne .L3 But if change the code to be: ``` void func(short *a, int y, int *c) { short ret; int i; for(i = 0; i < y; i++) ret += a[i]; *c = ret; } ``` Then aarch64 still has the extend inside the loop. That is ext-dce is able to remove the extension from the loop if it is not needed at all but it does not move the extension to outside of the loop. That is ext-dce can remove the extension in this case: ``` void func(short *a, int y, short *c) { short ret; int i; for(i = 0; i < y; i++) ret += a[i]; *c = ret; } ``` But not if the store is int.