Bug 12305 - processor return register saved/restore unnecessarily in leaf function
Summary: processor return register saved/restore unnecessarily in leaf function
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.4.0
: P2 enhancement
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2003-09-16 22:15 UTC by Toshiyasu Morita
Modified: 2004-04-28 11:24 UTC (History)
2 users (show)

See Also:
Host:
Target: sh-elf
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-11-08 21:46:12


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Toshiyasu Morita 2003-09-16 22:15:56 UTC
When this function is compiled:

int a, b; int foo(void) { return a + b; }

using -O2 -m4 -fPIC -S, the following code is created:

_foo:
        mov.l   r12,@-r15
        mova    .L3,r0
        mov.l   .L3,r12
        mov.l   r14,@-r15
        add     r0,r12
        mov.l   .L4,r0
        sts.l   pr,@-r15		<- PR saved unnecessarily
        mov.l   @(r0,r12),r1
        mov     r12,r0
        mov     r15,r14
        mov.l   @r1,r2
        mov.l   .L5,r1
        mov.l   @(r0,r1),r1
        mov.l   @r1,r1
        add     r1,r2
        mov     r2,r0
        mov     r14,r15
        lds.l   @r15+,pr		<- PR restored unnecessarily
        mov.l   @r15+,r14
        rts
        mov.l   @r15+,r12
Comment 1 Andrew Pinski 2003-11-08 21:17:47 UTC
This version did not have the store/restore of the return register:
./cc1 --version
GNU C version 3.4 20030718 (experimental) (sh4-hardhat-linux)
        compiled by GNU C version 3.4 20030718 (experimental).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Comment 2 Andrew Pinski 2003-11-08 21:46:12 UTC
I can confirm this on the mainline (20031108), looks like sh-linux does do the saving or 
restoring of the return register for some reason.
Comment 3 Anil Paranjpe 2004-04-28 07:26:01 UTC
(In reply to comment #2)
> I can confirm this on the mainline (20031108), looks like sh-linux does do 
the saving or 
> restoring of the return register for some reason.

Hi,

Above mentioned bug is solved in gcc 3.5 mainline (snapshot dated 27-03-2004). 
But this bug is still there in released gcc 3.4.

Can anybody tell me which patch will fix this bug in gcc 3.4 ?

Regards,
Anil Paranjpe
Comment 4 Dhananjay Deshpande 2004-04-28 09:29:38 UTC
Fixed with - 

http://gcc.gnu.org/ml/gcc-patches/2004-02/msg02248.html

http://gcc.gnu.org/ml/gcc-cvs/2004-02/msg01310.html

This PR can be closed.

-Dhananjay
Comment 5 Andrew Pinski 2004-04-28 11:24:33 UTC
Fixed for 3.5.0.