diff mbox

Fix PR middle-end/53590

Message ID 201206151848.13986.ebotcazou@adacore.com
State New
Headers show

Commit Message

Eric Botcazou June 15, 2012, 4:48 p.m. UTC
> 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  <ebotcazou@adacore.com>

        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.

Comments

Richard Biener June 17, 2012, 11:40 a.m. UTC | #1
On Fri, Jun 15, 2012 at 6:48 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
>> 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?

Ok.

Thanks,
Richard.

>
> 2012-06-15  Eric Botcazou  <ebotcazou@adacore.com>
>
>        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.
>
>
> --
> Eric Botcazou
diff mbox

Patch

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;