From patchwork Sun Oct 14 20:47:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 191422 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 4438D2C0098 for ; Mon, 15 Oct 2012 07:49:52 +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=1350852593; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version: Content-Type:Content-Transfer-Encoding:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=OLfJY9vBLNVXPKq8mL/yeSUSDqo=; b=RH502A4jYfDEWaj G7tCxYCaJhQ0+MRYCwh2/mjnxjsz6osW5CBWbtJ8lXTLo0fMz5zn2WPM664MmSlm cH4taOt5o/9Guqbve5uFaE9Ek62CYJBD02T7SHbTLt9Y1GSwH9bTco8CzX7lp6qe qKNG5m2u7S0nDnqcrAsvm2KIfnWc= 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:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type:Content-Transfer-Encoding:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=cjYvx5wD2YUkhJpelp1w45I11SQNEV5XRPDbd4LX42/wR0aVJXvA/Ha3gopebr M59MnVby8xQ3fTjCWBHYKxBDYJSYtANqVM5ctxiXrijuOdd1rH6uLAvA9URUcGDy fv/pce1nQJk5i1hYe3bHG84hBgjPLA+9z2iTo5rbT24zY=; Received: (qmail 14789 invoked by alias); 14 Oct 2012 20:49:45 -0000 Received: (qmail 14775 invoked by uid 22791); 14 Oct 2012 20:49:44 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,TW_CP X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 14 Oct 2012 20:49:39 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id B6EDB290036 for ; Sun, 14 Oct 2012 22:49:50 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xH2v-xbbV8Kq for ; Sun, 14 Oct 2012 22:49:50 +0200 (CEST) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id 84279290010 for ; Sun, 14 Oct 2012 22:49:50 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Fix PR rtl-optimization/54870 Date: Sun, 14 Oct 2012 22:47:12 +0200 Message-ID: <8550101.ZHQCWdrEkP@polaris> User-Agent: KMail/4.7.2 (Linux/3.1.10-1.16-desktop; KDE/4.7.2; x86_64; ; ) MIME-Version: 1.0 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 the execution failure of gfortran.dg/array_constructor_4.f90 in 64-bit mode on SPARC/Solaris at -O3. The dse2 dump for the reduced testcase reads: dse: local deletions = 0, global deletions = 1, spill deletions = 0 starting the processing of deferred insns deleting insn with uid = 25. ending the processing of deferred insns but the memory location stored to: (insn 25 27 154 2 (set (mem/c:SI (plus:DI (reg/f:DI 30 %fp) (const_int 2039 [0x7f7])) [6 A.1+16 S4 A64]) (reg:SI 1 %g1 [136])) array_constructor_4.f90:4 61 {*movsi_insn} (nil)) is read by a subsequent call to memcpy. It turns out that this memcpy call is generated for an aggregate assignment: MEM[(c_char * {ref-all})&i] = MEM[(c_char * {ref-all})&A.17]; Note the A.1 in the store and the A.17 in the load. A.1 and A.17 are aggregate variables sharing the same stack slot. A.17 is correcty marked as addressable because of the call to memcpy, but A.1 isn't since its address isn't taken, and DSE can optimize away (since 4.7) stores if their MEM_EXPR doesn't escape. The store is reaching the load because an intermediate store into A.17: (insn 78 76 82 6 (set (mem/c:SI (plus:DI (reg/f:DI 30 %fp) (const_int 2039 [0x7f7])) [6 A.17+16 S4 A64]) (reg:SI 1 %g1 [136])) array_constructor_4.f90:14 61 {*movsi_insn} (nil)) has been deleted by postreload as no-op (because redundant), thus making A.1 partially escape without marking it as addressable. The attached patch uses cfun->gimple_df->escaped.vars to plug the hole: when mark_addressable is called during RTL expansion and the decl is partitioned, all the variables in the partition are added to the bitmap. Then can_escape is changed to additionally test cfun->gimple_df->escaped.vars. Tested on x86-64/Linux and SPARC64/Solaris, OK for mainline and 4.7 branch? 2012-10-14 Eric Botcazou PR rtl-optimization/54870 * dse.c (can_escape): Test cfun->gimple_df->escaped.vars as well. * gimplify.c (mark_addressable): If this is a partition decl, add all the variables in the partition to cfun->gimple_df->escaped.vars. Index: dse.c =================================================================== --- dse.c (revision 192353) +++ dse.c (working copy) @@ -990,6 +990,7 @@ delete_dead_store_insn (insn_info_t insn } /* Check if EXPR can possibly escape the current function scope. */ + static bool can_escape (tree expr) { @@ -998,7 +999,10 @@ can_escape (tree expr) return true; base = get_base_address (expr); if (DECL_P (base) - && !may_be_aliased (base)) + && !may_be_aliased (base) + && !(cfun->gimple_df->escaped.vars + && bitmap_bit_p (cfun->gimple_df->escaped.vars, + DECL_PT_UID (base)))) return false; return true; } Index: gimplify.c =================================================================== --- gimplify.c (revision 192353) +++ gimplify.c (working copy) @@ -116,6 +116,26 @@ mark_addressable (tree x) && TREE_CODE (x) != RESULT_DECL) return; TREE_ADDRESSABLE (x) = 1; + + /* If this is a partitioned decl, we need to mark all the variables in the + partition as escaped. This is needed because a store into one of them + can be replaced with a store into another, and this may not change the + outcome of the escape analysis for DSE to work properly. */ + if (TREE_CODE (x) == VAR_DECL + && !TREE_STATIC (x) + && cfun->gimple_df != NULL + && cfun->gimple_df->decls_to_pointers != NULL) + { + void *namep + = pointer_map_contains (cfun->gimple_df->decls_to_pointers, x); + if (namep) + { + struct ptr_info_def *pi = get_ptr_info (*(tree *)namep); + if (cfun->gimple_df->escaped.vars == NULL) + cfun->gimple_df->escaped.vars = BITMAP_GGC_ALLOC (); + bitmap_ior_into (cfun->gimple_df->escaped.vars, pi->pt.vars); + } + } } /* Return a hash value for a formal temporary table entry. */