From patchwork Thu Jan 20 16:29:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 79721 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 B1504B70E3 for ; Fri, 21 Jan 2011 03:29:18 +1100 (EST) Received: (qmail 26629 invoked by alias); 20 Jan 2011 16:29:16 -0000 Received: (qmail 26621 invoked by uid 22791); 20 Jan 2011 16:29:15 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_ZF, 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; Thu, 20 Jan 2011 16:29:09 +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.13.8/8.13.8) with ESMTP id p0KGT7LU004957 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 20 Jan 2011 11:29:08 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p0KGT7EG010463 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 20 Jan 2011 11:29:07 -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 p0KGT6tm005291 for ; Thu, 20 Jan 2011 17:29:06 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p0KGT6CN005290 for gcc-patches@gcc.gnu.org; Thu, 20 Jan 2011 17:29:06 +0100 Date: Thu, 20 Jan 2011 17:29:06 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Avoid doing empty bb ehcleanup move if PHI on the landing pad has other uses (PR tree-optimization/47355) Message-ID: <20110120162906.GY2724@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! On the attached testcase we have something like: # names$_storage_30 = PHI : goto ; : special_destroy (names$_storage_29); names$_storage_21 = names$_storage_29 + 8; names$_size_23 = names$_size_7 + -1; : # names$_storage_29 = PHI # names$_size_7 = PHI if (names$_size_7 != 0) goto ; else goto ; : D.2159_25 = (long unsigned int) names$_size_38(D); D.2160_19 = D.2159_25 * 8; names$_storage_26 = names$_storage_30 + D.2160_19; zfree (names$_storage_26); : resx 1 and ehcleanup would like to move the landing pad from the L1 block to bb 17. It sees names$_storage_30 is used in bb 17 PHI argument from that edge and just goes on with change, which means names$_storage_30 is no longer defined, but one use in bb 18 is left around. In this case we can't even replace _30 in bb18 with _29, because that value could be incremented in the loop before it. This patch fixes it by not moving the landing pad if there are other uses of the old PHI result. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2011-01-20 Jakub Jelinek PR tree-optimization/47355 * tree-eh.c (cleanup_empty_eh_merge_phis): Give up if NOP has more than a single use. * g++.dg/opt/pr47355.C: New test. Jakub --- gcc/tree-eh.c.jj 2011-01-18 18:16:11.000000000 +0100 +++ gcc/tree-eh.c 2011-01-20 11:11:48.000000000 +0100 @@ -3552,6 +3552,9 @@ cleanup_empty_eh_merge_phis (basic_block /* If we did find the corresponding PHI, copy those inputs. */ if (ophi) { + /* If NOP is used somewhere else beyond nphi, give up. */ + if (!has_single_use (nop)) + goto fail; bitmap_set_bit (ophi_handled, SSA_NAME_VERSION (nop)); FOR_EACH_EDGE (e, ei, old_bb->preds) { --- gcc/testsuite/g++.dg/opt/pr47355.C.jj 2011-01-20 11:29:54.000000000 +0100 +++ gcc/testsuite/g++.dg/opt/pr47355.C 2011-01-20 11:29:29.000000000 +0100 @@ -0,0 +1,39 @@ +// PR tree-optimization/47355 +// { dg-do compile } +// { dg-options "-O -fipa-cp -fipa-cp-clone" } + +struct T +{ + T (); + void *p; + ~T (); +}; + +void foo (T *i); + +T *bar (); +void baz (T *); + +struct V +{ + long q; + T *r; + ~V () + { + while (q) + { + foo (r); + ++r; + --q; + } + baz (r); + } +}; + +void +foo () +{ + V v; + T t; + v.r = bar (); +}