From patchwork Mon May 9 19:19:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 94919 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 5CFB2B6EE8 for ; Tue, 10 May 2011 09:19:38 +1000 (EST) Received: (qmail 25828 invoked by alias); 9 May 2011 19:19:35 -0000 Received: (qmail 25811 invoked by uid 22791); 9 May 2011 19:19:32 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_TM, 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; Mon, 09 May 2011 19:19:17 +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.14.4/8.14.4) with ESMTP id p49JJGti026645 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 9 May 2011 15:19:17 -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 p49JJGVb026104 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 9 May 2011 15:19:16 -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 p49JJFWn015979; Mon, 9 May 2011 21:19:15 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p49JJFvC015977; Mon, 9 May 2011 21:19:15 +0200 Date: Mon, 9 May 2011 21:19:15 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Cc: Richard Henderson Subject: [PATCH] Fix remove_unreachable_handlers (PR tree-optimization/48794, tree-optimization/48611) Message-ID: <20110509191915.GY17079@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 new testcase shows, while my PR48611 patch stopped the problem from triggering on that testcase, it wasn't a real fix, just (IMHO) right thing to do to get better code. The real problem seems to be that if for whatever reason some optimizations don't happen or don't happen fully (in the testcase because of a series of -fno-* options), we might end up with an EH region where nothing inside of the region might throw, but there are RESX or EH_DISPATCH stmts referencing that region. If the region is removed as unreachable, but the RESX or EH_DISPATCH stays, it references a removed region and it will ICE during inlining or afterwards. The following patch fixes it by just keeping such regions around, I think it shouldn't happen if people don't turn optimizations off or at least shouldn't happen often. Other alternative would be to modify RESX/EH_HANDLER referencing the unreachable regions, the question is what to put there instead or if it can be e.g. removed altogether or replaced with __builtin_trap. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.6? 2011-05-09 Jakub Jelinek PR tree-optimization/48611 PR tree-optimization/48794 * tree-eh.c (remove_unreachable_handlers): Don't remove regions referenced from RESX or EH_DISPATCH arguments. * gfortran.dg/gomp/pr48611.f90: New test. * gfortran.dg/gomp/pr48794.f90: New test. Jakub --- gcc/tree-eh.c.jj 2011-05-02 18:39:28.000000000 +0200 +++ gcc/tree-eh.c 2011-05-09 17:31:12.000000000 +0200 @@ -3317,6 +3317,19 @@ remove_unreachable_handlers (void) SET_BIT (r_reachable, region->index); SET_BIT (lp_reachable, lp_nr); } + + /* Avoid removing regions referenced from RESX/EH_DISPATCH. */ + switch (gimple_code (stmt)) + { + case GIMPLE_RESX: + SET_BIT (r_reachable, gimple_resx_region (stmt)); + break; + case GIMPLE_EH_DISPATCH: + SET_BIT (r_reachable, gimple_eh_dispatch_region (stmt)); + break; + default: + break; + } } } --- gcc/testsuite/gfortran.dg/gomp/pr48611.f90.jj 2011-05-09 17:33:15.000000000 +0200 +++ gcc/testsuite/gfortran.dg/gomp/pr48611.f90 2011-05-09 17:32:10.000000000 +0200 @@ -0,0 +1,12 @@ +! PR tree-optimization/48611 +! { dg-do compile } +! { dg-options "-Os -fopenmp -fexceptions -fno-tree-ccp -fno-tree-copy-prop" } + + integer, allocatable :: a(:) + logical :: l +!$omp parallel private (a) reduction (.or.:l) + do i = 1, 7 + a(:) = i + end do +!$omp end parallel +end --- gcc/testsuite/gfortran.dg/gomp/pr48794.f90.jj 2011-05-09 17:33:19.000000000 +0200 +++ gcc/testsuite/gfortran.dg/gomp/pr48794.f90 2011-05-09 17:33:35.000000000 +0200 @@ -0,0 +1,12 @@ +! PR tree-optimization/48794 +! { dg-do compile } +! { dg-options "-Os -fopenmp -fexceptions -fno-tree-ccp -fno-tree-copy-prop" } + + integer, allocatable :: a(:) + logical :: l + if (allocated (a)) call abort +!$omp parallel private (a) reduction (.or.:l) + do i = 1, 7 + end do +!$omp end parallel +end