Comment 2 for bug 1720872

Revision history for this message
Dan Lewis (danielwlewis) wrote : Re: [Bug 1720872] Re: Missed optimization - unnecessary PUSH/POP

Hi Thomas,

Yes, both examples that I found push an even number of registers on entry
to the function. However, I don't understand why this is necessary. My
understanding was that the stack in the 32-bit Cortex-M4 need only be
aligned to a mod four address. Is this in gcc because of some 64-bit cpu's?

Thanks!
Dan

On Wed, Oct 4, 2017 at 1:32 AM, Thomas Preud'homme <
<email address hidden>> wrote:

> Hi,
>
> GCC often pushes r3 to ensure that the stack is 8byte aligned at
> function call boundary. If an odd number of register needs to be saved,
> GCC will also push r3 to make it even and thus keep the stack pointer
> 8byte aligned.
>
> Let me know if this is what happens for you.
>
> Best regards,
>
> Thomas
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1720872
>
> Title:
> Missed optimization - unnecessary PUSH/POP
>
> Status in GNU ARM Embedded Toolchain:
> New
>
> Bug description:
> I found two examples of where gcc -O3 produces a PUSH / POP sequence
> that unnecessarily includes register R3. According to the ARM
> Procedure Call Standard, register R3 does not need to be preserved by
> functions.
>
> An example of the C source code and the resulting ARM assembly can be
> found here:
>
> https://godbolt.org/g/UZFt9K
>
> This is with version 5.4 of gcc and using the following command line
> options:
>
> -O3 -march=armv7-m -mtune=cortex-m4 -mthumb
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/gcc-arm-embedded/+bug/1720872/+subscriptions
>