From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 14F4B3857007; Wed, 1 Jul 2020 09:57:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 14F4B3857007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1593597459; bh=eVU2SrkNVG9+d/m4lGtdApyvhhE4iZTAfU0HxajEUfI=; h=From:To:Subject:Date:From; b=OQ4awzi3NeFlKoKei3cReEcKwJDb35o1NcctNGNhp3vP5vEAWCOEqDza1/9YYwHzT wuS2YhOAaTK+96nyS1r1CgMRtwLiK4OhyIQpDCDRTLCVXYOavbD6+d5Xd3Rq2MuxjC Hb7w8d6yZGRNocwlQJlsclONy1u7/+HRZ/PnzlR8= From: "npiggin at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/96017] New: Powerpc suboptimal register spill in likely path Date: Wed, 01 Jul 2020 09:57:38 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 9.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: npiggin at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone cf_gcctarget cf_gccbuild Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Jul 2020 09:57:39 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96017 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 =3D foo; if (__builtin_expect(*val !=3D 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=