https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64458
Bug ID: 64458
Summary: [ARM] Redundant ldr when accessing var inside and
outside a loop
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: thopre01 at gcc dot gnu.org
Target: arm-none-eabi
When compiling the below example with -O2, 2 ldr are generated to access the
variable "some": one for the loop and one for the store.
int f (int);
unsigned int glob;
void
g (void)
{
while (glob);
glob = 1;
}
The following code is then generated:
0: push
{r4, lr}
4: ldr r4, pc, #32 ; 2c
8: ldr r0, [r4]
c: bl 0 <g>
10: cmp r0, #0
14: ldr r3, pc, #16 ; 2c
18: bne 8
1c: mov r2, #1
20: pop {r4, lr}
24: str r2, [r3]
28: bx lr
2c: .word 0x00000000
Note the redundant load of the address at offset 2c in instructions at offsets
4 and 14.