Bug 47685 - Tail call doesn't work for thumb2
Summary: Tail call doesn't work for thumb2
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.5.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2011-02-10 18:30 UTC by Alexandre Pereira Nunes
Modified: 2011-02-28 20:27 UTC (History)
1 user (show)

See Also:
Host:
Target: arm-none-eabi , arm-unknown-elf
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
testcase. (126 bytes, text/x-csrc)
2011-02-10 18:30 UTC, Alexandre Pereira Nunes
Details
Patch from the trunk, which I'm testing against 4.5.x (1.31 KB, patch)
2011-02-28 20:25 UTC, Alexandre Pereira Nunes
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexandre Pereira Nunes 2011-02-10 18:30:15 UTC
Created attachment 23298 [details]
testcase.

When compiling the attached test program for i.e. -mcpu=cortex-a9 -marm the tail call mechanism works correctly ... if you replace -marm for -mthumb then the result is a traditional stack frame, for which i couldn't find any switches to turn it off.

For example, this was taken from the example code for -mthumb:


func_c:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        push    {lr}
        movs    r3, #33
        bl      func_a
        pop     {pc}
        .size   func_c, .-func_c

And this for -marm:


func_c:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        mov     r3, #33
        b       func_a
        .size   func_c, .-func_c


This is more relevant for example to -mcpu=cortex-m3 where we have no ram to waste.
Comment 1 Alexandre Pereira Nunes 2011-02-10 18:30:48 UTC
It also happens on 4.4.5
Comment 2 Ramana Radhakrishnan 2011-02-27 23:27:11 UTC
This has been fixed on trunk and will be in the 4.6.0 release. 

With this commit

http://gcc.gnu.org/ml/gcc-cvs/2010-05/msg00725.html

cheers
Ramana
Comment 3 Alexandre Pereira Nunes 2011-02-28 20:25:50 UTC
Created attachment 23496 [details]
Patch from the trunk, which I'm testing against 4.5.x
Comment 4 Alexandre Pereira Nunes 2011-02-28 20:27:00 UTC
(In reply to comment #2)
> This has been fixed on trunk and will be in the 4.6.0 release. 
> 
> With this commit
> 
> http://gcc.gnu.org/ml/gcc-cvs/2010-05/msg00725.html
> 
> cheers
> Ramana


Thanks,

These changes were non-intrusive, so I've applied them to my 4.5.2 toolchain and it simply "works for me".

Cheers,

Alexandre