From patchwork Tue Jan 15 22:38:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 212349 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]) by ozlabs.org (Postfix) with SMTP id 3A4D72C0097 for ; Wed, 16 Jan 2013 09:39:25 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1358894367; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=zCMfBmvLac5bTotXIr0I ud2ihRY=; b=HNQ8Kcmmk8SRd4agoWgaoH0hGc+BY3EGjxTV/r85S9Cgkp0XqBuu biY3zldQtY/wL+fxfyZR/dPv+6jkmB3aqiY05ZThAIOiP5h6r3k48MT2dGkafQHP /xAzYzQLU5k5BJCNUH0CkOxf05uv0zpNOmJog3Dz1U59RoPJDNK0pdM= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=l+NpOiPpXzeHbDBaJeYCC76ISUdgQuqxIJ1ULCUW2qr4rLO0DN0N19fbEfxNP6 Xdk4GaY/6UxPeoa2Uw1hniJlf5YNKO/H8SXV7ERVdOack7ByW3mKdf+vdHc777hn pODzLK5NxIfcJPsjRtF1/q/fdU2cObnE6Su8Md8gADPcc=; Received: (qmail 16387 invoked by alias); 15 Jan 2013 22:39:16 -0000 Received: (qmail 16363 invoked by uid 22791); 15 Jan 2013 22:39:12 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 15 Jan 2013 22:38:37 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r0FMcZLT013343 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 15 Jan 2013 17:38:35 -0500 Received: from zalov.redhat.com (vpn1-5-224.ams2.redhat.com [10.36.5.224]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0FMcXDm020546 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 15 Jan 2013 17:38:34 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id r0FMcWRr026337; Tue, 15 Jan 2013 23:38:32 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r0FMcVvt026336; Tue, 15 Jan 2013 23:38:31 +0100 Date: Tue, 15 Jan 2013 23:38:31 +0100 From: Jakub Jelinek To: Richard Henderson , Bernd Schmidt Cc: gcc-patches@gcc.gnu.org, "H.J. Lu" Subject: [PATCH] Fix shrink-wrapping with vDRAP (PR target/55940) Message-ID: <20130115223831.GD7269@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! As the following testcase shows, even when stack_realign_drap we might need to prevent crtl->drap_reg accesses in the bbs considered for shrink-wrapping, even if reload decides stack realignment isn't needed, the vDRAP (in the testcase %edi) can be used by the first bbs and initialized only later on in the prologue. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2013-01-15 Jakub Jelinek PR target/55940 * function.c (thread_prologue_and_epilogue_insns): Always add crtl->drap_reg to set_up_by_prologue.set, even if stack_realign_drap is false. * gcc.dg/pr55940.c: New test. Jakub --- gcc/function.c.jj 2013-01-11 09:02:55.000000000 +0100 +++ gcc/function.c 2013-01-15 19:23:20.648826011 +0100 @@ -6029,7 +6029,7 @@ thread_prologue_and_epilogue_insns (void if (pic_offset_table_rtx) add_to_hard_reg_set (&set_up_by_prologue.set, Pmode, PIC_OFFSET_TABLE_REGNUM); - if (stack_realign_drap && crtl->drap_reg) + if (crtl->drap_reg) add_to_hard_reg_set (&set_up_by_prologue.set, GET_MODE (crtl->drap_reg), REGNO (crtl->drap_reg)); --- gcc/testsuite/gcc.dg/pr55940.c.jj 2013-01-15 20:33:21.288921765 +0100 +++ gcc/testsuite/gcc.dg/pr55940.c 2013-01-15 20:33:03.000000000 +0100 @@ -0,0 +1,54 @@ +/* PR target/55940 */ +/* { dg-do run } */ +/* { dg-options "-Os" } */ +/* { dg-additional-options "-mpreferred-stack-boundary=2" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */ + +struct S { int s; unsigned long t; }; + +__attribute__ ((noinline, noclone)) unsigned long long +bar (struct S *x, unsigned long y) +{ + asm volatile ("" : : "r" (x), "r" (y) : "memory"); + return x->s + y; +} + +__attribute__ ((noinline, noclone)) unsigned long long +foo (struct S *x, unsigned long y) +{ + unsigned long a; + if (__builtin_expect (((__UINTPTR_TYPE__) (x) + 0x1000U < 0x2000U), 0)) + return ~0ULL; + if (__builtin_expect (x->s <= 0 || x->s > 9, 0)) + return ~0ULL; + a = x->t >> 12; + if (y == a) + return ~0ULL; + if (x->s == 3) + return x->t + y * 4096; + return bar (x, y); +} + +int va, vb, vc, vd; + +int +main () +{ + struct S s; + asm volatile ("" : : : "memory"); + int a = va, b = vb, c = vc, d = vd; + asm volatile ("" : : : "memory"); + int i; + for (i = 0; i < 64; i++) + if (foo ((struct S *) 0, 0) != ~0ULL) + __builtin_abort (); + s.s = 3; + s.t = 2 << 12; + if (foo (&s, 2) != ~0ULL) + __builtin_abort (); + if (foo (&s, 3) != (2 << 12) + 3 * 4096) + __builtin_abort (); + asm volatile ("" : : : "memory"); + va = a; vb = b; vc = c; vd = d; + asm volatile ("" : : : "memory"); + return 0; +}