[Bug target/96017] New: Powerpc suboptimal register spill in likely path
npiggin at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Jul 1 09:57:38 GMT 2020
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
More information about the Gcc-bugs
mailing list