Optimize difference between 4.7.4 and 4.8.3

Asked by Jason

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_t)(*(volatile test_struct_t*)0x10000000).e;
}
=================================================

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
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Joey Ye (jinyun-ye) said :
#2

Jason,

Thanks reporting it. This is a 4.8 bug, which is similar to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56997 and has been fixed in GCC trunk.

I'm trying to backport it to GCC 4.8 and hopefully include it in gcc-arm-embedded 4.8 update 1 release
http://gcc.gnu.org/ml/gcc-patches/2014-02/msg00875.html

Thanks,
Joey

Can you help with this problem?

Provide an answer of your own, or ask Jason for more information if necessary.

To post a message you must log in.