From patchwork Tue Jan 22 14:13:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 214558 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 CBB312C007C for ; Wed, 23 Jan 2013 01:13:51 +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=1359468832; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=qjAFenDTMjl2UTYVaIeSwIkxSBI=; b=nlpFBXGU+ioM9we PpPn9IrYlmIctGIvlL3hPdGinMLze+FmJTm+Ax9l9V4/5GXxo9OjvmmIUBOgU/+H iv38UtI86igR9Wd6iSjjtriEfAqjWSENvbThiXbr7PP3I51jrbxKRnAC6BGYoSpk KnxUDS+v1tSooHXPhx8NSH5hZw3U= 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:MIME-Version:Content-Type:Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=OKNG/EqFwBQUkW779KnPMIRHhq1Z1uiBtTSA711IwvcJutnePxw223vzKVXs81 tewE3g5qDpIQc4zjUQlb+YnyJoWr/I250U0LkbEsy7xoIFrwgFOV28VnVRe9lt/E LdnQux/jDfKvE0FCZ64+P/yWWdpOsKFSx+MWUzL5RIux8=; Received: (qmail 28149 invoked by alias); 22 Jan 2013 14:13:36 -0000 Received: (qmail 28133 invoked by uid 22791); 22 Jan 2013 14:13:35 -0000 X-SWARE-Spam-Status: No, hits=-6.5 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; Tue, 22 Jan 2013 14:13:05 +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.14.4/8.14.4) with ESMTP id r0MED4VB011098 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 22 Jan 2013 09:13:04 -0500 Received: from redhat.com (ovpn-116-17.ams2.redhat.com [10.36.116.17]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0MED0xs026814 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 22 Jan 2013 09:13:03 -0500 Date: Tue, 22 Jan 2013 15:13:00 +0100 From: Marek Polacek To: GCC Patches Cc: Richard Guenther , Zdenek Dvorak Subject: [PATCH] Fix PR56035 Message-ID: <20130122141300.GD18759@redhat.com> MIME-Version: 1.0 Content-Disposition: inline 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 We ICEd on attached testcase because we didn't properly detected the latch edge. Furthermore, I think the code for re-computing latches is somehow broken at the moment. In fix_loop_structure we have /* If there was no latch, schedule the loop for removal. */ if (!first_latch) loop->header = NULL; /* If there was a single latch and it belongs to the loop of the header, record it. */ else if (latch && latch->src->loop_father == loop) loop->latch = latch->src; /* Otherwise there are multiple latches which are eventually disambiguated below. */ else loop->latch = NULL; but I don't think we can use the ->loop_father info, because that is already cleared by FOR_EACH_BB (bb) { if (changed_bbs) bb->aux = (void *) (size_t) loop_depth (bb->loop_father); bb->loop_father = current_loops->tree_root; } earlier on. Thus we ended up in the last else branch and NULLed loop->latch, which is clearly wrong. This patch just moves the hunk above so that we reset ->loop_father-s only after re-computing loop latches. Regtested/bootstraped on x86_64-linux, ok for trunk? 2013-01-22 Marek Polacek * cfgloopmanip.c (fix_loop_structure): Move clearing bb-to-loop mapping after re-computing latches. * testsuite/gcc.dg/pr56035.c: New test. Marek --- gcc/cfgloopmanip.c.mp 2013-01-22 14:11:25.241233824 +0100 +++ gcc/cfgloopmanip.c 2013-01-22 14:11:42.364285826 +0100 @@ -1784,16 +1784,6 @@ fix_loop_structure (bitmap changed_bbs) /* We need exact and fast dominance info to be available. */ gcc_assert (dom_info_state (CDI_DOMINATORS) == DOM_OK); - /* Remove the old bb -> loop mapping. Remember the depth of the blocks in - the loop hierarchy, so that we can recognize blocks whose loop nesting - relationship has changed. */ - FOR_EACH_BB (bb) - { - if (changed_bbs) - bb->aux = (void *) (size_t) loop_depth (bb->loop_father); - bb->loop_father = current_loops->tree_root; - } - if (loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS)) { release_recorded_exits (); @@ -1834,6 +1824,16 @@ fix_loop_structure (bitmap changed_bbs) loop->latch = NULL; } + /* Remove the old bb -> loop mapping. Remember the depth of the blocks in + the loop hierarchy, so that we can recognize blocks whose loop nesting + relationship has changed. */ + FOR_EACH_BB (bb) + { + if (changed_bbs) + bb->aux = (void *) (size_t) loop_depth (bb->loop_father); + bb->loop_father = current_loops->tree_root; + } + /* Remove the dead loops from structures. We start from the innermost loops, so that when we remove the loops, we know that the loops inside are preserved, and do not waste time relinking loops that will be --- gcc/testsuite/gcc.dg/pr56035.c.mp 2013-01-22 14:27:21.104614758 +0100 +++ gcc/testsuite/gcc.dg/pr56035.c 2013-01-22 14:31:01.642266091 +0100 @@ -0,0 +1,35 @@ +/* PR tree-optimization/56035 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -ftree-vectorize -fcse-follow-jumps -fstrict-overflow" } */ + +short a, c, *p; + +void +f (void) +{ + int b; + + if (c) + lbl1: + for (a = 0; a < 1; a++) + { + for (c = 0; c < 1; c++) + { + goto lbl1; + while (*p++) + lbl2: + ; + } + } + + for (;; b++) + { + if (c) + goto lbl2; + lbl3: + for (c = 0; c < 9; c++) + for (c = -17; c < 2; c++) + if (*p) + goto lbl3; + } +}