From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 34853 invoked by alias); 24 Nov 2015 15:08:57 -0000 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 Received: (qmail 34838 invoked by uid 89); 24 Nov 2015 15:08:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: fencepost.gnu.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (208.118.235.10) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 24 Nov 2015 15:08:55 +0000 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33925) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1a1FDA-0003Va-M8 for gcc-patches@gnu.org; Tue, 24 Nov 2015 10:08:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1FD6-00065t-52 for gcc-patches@gnu.org; Tue, 24 Nov 2015 10:08:52 -0500 Received: from relay1.mentorg.com ([192.94.38.131]:52760) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1FD5-00064f-Sp for gcc-patches@gnu.org; Tue, 24 Nov 2015 10:08:48 -0500 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-05.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1a1FD4-0001hd-7I from Tom_deVries@mentor.com ; Tue, 24 Nov 2015 07:08:46 -0800 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-05.mgc.mentorg.com (137.202.0.112) with Microsoft SMTP Server id 14.3.224.2; Tue, 24 Nov 2015 15:08:42 +0000 Subject: [PATCH] Improve verification of loop->latch in verify_loop_structure To: Richard Biener References: <56524E0D.7000203@mentor.com> CC: "gcc-patches@gnu.org" , Jakub Jelinek From: Tom de Vries Message-ID: <56547D49.5040609@mentor.com> Date: Tue, 24 Nov 2015 15:19:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------050502050605000306060800" X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 192.94.38.131 X-SW-Source: 2015-11/txt/msg02920.txt.bz2 --------------050502050605000306060800 Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1016 [ was: Re: [PATCH] Check NULL loop->latch in verify_loop_structure ] On 23/11/15 11:28, Richard Biener wrote: > On Mon, 23 Nov 2015, Tom de Vries wrote: > >> Hi, >> >> In verify_loop_structure, we stop checking the latch once we find that it's >> NULL. >> >> This patch tries a bit harder: >> - if !LOOPS_MAY_HAVE_MULTIPLE_LATCHES, we don't allow a NULL latch >> - if LOOPS_MAY_HAVE_MULTIPLE_LATCHES, we check that indeed there's no >> single loop latch. >> >> As a consequence of adding this check, I needed to fix expand_omp_for_generic, >> which missed an initialization of a loop latch. >> >> Bootstrapped and reg-tested on x86_64. >> >> OK for stage3 trunk? > > You miss to catch the case where loop->latch is non-NULL but there > are multiple latches, so I think the patch can be improved. > That case is more important for correctness (passes > seeing ->latch non-NULL assume a single latch). > Updated according to comment. Bootstrapped and reg-tested on x86_64. OK for stage3 trunk? Thanks, - Tom --------------050502050605000306060800 Content-Type: text/x-patch; name= "0001-Improve-verification-of-loop-latch-in-verify_loop_structure.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename*0="0001-Improve-verification-of-loop-latch-in-verify_loop_struc"; filename*1="ture.patch" Content-length: 3847 Improve verification of loop->latch in verify_loop_structure 2015-11-22 Tom de Vries * cfgloop.c (find_single_latch): New function, factored out of ... (flow_loops_find): ... here. (verify_loop_structure): Improve verification of loop->latch. * cfgloop.h (find_single_latch): Declare. * omp-low.c (expand_omp_for_generic): Initialize latch of orig_loop. --- gcc/cfgloop.c | 70 ++++++++++++++++++++++++++++++++++++++++++----------------- gcc/cfgloop.h | 1 + gcc/omp-low.c | 1 + 3 files changed, 52 insertions(+), 20 deletions(-) diff --git a/gcc/cfgloop.c b/gcc/cfgloop.c index bf00e0e..a6850e3 100644 --- a/gcc/cfgloop.c +++ b/gcc/cfgloop.c @@ -388,6 +388,33 @@ bb_loop_header_p (basic_block header) return false; } +/* Return the latch block for this header block, if it has just a single one. + Otherwise, return NULL. */ + +basic_block +find_single_latch (struct loop* loop) +{ + basic_block header = loop->header; + edge_iterator ei; + edge e; + basic_block latch = NULL; + + FOR_EACH_EDGE (e, ei, header->preds) + { + basic_block cand = e->src; + if (!flow_bb_inside_loop_p (loop, cand)) + continue; + + if (latch != NULL) + /* More than one latch edge. */ + return NULL; + + latch = cand; + } + + return latch; +} + /* Find all the natural loops in the function and save in LOOPS structure and recalculate loop_father information in basic block structures. If LOOPS is non-NULL then the loop structures for already recorded loops @@ -482,29 +509,10 @@ flow_loops_find (struct loops *loops) { struct loop *loop = larray[i]; basic_block header = loop->header; - edge_iterator ei; - edge e; flow_loop_tree_node_add (header->loop_father, loop); loop->num_nodes = flow_loop_nodes_find (loop->header, loop); - - /* Look for the latch for this header block, if it has just a - single one. */ - FOR_EACH_EDGE (e, ei, header->preds) - { - basic_block latch = e->src; - - if (flow_bb_inside_loop_p (loop, latch)) - { - if (loop->latch != NULL) - { - /* More than one latch edge. */ - loop->latch = NULL; - break; - } - loop->latch = latch; - } - } + loop->latch = find_single_latch (loop); } return loops; @@ -1439,6 +1447,28 @@ verify_loop_structure (void) error ("loop %d%'s latch is not dominated by its header", i); err = 1; } + if (find_single_latch (loop) == NULL) + { + error ("loop %d%'s latch is is not the only latch", i); + err = 1; + } + } + else + { + if (loops_state_satisfies_p (LOOPS_MAY_HAVE_MULTIPLE_LATCHES)) + { + if (find_single_latch (loop) != NULL) + { + error ("loop %d%'s latch is missing", i); + err = 1; + } + } + else + { + error ("loop %d%'s latch is missing, and loops may not have" + " multiple latches", i); + err = 1; + } } if (loops_state_satisfies_p (LOOPS_HAVE_SIMPLE_LATCHES)) { diff --git a/gcc/cfgloop.h b/gcc/cfgloop.h index ee73bf9..7faf591 100644 --- a/gcc/cfgloop.h +++ b/gcc/cfgloop.h @@ -270,6 +270,7 @@ bool mark_irreducible_loops (void); void release_recorded_exits (function *); void record_loop_exits (void); void rescan_loop_exit (edge, bool, bool); +basic_block find_single_latch (struct loop*); /* Loop data structure manipulation/querying. */ extern void flow_loop_tree_node_add (struct loop *, struct loop *); diff --git a/gcc/omp-low.c b/gcc/omp-low.c index 0d4c6e5..2d782eb 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -8903,6 +8903,7 @@ expand_omp_for_generic (struct omp_region *region, orig_loop->header = l1_bb; /* The loop may have multiple latches. */ add_loop (orig_loop, new_loop); + orig_loop->latch = find_single_latch (orig_loop); } } } --------------050502050605000306060800--