From patchwork Sat Dec 1 16:18:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 203140 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 F3CD12C0086 for ; Sun, 2 Dec 2012 03:18:53 +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=1354983534; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=DbwTvKmGgpvBRiz9v9cE CiyD5Ps=; b=DFTYx4WSTVVja319izOpzSybJ0szZnZNclkpJkQ13eP078qUA/Em nrYEeUNhTUhALIXkJU6001zjntYz585tmnp0ZWTmZxZrvebVSZi5j1bHZR7M0Dbb G4DXUi7kc6XAtEzkCnJQiuJLuN0EOls9tK+d7W98e1SEGP4yk+hDoNs= 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:Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Cu4uoO5QY/CNWsFy7UIFNFvoxbuy7o22EmOv4HJVJ009ytx2gLXXhdXUgQfrwI llXre1PnceB9WbUsj64kyAhu9DWb/mWm/3w5n3EHF4ZT/GKyrk++VlsnKjScWpd5 dkHl/TvKXlcz/jkSbhGnnsUn+Dkp16Z01CuYAX2ZmDIuc=; Received: (qmail 2053 invoked by alias); 1 Dec 2012 16:18:46 -0000 Received: (qmail 2031 invoked by uid 22791); 1 Dec 2012 16:18:44 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS 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; Sat, 01 Dec 2012 16:18:34 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qB1GIWpT026229 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 1 Dec 2012 11:18:32 -0500 Received: from redhat.com (ovpn-116-24.ams2.redhat.com [10.36.116.24]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qB1GIRJN018788 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Sat, 1 Dec 2012 11:18:31 -0500 Date: Sat, 1 Dec 2012 17:18:26 +0100 From: Marek Polacek To: Eric Botcazou Cc: gcc-patches@gcc.gnu.org, Richard Biener Subject: Re: [PATCH] Don't bypass blocks with multiple latch edges (PR middle-end/54838) Message-ID: <20121201161826.GH10621@redhat.com> References: <20121126142843.GH17362@redhat.com> <20121129153852.GC10621@redhat.com> <3679567.118qcDcHed@polaris> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <3679567.118qcDcHed@polaris> User-Agent: Mutt/1.5.20 (2009-06-14) 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 On Fri, Nov 30, 2012 at 11:00:28PM +0100, Eric Botcazou wrote: > OK, let's tweak the patch as follows: > 1) when current_loops is not NULL, we compute may_be_loop_header and whether > the loop has more than 1 latch edge exactly, > 2) when current_loops is NULL, we use your above method to do the same, > 3) once this is done, we return from the function before entering the loop if > this is a (potential) header with more than 1 (potential) latch edge. The > comment can say that threading through a loop header with more than 1 latch > edge is delicate and cite tree-threadupdate.c:thread_through_loop_header. Like this? Regtested/bootstrapped on x86_64-linux, ok for trunk? 2012-12-01 Marek Polacek PR middle-end/54838 * cprop.c (bypass_block): Determine number of latches. Return when there is more than one latch edge. * gcc.dg/pr54838.c: New test. Marek --- gcc/cprop.c.mp 2012-11-29 15:49:53.120524295 +0100 +++ gcc/cprop.c 2012-12-01 16:14:59.387335461 +0100 @@ -1510,13 +1510,28 @@ bypass_block (basic_block bb, rtx setcc, if (note) find_used_regs (&XEXP (note, 0), NULL); - may_be_loop_header = false; - FOR_EACH_EDGE (e, ei, bb->preds) - if (e->flags & EDGE_DFS_BACK) - { - may_be_loop_header = true; - break; - } + /* Determine whether there are more latch edges. Threading through + a loop header with more than one latch is delicate, see e.g. + tree-ssa-threadupdate.c:thread_through_loop_header. */ + if (current_loops) + { + may_be_loop_header = bb == bb->loop_father->header; + if (may_be_loop_header + && bb->loop_father->latch == NULL) + return 0; + } + else + { + unsigned n_back_edges = 0; + FOR_EACH_EDGE (e, ei, bb->preds) + if (e->flags & EDGE_DFS_BACK) + n_back_edges++; + + may_be_loop_header = n_back_edges > 0; + + if (n_back_edges > 1) + return 0; + } change = 0; for (ei = ei_start (bb->preds); (e = ei_safe_edge (ei)); ) --- gcc/testsuite/gcc.dg/pr54838.c.mp 2012-11-26 14:48:43.783980854 +0100 +++ gcc/testsuite/gcc.dg/pr54838.c 2012-11-26 14:49:51.051158719 +0100 @@ -0,0 +1,24 @@ +/* PR middle-end/54838 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-forward-propagate -ftracer" } */ + +void bar (void); + +void +foo (void *b, int *c) +{ +again: + switch (*c) + { + case 1: + if (!b) + { + bar (); + return; + } + goto again; + case 3: + if (!b) + goto again; + } +}