diff mbox

Teach CCP to do devirtualization

Message ID 20100928164913.GB22494@kam.mff.cuni.cz
State New
Headers show

Commit Message

Jan Hubicka Sept. 28, 2010, 4:49 p.m. UTC
Hi,
with recent folding improvements, we now work hard enough to make statement fold to look
into the virtual tables and work out function to be called.  Still we don't devirtualize
the call because we never actually substitute the operand of OBJ_TYPE_REF because there is
a NOP_EXPR in a way.

This patch makes ccp_fold_stmt to do the replacement.  I am not 100% sure if we
should not do some type checking and mark call statement uninlinable on
mismatch, but in general C++ should not let us to make mismatches.

I've bootstrapped/regtested the patch on x86_64 and tested on Mozilla.  There it devirutalize
about 900 calls during late ccp and also couple hundred calls before inlining.  I am not
attaching a testcase, since I inspected some and think they should be handled by the type
based mahcinery too, but they are not, so I filled in PR for that.  Once this is settled we
can decide what has to be handled the busy way.

OK?

	* tree-ssa-ccp.c (ccp_fold_stmt): Fold OBJ_TYPE_REF away
	when destination is known.

Comments

Richard Biener Sept. 29, 2010, 8:47 a.m. UTC | #1
On Tue, 28 Sep 2010, Jan Hubicka wrote:

> Hi,
> with recent folding improvements, we now work hard enough to make statement fold to look
> into the virtual tables and work out function to be called.  Still we don't devirtualize
> the call because we never actually substitute the operand of OBJ_TYPE_REF because there is
> a NOP_EXPR in a way.
> 
> This patch makes ccp_fold_stmt to do the replacement.  I am not 100% sure if we
> should not do some type checking and mark call statement uninlinable on
> mismatch, but in general C++ should not let us to make mismatches.
> 
> I've bootstrapped/regtested the patch on x86_64 and tested on Mozilla.  There it devirutalize
> about 900 calls during late ccp and also couple hundred calls before inlining.  I am not
> attaching a testcase, since I inspected some and think they should be handled by the type
> based mahcinery too, but they are not, so I filled in PR for that.  Once this is settled we
> can decide what has to be handled the busy way.
> 
> OK?
> 
> 	* tree-ssa-ccp.c (ccp_fold_stmt): Fold OBJ_TYPE_REF away
> 	when destination is known.
> 
> Index: tree-ssa-ccp.c
> ===================================================================
> --- tree-ssa-ccp.c	(revision 164689)
> +++ tree-ssa-ccp.c	(working copy)
> @@ -2307,6 +2307,17 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi
>  		changed = true;
>  	      }
>  	  }
> +	if (TREE_CODE (gimple_call_fn (stmt)) == OBJ_TYPE_REF)
> +	  {
> +	    tree expr = OBJ_TYPE_REF_EXPR (gimple_call_fn (stmt));
> +	    expr = valueize_op (expr);
> +	    if (TREE_CODE (expr) == ADDR_EXPR
> +	        && TREE_CODE (TREE_OPERAND (expr, 0)) == FUNCTION_DECL)
> +	     {
> +	       gimple_call_set_fndecl (stmt, TREE_OPERAND (expr, 0));

Ok with using gimple_call_set_fn (stmt, expr) here (which avoids
re-building the addr-expr).

Thanks,
Richard.
diff mbox

Patch

Index: tree-ssa-ccp.c
===================================================================
--- tree-ssa-ccp.c	(revision 164689)
+++ tree-ssa-ccp.c	(working copy)
@@ -2307,6 +2307,17 @@  ccp_fold_stmt (gimple_stmt_iterator *gsi
 		changed = true;
 	      }
 	  }
+	if (TREE_CODE (gimple_call_fn (stmt)) == OBJ_TYPE_REF)
+	  {
+	    tree expr = OBJ_TYPE_REF_EXPR (gimple_call_fn (stmt));
+	    expr = valueize_op (expr);
+	    if (TREE_CODE (expr) == ADDR_EXPR
+	        && TREE_CODE (TREE_OPERAND (expr, 0)) == FUNCTION_DECL)
+	     {
+	       gimple_call_set_fndecl (stmt, TREE_OPERAND (expr, 0));
+	       changed = true;
+	     }
+	  }
 
 	return changed;
       }