From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27795 invoked by alias); 30 Nov 2012 16:17:16 -0000 Received: (qmail 27774 invoked by uid 22791); 30 Nov 2012 16:17:13 -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; Fri, 30 Nov 2012 16:17:02 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qAUGGxNZ011491 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 30 Nov 2012 11:16:59 -0500 Received: from redhat.com (ovpn-116-24.ams2.redhat.com [10.36.116.24]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qAUGGtnP012826 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 30 Nov 2012 11:16:58 -0500 Date: Fri, 30 Nov 2012 16:28:00 -0000 From: Marek Polacek To: Richard Biener Cc: Eric Botcazou , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Don't bypass blocks with multiple latch edges (PR middle-end/54838) Message-ID: <20121130161654.GG10621@redhat.com> References: <20121126142843.GH17362@redhat.com> <20121129153852.GC10621@redhat.com> <5890792.ZMS3qalP0H@polaris> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2012-11/txt/msg02557.txt.bz2 On Fri, Nov 30, 2012 at 10:01:37AM +0100, Richard Biener wrote: > RTL cprop seems to run both before and after RTL loop optimizers (currently > after RTL loop optimizers we throw away loops - an arbitrary chosen point > before IRA across which I could not get things to work). Thus you could do > > if (current_loops) > is_loop_header = bb == bb->loop_father->header; > else > { > may_be_loop_header = false; > FOR_EACH_EDGE (e, ei, bb->preds) > if (e->flags & EDGE_DFS_BACK) > { > may_be_loop_header = true; > break; > } > } I can do this as a followup. > I don't understand > > /* The irreducible loops created by redirecting of edges entering the > loop from outside would decrease effectiveness of some of the > following optimizations, so prevent this. */ > if (may_be_loop_header > && !(e->flags & EDGE_DFS_BACK)) > { > ei_next (&ei); > continue; > } > > why isn't this simply > > if (may_be_loop_header) > { > ei_next (&ei); > continue; > } > > ? It looks like the code tries to allow "rotating" a loop - but that's only > good if bb has exactly two predecessors (one entry and one latch edge). > And even then it requires to manually update the loop structures (update > what the new header and latch blocks are). > > That said, removing the !(e->flags & EDGE_DFS_BACK) condition seems > to fix the ICE. Threading across a loop header is in fact complicated > (see the special routine tree-ssa-threadupdate.c:thread_through_loop_header > necessary for that). Let's declare the GIMPLE level did all interesting > threadings through headers. Agreed. This is the fix I had some time ago, but at that time it didn't seem like such a great idea. Done this time around. Regtested/bootstrapped on x86_64-linux, ok for trunk? 2012-11-30 Marek Polacek PR middle-end/54838 * cprop.c (bypass_block): Skip header edges. * gcc.dg/pr54838.c: New test. --- gcc/cprop.c.mp 2012-11-29 15:49:53.120524295 +0100 +++ gcc/cprop.c 2012-11-30 10:30:23.509501957 +0100 @@ -1539,8 +1539,7 @@ bypass_block (basic_block bb, rtx setcc, /* The irreducible loops created by redirecting of edges entering the loop from outside would decrease effectiveness of some of the following optimizations, so prevent this. */ - if (may_be_loop_header - && !(e->flags & EDGE_DFS_BACK)) + if (may_be_loop_header) { ei_next (&ei); continue; --- gcc/testsuite/gcc.dg/pr54838.c.mp 2012-11-26 14:48:43.783980854 +0100 +++ gcc/testsuite/gcc.dg/pr54838.c 2012-11-29 17:43:19.397737779 +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; + } +} Marek