Optimize difference between 4.7.4 and 4.8.3
Hi,
I updated to 4.8.3 recently and got a problem here.
This is my example code:
=======
#include <stdint.h>
typedef struct {
uint8_t a : 1;
uint8_t b : 1;
uint8_t c : 1;
uint8_t d : 3;
uint8_t e : 2;
} test_struct_t;
uint8_t test_func(void)
{
return (uint8_
}
=======
I used this command to compile the code:
arm-none-eabi-gcc -mthumb -mcpu=cortex-m4 -Os -c func.c
With GCC 4.7.4, it is compiled to:
=======
mov.w r3, #268435456 ; 0x10000000
ldrb r0, [r3, #0]
lsrs r0, r0, #6
bx lr
=======
But with GCC 4.8.3, it is compiled to:
=======
mov.w r3, #268435456 ; 0x10000000
ldr r0, [r3, #0]
ubfx r0, r0, #6, #2
bx lr
=======
I need ldrb here so I wonder why it is ldr with GCC 4.8.3.
Extra information:
1. With optimize flag -O0, the assembler is ldrb.
2. With optimize flag -O1, the assembler is ldr.
3. Replace -O1 with explicit flags which -O1 turns on: -fauto-inc-dec -fcompare-elim -fcprop-registers ..., the assembler is ldrb. This is strange.
Thanks a lot for your help.
Question information
- Language:
- English Edit question
- Status:
- Answered
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask Jason for more information if necessary.