From patchwork Fri Jun 15 16:48:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 165199 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 6BF2FB708B for ; Sat, 16 Jun 2012 02:56:17 +1000 (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=1340384178; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Subject:Date:User-Agent:Cc:References: In-Reply-To:MIME-Version:Message-Id:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=SHlJ1atpfXxJsBYybaha727N9M8=; b=BoV+93HsXAlJg+IHKfs2CFl4HQplRImi4UxazsNIkKC1WZ3zYujTNJzE3Nd+hy zjGj7W/WFOGTyfxK73W5t4YkZmJH+il4LG0L3vu9I2Vv0KB18oy6eTMHrKwY7SGA +uRzNeUryorngULYWFRI21HNgQFdL53l5n/HEBsehJoKw= 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:Received:From:To:Subject:Date:User-Agent:Cc:References:In-Reply-To:MIME-Version:Message-Id:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=qwSXNsQ8a3z4ahtZzyHiwc3gyw5X8WyBiyy0uBfmgh7wlAwTtdauJMmtXPlN/m eC96EXaY7lWKXTu4BqQ/Q65LHEDN8D/LTLXSszzFsh/S59t2LGC6Xmv/fM4jRQMl 2opbmqXSS8u4EwFEDn3b0uEBgFGr0IT2ezsVFdUrhsoeI=; Received: (qmail 7969 invoked by alias); 15 Jun 2012 16:56:14 -0000 Received: (qmail 7960 invoked by uid 22791); 15 Jun 2012 16:56:13 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=AWL, BAYES_00, KHOP_THREADED X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 15 Jun 2012 16:56:00 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 886172900B2; Fri, 15 Jun 2012 18:56:05 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pPhcrbFOuTqg; Fri, 15 Jun 2012 18:56:05 +0200 (CEST) Received: from [192.168.1.2] (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id 4856E2900AE; Fri, 15 Jun 2012 18:56:05 +0200 (CEST) From: Eric Botcazou To: Richard Guenther Subject: Re: [patch] Fix PR middle-end/53590 Date: Fri, 15 Jun 2012 18:48:13 +0200 User-Agent: KMail/1.9.9 Cc: gcc-patches@gcc.gnu.org References: <201206131206.04396.ebotcazou@adacore.com> <201206151113.56685.ebotcazou@adacore.com> In-Reply-To: MIME-Version: 1.0 Message-Id: <201206151848.13986.ebotcazou@adacore.com> 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 > Btw, I think we should enable this flag by default for all languages but > Java so that if you enable -fnon-call-exceptions for C or C++ you don't get > too many spurious exceptions from dead code. The attached patch enables it for the C family of languages (I'm not too sure about the other languages). It also adds the missing bits related to inlining (with the annoying FIXME for LTO in can_inline_edge_p). Bootstrapped/regtested on x86_64-suse-linux, OK for mainline? 2012-06-15 Eric Botcazou PR middle-end/53590 * doc/invoke.texi (-fdelete-dead-exceptions): Update. * cif-code.def (DEAD_EXCEPTIONS): New code. * ipa-inline.c (can_inline_edge_p): Return false if the caller can delete dead exceptions but the callee cannot. * tree-inline.c (initialize_cfun): Copy can_delete_dead_exceptions. c-family/ * c-opts.c (c_common_init_options_struct): Set opts->x_flag_delete_dead_exceptions to 1. Index: doc/invoke.texi =================================================================== --- doc/invoke.texi (revision 188667) +++ doc/invoke.texi (working copy) @@ -19322,7 +19322,9 @@ arbitrary signal handlers such as @code{ Consider that instructions that may throw exceptions but don't otherwise contribute to the execution of the program can be optimized away. This option is enabled by default for the Ada front end, as permitted by -the Ada language specification. +the Ada language specification. It is also enabled for the front ends of +the C family of languages, as it applies only to non-call exceptions and +those are not part of the the language specifications. Optimization passes that cause dead exceptions to be removed are enabled independently at different optimization levels. @item -funwind-tables Index: c-family/c-opts.c =================================================================== --- c-family/c-opts.c (revision 188445) +++ c-family/c-opts.c (working copy) @@ -204,6 +204,11 @@ c_common_init_options_struct (struct gcc /* By default, C99-like requirements for complex multiply and divide. */ opts->x_flag_complex_method = 2; + + /* We can delete dead instructions that may throw exceptions because, in + practice, this occurs only for non-call exceptions and those are not + part of the the language specifications. */ + opts->x_flag_delete_dead_exceptions = 1; } /* Common initialization before calling option handlers. */ Index: cif-code.def =================================================================== --- cif-code.def (revision 188445) +++ cif-code.def (working copy) @@ -96,7 +96,11 @@ DEFCIFCODE(EH_PERSONALITY, N_("exception /* We can't inline if the callee can throw non-call exceptions but the caller cannot. */ -DEFCIFCODE(NON_CALL_EXCEPTIONS, N_("non-call exception handling mismatch")) +DEFCIFCODE(NON_CALL_EXCEPTIONS, N_("non-call exceptions handling mismatch")) + +/* We can't inline if the caller can delete dead exceptions but the + callee cannot. */ +DEFCIFCODE(DEAD_EXCEPTIONS, N_("dead exceptions handling mismatch")) /* We can't inline because of mismatched target specific options. */ DEFCIFCODE(TARGET_OPTION_MISMATCH, N_("target specific option mismatch")) Index: ipa-inline.c =================================================================== --- ipa-inline.c (revision 188667) +++ ipa-inline.c (working copy) @@ -302,6 +302,16 @@ can_inline_edge_p (struct cgraph_edge *e e->inline_failed = CIF_NON_CALL_EXCEPTIONS; inlinable = false; } + /* Don't inline if the caller can delete dead exceptions but the + callee cannot. + FIXME: this is obviously wrong for LTO where STRUCT_FUNCTION is missing. + Move the flag into cgraph node or mirror it in the inline summary. */ + else if (caller_cfun && caller_cfun->can_delete_dead_exceptions + && !(callee_cfun && callee_cfun->can_delete_dead_exceptions)) + { + e->inline_failed = CIF_DEAD_EXCEPTIONS; + inlinable = false; + } /* Check compatibility of target optimization options. */ else if (!targetm.target_option.can_inline_p (e->caller->symbol.decl, callee->symbol.decl)) Index: tree-inline.c =================================================================== --- tree-inline.c (revision 188668) +++ tree-inline.c (working copy) @@ -2107,6 +2107,7 @@ initialize_cfun (tree new_fndecl, tree c cfun->after_inlining = src_cfun->after_inlining; cfun->can_throw_non_call_exceptions = src_cfun->can_throw_non_call_exceptions; + cfun->can_delete_dead_exceptions = src_cfun->can_delete_dead_exceptions; cfun->returns_struct = src_cfun->returns_struct; cfun->returns_pcc_struct = src_cfun->returns_pcc_struct; cfun->after_tree_profile = src_cfun->after_tree_profile;