From patchwork Tue Mar 19 11:56:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 229042 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 58EA02C00A4 for ; Tue, 19 Mar 2013 23:37:42 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= dkim1; b=nbw5aGc+0huiwnZSjIAqDSWknGH9pxyBFEIWsugAJtSRKiQa93i6hBd SCYTNFR4+FCHwLvcbKrk/skZ8YvlZqmiv5XDOdjt+k6ooOYJYjVvyfLYtx0wEp71 y8soy+A5PMhaGwQshpJqiBoGhlNK2Ja9nMT8x8YqV6AUgm2a6mZE= DKIM-Signature: v=1; a=rsa-sha1; c=simple; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s=dkim1; bh=azEhjEL53/hM3+hN2IX8gng/ciw=; b=kyoEcnzSGLFkGmDWcTt0TcbbLq6/ GqEHYdhbh7YtYxkm8/XGuJtLrq9GyvBsVKhO93/NM51m+VE03/D8sfQeOlkXk/2g i97wDMFi6eVZixRe2qg6k26EqZ+WZauUkLsaFgstOg83Vf6G9erebXf9kbhqQDoC h0tgkfBRj8S9UI8= Received: (qmail 30134 invoked by alias); 19 Mar 2013 12:09:12 -0000 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 Received: (qmail 27661 invoked by uid 89); 19 Mar 2013 11:56:50 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 19 Mar 2013 11:56:49 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E8EC7A4F28 for ; Tue, 19 Mar 2013 12:56:47 +0100 (CET) Date: Tue, 19 Mar 2013 12:56:47 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Streamline loop verifier, make it less prone to ICE Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 The following fixes the most annoying ICE during loop verification (get_loop_body ICEing) and re-structures things a bit. It also fixes an ICE that occurs when trying to graph a corrupt loop tree (I'm using that heavily, and ICEing within the graphing is annoying - this doesn't fix the corresponding get_loop_body ICE there) Bootstrapped and tested on x86_64-unknown-linux-gnu. Richard. 2013-03-19 Richard Biener * cfgloop.c (verify_loop_structure): Streamline and avoid ICEing on corrupt loop tree. * graph.c (draw_cfg_nodes_for_loop): Avoid ICEing on corrupt loop tree. Index: gcc/cfgloop.c =================================================================== --- gcc/cfgloop.c (revision 196784) +++ gcc/cfgloop.c (working copy) @@ -1319,7 +1319,7 @@ verify_loop_structure (void) { unsigned *sizes, i, j; sbitmap irreds; - basic_block bb; + basic_block bb, *bbs; struct loop *loop; int err = 0; edge e; @@ -1335,43 +1335,51 @@ verify_loop_structure (void) else verify_dominators (CDI_DOMINATORS); - /* Check sizes. */ - sizes = XCNEWVEC (unsigned, num); - sizes[0] = 2; - - FOR_EACH_BB (bb) - for (loop = bb->loop_father; loop; loop = loop_outer (loop)) - sizes[loop->num]++; - - FOR_EACH_LOOP (li, loop, LI_INCLUDE_ROOT) - { - i = loop->num; - - if (loop->num_nodes != sizes[i]) - { - error ("size of loop %d should be %d, not %d", - i, sizes[i], loop->num_nodes); - err = 1; - } - } - /* Check the headers. */ FOR_EACH_BB (bb) - if (bb_loop_header_p (bb) - && bb->loop_father->header != bb) + if (bb_loop_header_p (bb)) + { + if (bb->loop_father->header == NULL) + { + error ("loop with header %d marked for removal", bb->index); + err = 1; + } + else if (bb->loop_father->header != bb) + { + error ("loop with header %d not in loop tree", bb->index); + err = 1; + } + } + else if (bb->loop_father->header == bb) { - error ("loop with header %d not in loop tree", bb->index); + error ("non-loop with header %d not marked for removal", bb->index); err = 1; } - /* Check get_loop_body. */ + /* Check the recorded loop father and sizes of loops. */ visited = sbitmap_alloc (last_basic_block); bitmap_clear (visited); + bbs = XNEWVEC (basic_block, n_basic_blocks); FOR_EACH_LOOP (li, loop, LI_FROM_INNERMOST) { - basic_block *bbs = get_loop_body (loop); + unsigned n; - for (j = 0; j < loop->num_nodes; j++) + if (loop->header == NULL) + { + error ("removed loop %d in loop tree", loop->num); + err = 1; + continue; + } + + n = get_loop_body_with_size (loop, bbs, n_basic_blocks); + if (loop->num_nodes != n) + { + error ("size of loop %d should be %d, not %d", + loop->num, n, loop->num_nodes); + err = 1; + } + + for (j = 0; j < n; j++) { bb = bbs[j]; @@ -1394,16 +1402,16 @@ verify_loop_structure (void) err = 1; } } - - free (bbs); } + free (bbs); sbitmap_free (visited); /* Check headers and latches. */ FOR_EACH_LOOP (li, loop, 0) { i = loop->num; - + if (loop->header == NULL) + continue; if (!bb_loop_header_p (loop->header)) { error ("loop %d%'s header is not a loop header", i); @@ -1561,6 +1569,7 @@ verify_loop_structure (void) { unsigned n_exits = 0, eloops; + sizes = XCNEWVEC (unsigned, num); memset (sizes, 0, sizeof (unsigned) * num); FOR_EACH_BB (bb) { @@ -1624,11 +1633,12 @@ verify_loop_structure (void) err = 1; } } + + free (sizes); } gcc_assert (!err); - free (sizes); if (!dom_available) free_dominance_info (CDI_DOMINATORS); } Index: gcc/graph.c =================================================================== --- gcc/graph.c (revision 196784) +++ gcc/graph.c (working copy) @@ -213,7 +213,8 @@ draw_cfg_nodes_for_loop (pretty_printer unsigned int i; const char *fillcolors[3] = { "grey88", "grey77", "grey66" }; - if (loop->latch != EXIT_BLOCK_PTR) + if (loop->header != NULL + && loop->latch != EXIT_BLOCK_PTR) pp_printf (pp, "\tsubgraph cluster_%d_%d {\n" "\tstyle=\"filled\";\n" @@ -229,6 +230,9 @@ draw_cfg_nodes_for_loop (pretty_printer for (struct loop *inner = loop->inner; inner; inner = inner->next) draw_cfg_nodes_for_loop (pp, funcdef_no, inner); + if (loop->header == NULL) + return; + if (loop->latch == EXIT_BLOCK_PTR) body = get_loop_body (loop); else