From patchwork Tue Nov 2 23:40:55 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 69935 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 49A90B6EE8 for ; Wed, 3 Nov 2010 10:41:16 +1100 (EST) Received: (qmail 2550 invoked by alias); 2 Nov 2010 23:41:08 -0000 Received: (qmail 2540 invoked by uid 22791); 2 Nov 2010 23:41:06 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD 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, 02 Nov 2010 23:40:59 +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.13.8/8.13.8) with ESMTP id oA2NevbQ031554 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 2 Nov 2010 19:40:57 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oA2NeuMv007408 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 2 Nov 2010 19:40:57 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id oA2NeuIQ026162; Wed, 3 Nov 2010 00:40:56 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id oA2NetEb026115; Wed, 3 Nov 2010 00:40:55 +0100 Date: Wed, 3 Nov 2010 00:40:55 +0100 From: Jakub Jelinek To: Zdenek Dvorak Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix loop unswitching with irreducible loop edges (PR tree-optimization/46107) Message-ID: <20101102234055.GM29412@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! As the testcase shows, if loop unswitching calls loop_version, it temporarily removes EDGE_IRREDUCIBLE_LOOP bit from entry->flags. If cfg_hook_duplicate_loop_to_header_edge fails, nothing restores it back and thus we ICE in verify_loop_structure (). Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2010-11-02 Jakub Jelinek PR tree-optimization/46107 * cfgloopmanip.c (loop_version): Set irred_flag back into entry->flags if cfg_hook_duplicate_loop_to_header_edge failed. * gcc.c-torture/compile/pr46107.c: New test. Jakub --- gcc/cfgloopmanip.c.jj 2010-08-20 16:05:40.000000000 +0200 +++ gcc/cfgloopmanip.c 2010-11-02 20:03:11.000000000 +0100 @@ -1,6 +1,6 @@ /* Loop manipulation code for GNU compiler. - Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009 Free Software - Foundation, Inc. + Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010 + Free Software Foundation, Inc. This file is part of GCC. @@ -1538,7 +1538,10 @@ loop_version (struct loop *loop, /* Duplicate loop. */ if (!cfg_hook_duplicate_loop_to_header_edge (loop, entry, 1, NULL, NULL, NULL, 0)) - return NULL; + { + entry->flags |= irred_flag; + return NULL; + } /* After duplication entry edge now points to new loop head block. Note down new head as second_head. */ --- gcc/testsuite/gcc.c-torture/compile/pr46107.c.jj 2010-11-02 20:11:54.000000000 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr46107.c 2010-11-02 20:11:35.000000000 +0100 @@ -0,0 +1,16 @@ +/* PR tree-optimization/46107 */ + +int foo (void) __attribute__ ((noreturn)); + +void +bar (int x, int *y, int z) +{ + static void *j[] = { &&l1, &&l2 }; +l1: + if (*y) + goto *j[z]; + foo (); +l2: + *y ^= (x & 1) ? -1 : 0; + goto *j[x]; +}