From patchwork Fri Jan 28 23:06:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Bergner X-Patchwork-Id: 80905 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 14221B7109 for ; Sat, 29 Jan 2011 10:06:30 +1100 (EST) Received: (qmail 26913 invoked by alias); 28 Jan 2011 23:06:28 -0000 Received: (qmail 26905 invoked by uid 22791); 28 Jan 2011 23:06:28 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from e6.ny.us.ibm.com (HELO e6.ny.us.ibm.com) (32.97.182.146) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 28 Jan 2011 23:06:23 +0000 Received: from d01dlp02.pok.ibm.com (d01dlp02.pok.ibm.com [9.56.224.85]) by e6.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p0SMpxlw026101 for ; Fri, 28 Jan 2011 17:52:00 -0500 Received: from d01relay03.pok.ibm.com (d01relay03.pok.ibm.com [9.56.227.235]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 46D524DE803F for ; Fri, 28 Jan 2011 18:05:53 -0500 (EST) Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay03.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p0SN6IAP316640 for ; Fri, 28 Jan 2011 18:06:18 -0500 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p0SN6ILt008694 for ; Fri, 28 Jan 2011 18:06:18 -0500 Received: from [192.168.1.101] (vorma.rchland.ibm.com [9.10.86.174]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p0SN6HFY008500; Fri, 28 Jan 2011 18:06:17 -0500 Subject: [PATCH, dataflow] PR47525 DCE fails to eliminate dead calls to pure functions From: Peter Bergner To: gcc-patches Cc: Kenneth Zadeck , Paolo Bonzini Date: Fri, 28 Jan 2011 17:06:15 -0600 Message-ID: <1296255975.2625.41.camel@otta> Mime-Version: 1.0 X-Content-Scanned: Fidelis XPS MAILER 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 Tracking down some test suite failures while doing a --with-cpu=power7 build, I noticed that DCE is no longer eliminating dead calls to const or pure function calls. This is due to all global registers being added to every call's use and def chains, even though const functions won't reference them at all and pure functions won't set them. The following patch fixes that and has bootstrapped and regtested with no regressions. This is a regression since it works in gcc 4.3, but fails in gcc 4.4, 4.5 and trunk, but I understand it only a performance issue and not a correctness issue. Is that patch OK? If so, do we want this in mainline now or after 4.6 has branched? Peter PR rtl-optimization/47525 * df-scan.c: Update copyright years. (df_get_call_refs): Do not mark global registers as DF_REF_REG_USE and non-clobber DF_REF_REG_DEF for calls to const and pure functions. Index: df-scan.c =================================================================== --- df-scan.c (revision 169365) +++ df-scan.c (working copy) @@ -1,6 +1,6 @@ /* Scanning of rtl for dataflow analysis. Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, - 2008, 2009, 2010 Free Software Foundation, Inc. + 2008, 2009, 2010, 2011 Free Software Foundation, Inc. Originally contributed by Michael P. Hayes (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com) Major rewrite contributed by Danny Berlin (dberlin@dberlin.org) @@ -3360,16 +3360,19 @@ df_get_call_refs (struct df_collection_r NULL, bb, insn_info, DF_REF_REG_USE, DF_REF_CALL_STACK_USAGE | flags); - /* Calls may also reference any of the global registers, - so they are recorded as used. */ - for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) - if (global_regs[i]) - { - df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i], - NULL, bb, insn_info, DF_REF_REG_USE, flags); - df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i], - NULL, bb, insn_info, DF_REF_REG_DEF, flags); - } + /* Calls to const functions cannot access any global registers and calls to + pure functions cannot set them. All other calls may reference any of the + global registers, so they are recorded as used. */ + if (!RTL_CONST_CALL_P (insn_info->insn)) + for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) + if (global_regs[i]) + { + df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i], + NULL, bb, insn_info, DF_REF_REG_USE, flags); + if (!RTL_PURE_CALL_P (insn_info->insn)) + df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i], + NULL, bb, insn_info, DF_REF_REG_DEF, flags); + } is_sibling_call = SIBLING_CALL_P (insn_info->insn); EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset, 0, ui, bi)