This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, cgraph] Fix "mismatched arguments" inlining warning


While working on the dhystone inlining problem, I found that the dump for
ipa-inline was incorrect (along with -Winline).  When inlining is refused due
a type mismatch I got "function not considered for inlining" instead of
"mismatched arguments" as the reason:

Considering f with 0 insns
 to be inlined into main
 Estimated growth after inlined into all callees is -13 insns.
 Estimated badness is -2147483635, frequency 1.00.
 Not inlining into main:function not considered for inlining.
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Apparently there are two places that need updating when you add a new "static"
reason for refusing to inline a function: initialize_inline_failed and
cgraph_create_edge.  The patch that added the check for mismatched arguments
only updated the first.

Furthermore, it seems that the first (initialize_inline_failed) has actually
never has any effect.  The function comment says that it updates inline_failed
on the callee edges from a node but in reality it updates the *caller* edges
going into the node.  The inlining code that puts out the warning is concerned
with the current function and calls leading from there so it never looks at
the information set by initialize_inline_failed (i.e. why current node
wouldn't be inlined into its callers).

So the patch below cleans this up a little bit.  As it turns out
initialize_inline_failed is always called right after we create all callee
edges from a node using cgraph_create_edge.  Thus if we set up the
inline_failed completely in cgraph_create_edge those calls can go.

I'm hoping this would qualify as a regression against 3.4.  The testcase below
inlines fine with 3.4 but now gives the misleading:

  winline-10.c:6: warning: inlining failed in call to 'f': function not considered for inlining

It seems to me that we changed the behavior but fail to give a meaningful
warning.

Bootstrapped and tested on x86_64-linux.

OK to install?

Adam


	* cgraphbuild.c (build_cgraph_edges, rebuild_cgraph_edges): Don't
	call initialize_inline_failed.
	(initialize_inline_failed): Move it from here ...
	* cgraph.c (initialize_inline_failed): ... to here.
	(cgraph_create_edge): Call initialize_inline_failed rather than
	setting inline_failed directly.

testsuite/
	* gcc.dg/winline-10.c: New test.

Index: cgraphbuild.c
===================================================================
--- cgraphbuild.c	(revision 144705)
+++ cgraphbuild.c	(working copy)
@@ -78,31 +78,6 @@ record_reference (tree *tp, int *walk_su
   return NULL_TREE;
 }
 
-/* Give initial reasons why inlining would fail on all calls from
-   NODE.  Those get either nullified or usually overwritten by more precise
-   reason later.  */
-
-static void
-initialize_inline_failed (struct cgraph_node *node)
-{
-  struct cgraph_edge *e;
-
-  for (e = node->callers; e; e = e->next_caller)
-    {
-      gcc_assert (!e->callee->global.inlined_to);
-      gcc_assert (e->inline_failed);
-      if (node->local.redefined_extern_inline)
-	e->inline_failed = N_("redefined extern inline functions are not "
-			   "considered for inlining");
-      else if (!node->local.inlinable)
-	e->inline_failed = N_("function not inlinable");
-      else if (gimple_call_cannot_inline_p (e->call_stmt))
-	e->inline_failed = N_("mismatched arguments");
-      else
-	e->inline_failed = N_("function not considered for inlining");
-    }
-}
-
 /* Computes the frequency of the call statement so that it can be stored in
    cgraph_edge.  BB is the basic block of the call statement.  */
 int
@@ -194,7 +169,6 @@ build_cgraph_edges (void)
     }
 
   pointer_set_destroy (visited_nodes);
-  initialize_inline_failed (node);
   return 0;
 }
 
@@ -254,8 +228,8 @@ rebuild_cgraph_edges (void)
 			      bb->loop_depth);
 
       }
-  initialize_inline_failed (node);
   gcc_assert (!node->global.inlined_to);
+
   return 0;
 }
 
Index: cgraph.c
===================================================================
--- cgraph.c	(revision 144705)
+++ cgraph.c	(working copy)
@@ -655,6 +655,27 @@ cgraph_set_call_stmt (struct cgraph_edge
     }
 }
 
+/* Give initial reasons why inlining would fail on EDGE.  This gets either
+   nullified or usually overwritten by more precise reasons later.  */
+
+static void
+initialize_inline_failed (struct cgraph_edge *e)
+{
+  struct cgraph_node *callee = e->callee;
+
+  if (!callee->analyzed)
+    e->inline_failed = N_("function body not available");
+  else if (callee->local.redefined_extern_inline)
+    e->inline_failed = N_("redefined extern inline functions are not "
+			  "considered for inlining");
+  else if (!callee->local.inlinable)
+    e->inline_failed = N_("function not inlinable");
+  else if (gimple_call_cannot_inline_p (e->call_stmt))
+    e->inline_failed = N_("mismatched arguments");
+  else
+    e->inline_failed = N_("function not considered for inlining");
+}
+
 /* Create edge from CALLER to CALLEE in the cgraph.  */
 
 struct cgraph_edge *
@@ -682,16 +703,6 @@ cgraph_create_edge (struct cgraph_node *
       edge->uid = cgraph_edge_max_uid++;
     }
 
-  if (!callee->analyzed)
-    edge->inline_failed = N_("function body not available");
-  else if (callee->local.redefined_extern_inline)
-    edge->inline_failed = N_("redefined extern inline functions are not "
-			     "considered for inlining");
-  else if (callee->local.inlinable)
-    edge->inline_failed = N_("function not considered for inlining");
-  else
-    edge->inline_failed = N_("function not inlinable");
-
   edge->aux = NULL;
 
   edge->caller = caller;
@@ -725,6 +736,9 @@ cgraph_create_edge (struct cgraph_node *
       gcc_assert (!*slot);
       *slot = edge;
     }
+
+  initialize_inline_failed (edge);
+
   return edge;
 }
 
Index: testsuite/gcc.dg/winline-10.c
===================================================================
--- testsuite/gcc.dg/winline-10.c	(revision 0)
+++ testsuite/gcc.dg/winline-10.c	(revision 0)
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Winline" } */
+
+struct s { int a; };
+
+inline void f (x)	/* { dg-warning "inlining .* mismatched arg" "" } */
+     int x;
+{
+  asm ("");
+}
+
+void g (struct s x)
+{
+  f (x); 		/* { dg-warning "called from here" "" } */
+}
+
+void f (int x);		/* { dg-warning "follows non-prototype definition" } */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]