public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/96017] New: Powerpc suboptimal register spill in likely path
@ 2020-07-01  9:57 npiggin at gmail dot com
  2020-07-01 10:01 ` [Bug target/96017] " wschmidt at gcc dot gnu.org
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: npiggin at gmail dot com @ 2020-07-01  9:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96017

            Bug ID: 96017
           Summary: Powerpc suboptimal register spill in likely path
           Product: gcc
           Version: 9.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: npiggin at gmail dot com
  Target Milestone: ---
            Target: powerpc64le-linux-gnu
             Build: gcc version 9.2.1 20190909 (Debian 9.2.1-8)

-- test.c --
extern int foo;
extern void slowpath(int *);

int test(int *val)
{
        int ret = foo;

        if (__builtin_expect(*val != 0, 0))
                slowpath(val);

        return ret;
}
--

Compiling with -O2 gives the following asm. It seems possible for the fast path
case to avoid the stack frame by using a volatile register to save the val
argument in case the slow path needs it (or alternatively to save the load from
'foo', as r31 is used now, but that requires an extra register move on a
critical path for the return value). This should be smaller and faster code
even for the slow path too.

        addis   r2,r12,0
        addi    r2,r2,0
        lwz     r9,0(r3)
        addis   r10,r2,0
        ld      r10,0(r10)
        std     r31,-8(r1)
        stdu    r1,-48(r1)
        lwa     r31,0(r10)
        cmpwi   r9,0
        bne     1f
        addi    r1,r1,48
        mr      r3,r31
        ld      r31,-8(r1)
        blr
        nop
        ori     r2,r2,0
1:      mflr    r0
        std     r0,64(r1)
        bl      slowpath
        nop
        ld      r0,64(r1)
        addi    r1,r1,48
        mr      r3,r31
        ld      r31,-8(r1)
        mtlr    r0
        blr

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

end of thread, other threads:[~2023-11-24  9:22 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-01  9:57 [Bug target/96017] New: Powerpc suboptimal register spill in likely path npiggin at gmail dot com
2020-07-01 10:01 ` [Bug target/96017] " wschmidt at gcc dot gnu.org
2020-07-01 10:02 ` wschmidt at gcc dot gnu.org
2020-07-01 10:06 ` wschmidt at gcc dot gnu.org
2020-07-01 10:21 ` npiggin at gmail dot com
2020-07-01 14:00 ` bergner at gcc dot gnu.org
2020-07-01 23:58 ` segher at gcc dot gnu.org
2020-07-02  1:18 ` bergner at gcc dot gnu.org
2020-07-02  1:24 ` bergner at gcc dot gnu.org
2020-07-02  2:06 ` bergner at gcc dot gnu.org
2020-07-02  2:45 ` bergner at gcc dot gnu.org
2020-07-02 21:22 ` segher at gcc dot gnu.org
2020-07-02 21:24 ` segher at gcc dot gnu.org
2021-04-27 11:39 ` jakub at gcc dot gnu.org
2021-07-28  7:04 ` rguenth at gcc dot gnu.org
2023-11-24  8:46 ` jskumari at gcc dot gnu.org
2023-11-24  9:22 ` jskumari 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).