Fix ICE in ipa-cp when mixing -O0 and -O2 code in LTO
diff mbox series

Message ID 20191112193640.gnm4u6aek6gy75tz@kam.mff.cuni.cz
State New
Headers show
Series
  • Fix ICE in ipa-cp when mixing -O0 and -O2 code in LTO
Related show

Commit Message

Jan Hubicka Nov. 12, 2019, 7:36 p.m. UTC
Hi,
this fixes second ICE seen during profiledbootstrap with Ada enabled.
The problem is that Ada builds some object files with -O2 -O0 (not sure
why) and these functions get flag_ipa_cp but !optimize.   Because of -O0
ipa-cp pass is not run at compile time and summaries are never produced.
So In addition to !flag_ipa_cp functions we also need to punt on
!optimize.  This is something we may want to clean up next stage1.

Bootstrapped/regtesetd x86_64-linux, comited

	* ipa-cp.c (ignore_edge_p): Also look for optimize flag.
	(ipcp_verify_propagated_values): Likewise.
	(propagate_constants_across_call): Likewise.
	(propagate_constants_topo): Likewise.
	(ipcp_propagate_stage): Likewise.

Comments

Eric Botcazou Nov. 12, 2019, 8:29 p.m. UTC | #1
> this fixes second ICE seen during profiledbootstrap with Ada enabled.
> The problem is that Ada builds some object files with -O2 -O0 (not sure
> why) and these functions get flag_ipa_cp but !optimize.   

# Compile s-excdeb.o without optimization and with debug info to let the
# debugger set breakpoints and inspect subprogram parameters on exception
# related events.

We could probably try wih -Og these days.
Jan Hubicka Nov. 12, 2019, 10:51 p.m. UTC | #2
> > this fixes second ICE seen during profiledbootstrap with Ada enabled.
> > The problem is that Ada builds some object files with -O2 -O0 (not sure
> > why) and these functions get flag_ipa_cp but !optimize.   
> 
> # Compile s-excdeb.o without optimization and with debug info to let the
> # debugger set breakpoints and inspect subprogram parameters on exception
> # related events.
> 
> We could probably try wih -Og these days.

That sounds like a good idea to me :)

Using -O0 and -fprofile-generate triggers yet another problem.  The
module gets a constructor function registering the profile info and
TARGET_OPTIMIZATION_NODE is not set for it (because it is built after
free lang data). This eventually makes ipa-cp to think that the function
is compiled with -O2 (because WPA is invoked with -O2) and ICE again.

I am testing the following:

Index: ipa.c
===================================================================
--- ipa.c	(revision 278094)
+++ ipa.c	(working copy)
@@ -914,7 +914,10 @@ cgraph_build_static_cdtor_1 (char which,
 void
 cgraph_build_static_cdtor (char which, tree body, int priority)
 {
-  cgraph_build_static_cdtor_1 (which, body, priority, false, NULL, NULL);
+  gcc_assert (!in_lto_p);
+  cgraph_build_static_cdtor_1 (which, body, priority, false,
+			       optimization_default_node,
+			       target_option_default_node);
 }
 
 /* When target does not have ctors and dtors, we call all constructor

Patch
diff mbox series

Index: ipa-cp.c
===================================================================
--- ipa-cp.c	(revision 278094)
+++ ipa-cp.c	(working copy)
@@ -816,6 +816,8 @@  ignore_edge_p (cgraph_edge *e)
     = e->callee->function_or_virtual_thunk_symbol (&avail, e->caller);
 
   return (avail <= AVAIL_INTERPOSABLE
+	  || !opt_for_fn (e->caller->decl, optimize)
+	  || !opt_for_fn (ultimate_target->decl, optimize)
 	  || !opt_for_fn (e->caller->decl, flag_ipa_cp)
 	  || !opt_for_fn (ultimate_target->decl, flag_ipa_cp));
 }
@@ -1471,7 +1473,8 @@  ipcp_verify_propagated_values (void)
   FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
     {
       class ipa_node_params *info = IPA_NODE_REF (node);
-      if (!opt_for_fn (node->decl, flag_ipa_cp))
+      if (!opt_for_fn (node->decl, flag_ipa_cp)
+	  || !opt_for_fn (node->decl, optimize))
 	continue;
       int i, count = ipa_get_param_count (info);
 
@@ -2316,7 +2319,9 @@  propagate_constants_across_call (struct
   parms_count = ipa_get_param_count (callee_info);
   if (parms_count == 0)
     return false;
-  if (!args)
+  if (!args
+      || !opt_for_fn (cs->caller->decl, flag_ipa_cp)
+      || !opt_for_fn (cs->caller->decl, optimize))
     {
       for (i = 0; i < parms_count; i++)
 	ret |= set_all_contains_variable (ipa_get_parm_lattices (callee_info,
@@ -3238,7 +3243,8 @@  propagate_constants_topo (class ipa_topo
       FOR_EACH_VEC_ELT (cycle_nodes, j, v)
 	if (v->has_gimple_body_p ())
 	  {
-	    if (opt_for_fn (v->decl, flag_ipa_cp))
+	    if (opt_for_fn (v->decl, flag_ipa_cp)
+		&& opt_for_fn (v->decl, optimize))
 	      push_node_to_stack (topo, v);
 	    /* When V is not optimized, we can not push it to stac, but
 	       still we need to set all its callees lattices to bottom.  */
@@ -3269,7 +3275,8 @@  propagate_constants_topo (class ipa_topo
 	 their topological sort.  */
       FOR_EACH_VEC_ELT (cycle_nodes, j, v)
 	if (v->has_gimple_body_p ()
-	    && opt_for_fn (v->decl, flag_ipa_cp))
+	    && opt_for_fn (v->decl, flag_ipa_cp)
+	    && opt_for_fn (v->decl, optimize))
 	  {
 	    struct cgraph_edge *cs;
 
@@ -3348,7 +3355,9 @@  ipcp_propagate_stage (class ipa_topo_inf
 
   FOR_EACH_DEFINED_FUNCTION (node)
   {
-    if (node->has_gimple_body_p () && opt_for_fn (node->decl, flag_ipa_cp))
+    if (node->has_gimple_body_p ()
+	&& opt_for_fn (node->decl, flag_ipa_cp)
+	&& opt_for_fn (node->decl, optimize))
       {
         class ipa_node_params *info = IPA_NODE_REF (node);
         determine_versionability (node, info);