From patchwork Fri Jan 30 06:57:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 434743 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 866F31401F6 for ; Fri, 30 Jan 2015 17:58:02 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=indaj/3xj+NXAfMPx Y+VVC6E+UeFiyzbpPT3wDzA1g9ARlA4EgAgMSrnGUAgaClQ14Q+aaOrHdVqHLoVB /rQbuuxOyHJT0ikBb+fOuZ3OmTrM5Gx/Km+3WkHlbrODxz7xt0OouUmpR0SVYKGR Z2ypENwCmMpcqXsWZyRbBcAOq8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=erP4y57Isb4VFrfoKIcZOwG mZOA=; b=I9cl946rsYn7y7mlyc+APRIXEKNn9+Vsezo5OYJfgO6phGfHLh+Otxt tYvdoo7zGQpqVQF3C31gOMGICezyb8eZJ+XfaGIp6K5IC36ZkWTilp3Y6LjLMvSb IaNnHT2aCZyG9cG4/43A8QLaG3aRHN1zZYUR24PyOxfbcNtKwjTY= Received: (qmail 323 invoked by alias); 30 Jan 2015 06:57:31 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 308 invoked by uid 89); 30 Jan 2015 06:57:29 -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-f53.google.com Received: from mail-pa0-f53.google.com (HELO mail-pa0-f53.google.com) (209.85.220.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 30 Jan 2015 06:57:21 +0000 Received: by mail-pa0-f53.google.com with SMTP id kx10so48808234pab.12 for ; Thu, 29 Jan 2015 22:57:19 -0800 (PST) X-Received: by 10.68.241.35 with SMTP id wf3mr7097554pbc.22.1422601039215; Thu, 29 Jan 2015 22:57:19 -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 nb1sm9669284pdb.85.2015.01.29.22.57.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jan 2015 22:57:17 -0800 (PST) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 24BBDEA4719; Fri, 30 Jan 2015 17:27:13 +1030 (ACDT) Date: Fri, 30 Jan 2015 17:27:13 +1030 From: Alan Modra To: gcc-patches@gcc.gnu.org Cc: David Edelsohn Subject: [RS6000] fix for RTL cprop vs. fixed hard regs Message-ID: <20150130065713.GF14796@bubble.grove.modra.org> Mail-Followup-To: gcc-patches@gcc.gnu.org, David Edelsohn References: <20150116094227.GV23768@bubble.grove.modra.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20150116094227.GV23768@bubble.grove.modra.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes On Fri, Jan 16, 2015 at 08:12:27PM +1030, Alan Modra wrote: > https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-December/123776.html > shows gcc-5 miscompiling a powerpc64 linux kernel. The executive > summary is that the rs6000 backend has a bug in its RTL description of > indirect calls. We specify a parallel containing both the actual call > and an action that happens after the call, the restore of r2. The > restore is simply a memory load: > (set (reg:DI 2 2) > (mem/v/c:DI (plus:DI (reg/f:DI 1 1) > (const_int 40 [0x28])) [0 S8 A8])) > This leads to cprop concluding that it is valid to replace the > reference to r1 with another register having the same value before the > call. Unfortunately, sometimes a call-clobbered register is chosen. This is the rs6000 backend fix. Bootstrapped etc. powerpc64-linux. OK to apply? gcc/ * config/rs6000/rs6000.c (rs6000_call_aix): Use unspec rather than mem for toc_restore. * config/rs6000/rs6000.md (UNSPEC_TOCSLOT): Define. (call_indirect_aix, call_value_indirect_aix): Adjust to suit. (call_indirect_elfv2, call_value_indirect_elfv2): Likewise. gcc/testsuite/ * gcc.target/powerpc/cprophard.c: New. Index: gcc/config/rs6000/rs6000.c =================================================================== --- gcc/config/rs6000/rs6000.c (revision 220025) +++ gcc/config/rs6000/rs6000.c (working copy) @@ -32934,7 +32934,10 @@ rs6000_call_aix (rtx value, rtx func_desc, rtx fla rtx stack_toc_mem = gen_frame_mem (Pmode, gen_rtx_PLUS (Pmode, stack_ptr, stack_toc_offset)); - toc_restore = gen_rtx_SET (VOIDmode, toc_reg, stack_toc_mem); + rtx stack_toc_unspec = gen_rtx_UNSPEC (Pmode, + gen_rtvec (1, stack_toc_offset), + UNSPEC_TOCSLOT); + toc_restore = gen_rtx_SET (VOIDmode, toc_reg, stack_toc_unspec); /* Can we optimize saving the TOC in the prologue or do we need to do it at every call? */ Index: gcc/config/rs6000/rs6000.md =================================================================== --- gcc/config/rs6000/rs6000.md (revision 220025) +++ gcc/config/rs6000/rs6000.md (working copy) @@ -138,6 +138,7 @@ UNSPEC_PACK_128BIT UNSPEC_LSQ UNSPEC_FUSION_GPR + UNSPEC_TOCSLOT ]) ;; @@ -11348,16 +11349,16 @@ ;; Call to indirect functions with the AIX abi using a 3 word descriptor. ;; Operand0 is the addresss of the function to call ;; Operand2 is the location in the function descriptor to load r2 from -;; Operand3 is the stack location to hold the current TOC pointer +;; Operand3 is the offset of the stack location holding the current TOC pointer (define_insn "*call_indirect_aix" [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l")) (match_operand 1 "" "g,g")) (use (match_operand:P 2 "memory_operand" ",")) - (set (reg:P TOC_REGNUM) (match_operand:P 3 "memory_operand" ",")) + (set (reg:P TOC_REGNUM) (unspec [(match_operand:P 3 "const_int_operand" "n,n")] UNSPEC_TOCSLOT)) (clobber (reg:P LR_REGNO))] "DEFAULT_ABI == ABI_AIX" - " 2,%2\;b%T0l\; 2,%3" + " 2,%2\;b%T0l\; 2,%3(1)" [(set_attr "type" "jmpreg") (set_attr "length" "12")]) @@ -11366,24 +11367,24 @@ (call (mem:SI (match_operand:P 1 "register_operand" "c,*l")) (match_operand 2 "" "g,g"))) (use (match_operand:P 3 "memory_operand" ",")) - (set (reg:P TOC_REGNUM) (match_operand:P 4 "memory_operand" ",")) + (set (reg:P TOC_REGNUM) (unspec [(match_operand:P 4 "const_int_operand" "n,n")] UNSPEC_TOCSLOT)) (clobber (reg:P LR_REGNO))] "DEFAULT_ABI == ABI_AIX" - " 2,%3\;b%T1l\; 2,%4" + " 2,%3\;b%T1l\; 2,%4(1)" [(set_attr "type" "jmpreg") (set_attr "length" "12")]) ;; Call to indirect functions with the ELFv2 ABI. ;; Operand0 is the addresss of the function to call -;; Operand2 is the stack location to hold the current TOC pointer +;; Operand2 is the offset of the stack location holding the current TOC pointer (define_insn "*call_indirect_elfv2" [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l")) (match_operand 1 "" "g,g")) - (set (reg:P TOC_REGNUM) (match_operand:P 2 "memory_operand" ",")) + (set (reg:P TOC_REGNUM) (unspec [(match_operand:P 2 "const_int_operand" "n,n")] UNSPEC_TOCSLOT)) (clobber (reg:P LR_REGNO))] "DEFAULT_ABI == ABI_ELFv2" - "b%T0l\; 2,%2" + "b%T0l\; 2,%2(1)" [(set_attr "type" "jmpreg") (set_attr "length" "8")]) @@ -11391,10 +11392,10 @@ [(set (match_operand 0 "" "") (call (mem:SI (match_operand:P 1 "register_operand" "c,*l")) (match_operand 2 "" "g,g"))) - (set (reg:P TOC_REGNUM) (match_operand:P 3 "memory_operand" ",")) + (set (reg:P TOC_REGNUM) (unspec [(match_operand:P 3 "const_int_operand" "n,n")] UNSPEC_TOCSLOT)) (clobber (reg:P LR_REGNO))] "DEFAULT_ABI == ABI_ELFv2" - "b%T1l\; 2,%3" + "b%T1l\; 2,%3(1)" [(set_attr "type" "jmpreg") (set_attr "length" "8")]) 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); +}