From patchwork Tue Oct 23 15:38:09 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 193517 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 932832C00F3 for ; Wed, 24 Oct 2012 02:38:35 +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=1351611515; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To: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=SrsRbJGMW03JKvi3+l0Q ofc3DQQ=; b=hQy0JOnP+8RFvr+Kr2O+mCH8XtDOkaImjWtllz/NUvX5R2Y313Kg Kwb4MiZEOKwsKsQE3qXxvAQJBKzgFh2d/yEjEH/50cwHPBoGvfM4Bjg12CURh5fe G6y8VWU5HQAoz0Yc4KL0Pk9kL0xq/FSZmRfXXp3Z405hY5Of8yE/Qxk= 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: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=O8rQWVCIFsSu5xbQXrYkUPImW+8APq1C2VMkwu37KSzBzl0LV43YbNYl7yQZjT zul/PRHCvFhIj+M3lnqB2ExdWHEC5vSvMTW1NyeuYofWuMYgDGU1IuAmEREiEZSW JSHg94ooHOfGJGQMs2wfAjjtCZM4kstiU8OMAwXjE0fiM=; Received: (qmail 758 invoked by alias); 23 Oct 2012 15:38:30 -0000 Received: (qmail 749 invoked by uid 22791); 23 Oct 2012 15:38:29 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_HF 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, 23 Oct 2012 15:38:20 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9NFcJF5032126 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 23 Oct 2012 11:38:19 -0400 Received: from zalov.redhat.com (vpn1-6-28.ams2.redhat.com [10.36.6.28]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9NFcGfE010211 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 23 Oct 2012 11:38:17 -0400 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id q9NFcFde022422 for ; Tue, 23 Oct 2012 17:38:16 +0200 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id q9NFcFja022421 for gcc-patches@gcc.gnu.org; Tue, 23 Oct 2012 17:38:15 +0200 Date: Tue, 23 Oct 2012 17:38:09 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Invalidate in cselib sp after processing frame_pointer_needed fp setter (PR rtl-optimization/54921) Message-ID: <20121023153809.GR1752@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! This is an attempt to hopefully end the endless stream of aliasing miscompilations where alias.c assumes that hfp based accesses can't alias sp based accesses, but both sp and fp can appear in VALUEs pretty much randomly. As detailed in the PR, we have the r variable at rbp - 48 and rsp is also rbp - 48, some stores use direct rbp - 44 based addresses which then have find_base_term of the value equal to (address:DI -4), other stores use rdi == r9 based address, where r9 is r8 + 4 and r8 is rbp - 48, but value for r8 has r8 as well as rsp registers in its locs and therefore find_base_term returns (address:DI -1) - i.e. sp based term, and alias.c says those two can't alias even when they actually do. The fix is what I've done recently in var-tracking.c, invalidate sp if frame_pointer_needed right after the fp setter insn, so we then have a set of VALUEs which are based on rbp and a different set of values which are based on rsp, but those two sets are now disjoint. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2012-10-23 Jakub Jelinek PR rtl-optimization/54921 * cselib.c (cselib_process_insn): If frame_pointer_needed, call cselib_invalidate_rtx (stack_pointer_rtx) after processing a frame pointer setter in the prologue. * gcc.dg/pr54921.c: New test. Jakub --- gcc/cselib.c.jj 2012-10-16 13:20:25.000000000 +0200 +++ gcc/cselib.c 2012-10-23 14:22:17.694861625 +0200 @@ -2655,6 +2655,34 @@ cselib_process_insn (rtx insn) if (GET_CODE (XEXP (x, 0)) == CLOBBER) cselib_invalidate_rtx (XEXP (XEXP (x, 0), 0)); + /* On setter of the hard frame pointer if frame_pointer_needed, + invalidate stack_pointer_rtx, so that sp and {,h}fp based + VALUEs are distinct. */ + if (reload_completed + && frame_pointer_needed + && RTX_FRAME_RELATED_P (insn) + && BLOCK_FOR_INSN (insn) == single_succ (ENTRY_BLOCK_PTR)) + { + rtx pat = PATTERN (insn); + rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX); + if (expr) + pat = XEXP (expr, 0); + if (GET_CODE (pat) == SET + && SET_DEST (pat) == hard_frame_pointer_rtx) + cselib_invalidate_rtx (stack_pointer_rtx); + else if (GET_CODE (pat) == PARALLEL) + { + int i; + for (i = XVECLEN (pat, 0) - 1; i >= 0; i--) + if (GET_CODE (XVECEXP (pat, 0, i)) == SET + && SET_DEST (XVECEXP (pat, 0, i)) == hard_frame_pointer_rtx) + { + cselib_invalidate_rtx (stack_pointer_rtx); + break; + } + } + } + cselib_current_insn = NULL_RTX; if (n_useless_values > MAX_USELESS_VALUES --- gcc/testsuite/gcc.dg/pr54921.c.jj 2012-10-23 14:17:49.811466882 +0200 +++ gcc/testsuite/gcc.dg/pr54921.c 2012-10-23 14:17:32.000000000 +0200 @@ -0,0 +1,32 @@ +/* PR rtl-optimization/54921 */ +/* { dg-do run } */ +/* { dg-options "-Os -fno-omit-frame-pointer -fsched2-use-superblocks -ftree-slp-vectorize" } */ +/* { dg-additional-options "-fstack-protector" { target fstack_protector } } */ + +struct A +{ + int a; + char b[32]; +} a, b; + +__attribute__((noinline, noclone)) +struct A +bar (int x) +{ + struct A r; + static int n; + r.a = ++n; + __builtin_memset (r.b, 0, sizeof (r.b)); + r.b[0] = x; + return r; +} + +int +main () +{ + a = bar (3); + b = bar (4); + if (a.a != 1 || a.b[0] != 3 || b.a != 2 || b.b[0] != 4) + __builtin_abort (); + return 0; +}