Poor code gen for addr[offset] = val
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
GNU Arm Embedded Toolchain |
Confirmed
|
Low
|
Terry Guo |
Bug Description
Versions: 4.9q4 (and back thru at least 4.7q3)
Host: Windows
Symptom:
Sequences of constructs like "addr[offset] = val;" and/or "addr->offset = val;" generate poorly optimized "-Os" machine code.
Compile the following example and then again with the macro replaced with the inline assembly statement instead. The former is 30% larger than the later.
Example:
#include <stdint.h>
#define setRegsWord(addr, offset, value) \
*(uint32_t volatile*
/* asm volatile( \
" str %[Rv], [%[Rbase], %[Immed]]\n\t" \
: \
: [Rv] "r" (value), [Rbase] "r" (addr), [Immed] "I" (offset) \
)*/
void __attribute_
{
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
setRegsWord(
do {} while(1);
}
Changed in gcc-arm-embedded: | |
assignee: | nobody → Terry Guo (terry.guo) |
Changed in gcc-arm-embedded: | |
status: | New → Confirmed |
Changed in gcc-arm-embedded: | |
importance: | Undecided → Low |
Thanks for reporting such an interesting issue. Basically the code are doing below things:
mov r3, #imme1
str r0, [r3]
Consider case that the #imme1 is too big to be encoded in 'mov' instruction, but value like '#imme1 - offset' can be encoded. The clever way will be:
mov r3, #imme1-offset
str r0, [r3, offset]
But looks current 4.9 and trunk are not so clever, the less efficient code will be generated:
ldr r3, .L1
str r0, [r3]
.L1:
.word #imme1
Joey, does this look familiar to you?