From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18966 invoked by alias); 29 Jan 2015 14:36:06 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 18955 invoked by uid 89); 29 Jan 2015 14:36:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f52.google.com Received: from mail-pa0-f52.google.com (HELO mail-pa0-f52.google.com) (209.85.220.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 29 Jan 2015 14:36:02 +0000 Received: by mail-pa0-f52.google.com with SMTP id kx10so39704750pab.11 for ; Thu, 29 Jan 2015 06:36:00 -0800 (PST) X-Received: by 10.66.236.36 with SMTP id ur4mr1008240pac.107.1422542160098; Thu, 29 Jan 2015 06:36:00 -0800 (PST) Received: from bubble.grove.modra.org (CPE-58-160-155-134.oycza5.sa.bigpond.net.au. [58.160.155.134]) by mx.google.com with ESMTPSA id nn7sm8038855pdb.4.2015.01.29.06.35.58 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jan 2015 06:35:59 -0800 (PST) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 88111EA4AF4; Fri, 30 Jan 2015 01:05:54 +1030 (ACDT) Date: Thu, 29 Jan 2015 15:35:00 -0000 From: Alan Modra To: Segher Boessenkool Cc: gcc-patches@gcc.gnu.org Subject: Re: RTL cprop vs. fixed hard regs Message-ID: <20150129143554.GB14796@bubble.grove.modra.org> Mail-Followup-To: Segher Boessenkool , gcc-patches@gcc.gnu.org References: <20150116094227.GV23768@bubble.grove.modra.org> <20150116170324.GB12714@gate.crashing.org> <20150117003712.GW23768@bubble.grove.modra.org> <9A8D0D09-4FC5-4C5F-9B4F-B0A3DC974643@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9A8D0D09-4FC5-4C5F-9B4F-B0A3DC974643@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2015-01/txt/msg02618.txt.bz2 On Sat, Jan 17, 2015 at 01:12:49PM +0100, Richard Biener wrote: > On January 17, 2015 1:37:12 AM CET, Alan Modra wrote: > >On Fri, Jan 16, 2015 at 11:03:24AM -0600, Segher Boessenkool wrote: > >> On Fri, Jan 16, 2015 at 08:12:27PM +1030, Alan Modra wrote: > >> > OK, so we need to fix this in the rs6000 backend, but it occurs to > >me > >> > that cprop also has a bug here. It shouldn't be touching fixed > >hard > >> > registers. > >> > >> Why not? It cannot allocate a fixed reg to a pseudo, but other than > >> that there is nothing special about fixed regs; the transform is > >> perfectly valid as far as I see. > > > >I didn't say that copying to a pseudo and using that was invalid.. > >The bug I see is a mis-optimisation. Also, the asm operands case that > >do_local_cprop already rules out changing is very similar to fixed > >regs. Would you argue that changing asm operands is also valid? :) > > > >> It isn't a desirable transform in this case, but that is not true for > >> fixed regs in general (just because the stack pointer is live > >everywhere). > > > >What's the point in extending the lifetime of some pseudo when you > >know the original fixed register is available everywhere? Do you have > >some concrete example in mind where this "optimisation" is beneficial? > > > >Some ports even include pc in fixed_regs. So there are obvious > >examples where regs in fixed_regs change behind the compiler's back. > >Naive users might even expect to see the "current" value of those > >regs. (Again, I'm not saying that it is invalid if gcc substituted an > >older value.) > > Just to add, we avoid doing this on the GIMPLE level as well. Segher, does this one look better to you? The previous patch turned off constant propagation for fixed registers as well as register copy propagation. The latter is all I really meant to do. Bootstrapped etc. powerpc64-linux. gcc/ * cprop.c (do_local_cprop): Disallow register copy propagation of fixed hard registers. gcc/testsuite/ * gcc.target/powerpc/cprophard.c: New. Index: gcc/cprop.c =================================================================== --- gcc/cprop.c (revision 219792) +++ gcc/cprop.c (working copy) @@ -1207,7 +1207,11 @@ if (cprop_constant_p (this_rtx)) newcnst = this_rtx; - if (REG_P (this_rtx) && REGNO (this_rtx) >= FIRST_PSEUDO_REGISTER + if (REG_P (this_rtx) + && REGNO (this_rtx) >= FIRST_PSEUDO_REGISTER + /* Don't copy propagate fixed regs. This just tends to + extend the lifetime of this_rtx to no purpose. */ + && (REGNO (x) >= FIRST_PSEUDO_REGISTER || !fixed_regs[REGNO (x)]) /* Don't copy propagate if it has attached REG_EQUIV note. At this point this only function parameters should have REG_EQUIV notes and if the argument slot is used somewhere Index: gcc/testsuite/gcc.target/powerpc/cprophard.c =================================================================== --- gcc/testsuite/gcc.target/powerpc/cprophard.c (revision 0) +++ gcc/testsuite/gcc.target/powerpc/cprophard.c (working copy) @@ -0,0 +1,13 @@ +/* { dg-do compile { target { powerpc*-*-* && lp64 } } } */ +/* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler "ld 2,(24|40)\\(1\\)" } } */ + +/* From a linux kernel mis-compile of net/core/skbuff.c. */ +register unsigned long current_r1 asm ("r1"); + +void f (unsigned int n, void (*fun) (unsigned long)) +{ + while (n--) + (*fun) (current_r1 & -0x1000); +} -- Alan Modra Australia Development Lab, IBM