From patchwork Tue Nov 9 19:11:12 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 70570 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 8197AB7124 for ; Wed, 10 Nov 2010 06:11:23 +1100 (EST) Received: (qmail 28470 invoked by alias); 9 Nov 2010 19:11:21 -0000 Received: (qmail 28457 invoked by uid 22791); 9 Nov 2010 19:11:20 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD 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, 09 Nov 2010 19:11:15 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oA9JBEdt029997 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 9 Nov 2010 14:11:14 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oA9JBDo0020005 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 9 Nov 2010 14:11:13 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id oA9JBCGE023762 for ; Tue, 9 Nov 2010 20:11:13 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id oA9JBCT7023761 for gcc-patches@gcc.gnu.org; Tue, 9 Nov 2010 20:11:12 +0100 Date: Tue, 9 Nov 2010 20:11:12 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [committed] Fix stack slot coalescing at -O0 (PR target/43808) Message-ID: <20101109191112.GV29412@tyan-ft48-01.lab.bos.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! If -O0 is used together with passes that use alias into in the RTL (e.g. scheduling), we may miscompile code, as update_alias_info_with_stack_vars wasn't being called and thus a !may_be_alias var which shared a stack slot with a may_be_alias var could result in wrong scheduling. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, acked by Richard on IRC, committed to trunk. 2010-11-09 Jakub Jelinek PR target/43808 * cfgexpand.c (partition_stack_vars): Call update_alias_info_with_stack_vars unconditionally. (update_alias_info_with_stack_vars): Allow unused unreferenced vars when not optimizing. * gfortran.dg/pr43808.f90: New test. Jakub --- gcc/cfgexpand.c.jj 2010-11-03 16:58:31.000000000 +0100 +++ gcc/cfgexpand.c 2010-11-08 17:34:22.000000000 +0100 @@ -516,9 +516,11 @@ update_alias_info_with_stack_vars (void) unsigned int uid = DECL_PT_UID (decl); /* We should never end up partitioning SSA names (though they may end up on the stack). Neither should we allocate stack - space to something that is unused and thus unreferenced. */ + space to something that is unused and thus unreferenced, except + for -O0 where we are preserving even unreferenced variables. */ gcc_assert (DECL_P (decl) - && referenced_var_lookup (DECL_UID (decl))); + && (!optimize + || referenced_var_lookup (DECL_UID (decl)))); bitmap_set_bit (part, uid); *((bitmap *) pointer_map_insert (decls_to_partitions, (void *)(size_t) uid)) = part; @@ -684,8 +686,7 @@ partition_stack_vars (void) } } - if (optimize) - update_alias_info_with_stack_vars (); + update_alias_info_with_stack_vars (); } /* A debugging aid for expand_used_vars. Dump the generated partitions. */ --- gcc/testsuite/gfortran.dg/pr43808.f90.jj 2010-11-08 17:32:16.000000000 +0100 +++ gcc/testsuite/gfortran.dg/pr43808.f90 2010-11-08 17:30:41.000000000 +0100 @@ -0,0 +1,18 @@ +! PR target/43808 +! { dg-do run } +! { dg-options "-O0 -fipa-reference -fschedule-insns -fstrict-aliasing" } + + type :: a + integer, allocatable :: i(:) + end type a + type :: b + type (a), allocatable :: j(:) + end type b + type(a) :: x(2) + type(b) :: y(2) + x(1) = a((/1,2,3,4/)) + x(2) = a((/1,2,3,4/)+10) + y(1) = b((/x(1),x(2)/)) + y(2) = b((/x(1),x(2)/)) + if (y(1)%j(1)%i(1) .ne. 1) call abort +end