public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Teach CCP to do devirtualization
@ 2010-09-28 20:01 Jan Hubicka
  2010-09-29 16:56 ` Richard Guenther
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Hubicka @ 2010-09-28 20:01 UTC (permalink / raw)
  To: gcc-patches, rguenther

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));
+	       changed = true;
+	     }
+	  }
 
 	return changed;
       }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Teach CCP to do devirtualization
  2010-09-28 20:01 Teach CCP to do devirtualization Jan Hubicka
@ 2010-09-29 16:56 ` Richard Guenther
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Guenther @ 2010-09-29 16:56 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: gcc-patches

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-09-29  8:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-28 20:01 Teach CCP to do devirtualization Jan Hubicka
2010-09-29 16:56 ` Richard Guenther

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).