public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/54019] New: [SH] Tail calls with -fPIC use bsrf instead of braf
@ 2012-07-18 19:14 olegendo at gcc dot gnu.org
  2013-11-24 17:30 ` [Bug target/54019] " olegendo at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: olegendo at gcc dot gnu.org @ 2012-07-18 19:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54019

             Bug #: 54019
           Summary: [SH] Tail calls with -fPIC use bsrf instead of braf
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: olegendo@gcc.gnu.org
            Target: sh*-*-*


The following function:

int a, b;

int bleh (int x, int y);

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

compiled with -m4 -O2 -ml -fPIC:

        mov.l   r12,@-r15       ! 42    movsi_ie/11    [length = 2]
        mova    .L3,r0          ! 44    mova    [length = 2]
        mov.l   .L3,r12         ! 45    movsi_ie/1    [length = 2]
        sts.l   pr,@-r15        ! 43    movsi_ie/13    [length = 2]
        add     r0,r12          ! 46    *addsi3_compact    [length = 2]
        mov.l   .L4,r0          ! 5    movsi_ie/1    [length = 2]
        mov.l   @(r0,r12),r2    ! 7    movsi_ie/7    [length = 2]
        mov.l   .L5,r0          ! 34    movsi_ie/1    [length = 2]
        mov.l   @r2,r5          ! 8    movsi_ie/7    [length = 2]
        mov.l   @(r0,r12),r1    ! 11    movsi_ie/7    [length = 2]
        mov     r5,r4           ! 37    movsi_ie/2    [length = 2]
        mov.l   @r1,r1          ! 12    movsi_ie/7    [length = 2]
        add     r1,r4           ! 15    *addsi3_compact    [length = 2]
        sub     r1,r5           ! 16    *subsi3_internal    [length = 2]
        mov.l   .L6,r1          ! 39    movsi_ie/1    [length = 2]
        bsrf    r1              ! 41    call_valuei_pcrel    [length = 4]
.LPCS0:
        nop
        lds.l   @r15+,pr        ! 55    movsi_ie/17    [length = 2]
        rts                     ! 58    *return_i    [length = 2]
        mov.l   @r15+,r12       ! 56    movsi_ie/7    [length = 2]
.L7:
        .align 2
.L3:
        .long   _GLOBAL_OFFSET_TABLE_
.L4:
        .long   _a@GOT
.L5:
        .long   _b@GOT
.L6:
    .long   __Z4blehii@PLT-(.LPCS0+2-.)
    .cfi_endproc

Instead of 'bsrf' the 'braf' instruction could be used.
Maybe this is a side effect of PR 12306.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug target/54019] [SH] Tail calls with -fPIC use bsrf instead of braf
  2012-07-18 19:14 [Bug target/54019] New: [SH] Tail calls with -fPIC use bsrf instead of braf olegendo at gcc dot gnu.org
@ 2013-11-24 17:30 ` olegendo at gcc dot gnu.org
  2013-11-24 23:06 ` kkojima at gcc dot gnu.org
  2013-11-25 17:21 ` olegendo at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: olegendo at gcc dot gnu.org @ 2013-11-24 17:30 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54019

Oleg Endo <olegendo at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kkojima at gcc dot gnu.org

--- Comment #1 from Oleg Endo <olegendo at gcc dot gnu.org> ---
In sh.c, above the function 'sh_function_ok_for_sibcall', which implements
TARGET_FUNCTION_OK_FOR_SIBCALL there is a comment:

/* If PIC, we cannot make sibling calls to global functions
   because the PLT requires r12 to be live.  */

PLT entries use r12 and expect it to be a valid GOT pointer.
Because r12 must be preserved across function calls, it will have to be
restored before doing the tail call, like

    ...
    braf
    mov.l   @r15+,r12

If the PIC function was invoked by a non-PIC function, the contents of r12
might not be necessarily a valid GOT pointer.

Kaz, could you please confirm or refute this?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug target/54019] [SH] Tail calls with -fPIC use bsrf instead of braf
  2012-07-18 19:14 [Bug target/54019] New: [SH] Tail calls with -fPIC use bsrf instead of braf olegendo at gcc dot gnu.org
  2013-11-24 17:30 ` [Bug target/54019] " olegendo at gcc dot gnu.org
@ 2013-11-24 23:06 ` kkojima at gcc dot gnu.org
  2013-11-25 17:21 ` olegendo at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: kkojima at gcc dot gnu.org @ 2013-11-24 23:06 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54019

Kazumoto Kojima <kkojima at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-11-24
     Ever confirmed|0                           |1

--- Comment #2 from Kazumoto Kojima <kkojima at gcc dot gnu.org> ---
Confirmed.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug target/54019] [SH] Tail calls with -fPIC use bsrf instead of braf
  2012-07-18 19:14 [Bug target/54019] New: [SH] Tail calls with -fPIC use bsrf instead of braf olegendo at gcc dot gnu.org
  2013-11-24 17:30 ` [Bug target/54019] " olegendo at gcc dot gnu.org
  2013-11-24 23:06 ` kkojima at gcc dot gnu.org
@ 2013-11-25 17:21 ` olegendo at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: olegendo at gcc dot gnu.org @ 2013-11-25 17:21 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54019

--- Comment #3 from Oleg Endo <olegendo at gcc dot gnu.org> ---
(In reply to Kazumoto Kojima from comment #2)
> Confirmed.

Assuming my theories in comment #1 are correct, I guess to fix/improve this it
would require similar mechanisms as mentioned in PR 12306


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-11-25 17:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-18 19:14 [Bug target/54019] New: [SH] Tail calls with -fPIC use bsrf instead of braf olegendo at gcc dot gnu.org
2013-11-24 17:30 ` [Bug target/54019] " olegendo at gcc dot gnu.org
2013-11-24 23:06 ` kkojima at gcc dot gnu.org
2013-11-25 17:21 ` olegendo at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).