https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64616
Bug ID: 64616
Summary: Redundant ldr when accessing var inside and outside a
loop
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: thopre01 at gcc dot gnu.org
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 g (int);
unsigned int glob;
void
f (void)
{
while (g (glob));
glob = 1;
}
{code}
The following code is then generated:
f:
push {r3, r4, r5, lr}
ldr r5, .L6
.L2:
ldr r0, [r5]
ldr r4, .L6
bl g
cmp r0, #0
bne .L2
movs r3, #1
str r3, [r4]
pop {r3, r4, r5, pc}
Note the redundant load of the address at offset 2c in instructions at offsets
4 and 14.