[PATCH] Fix devirtualization ICE (PR tree-optimization/59622, take 3)

Richard Biener rguenther@suse.de
Wed Jan 8 10:46:00 GMT 2014


On Tue, 7 Jan 2014, Jakub Jelinek wrote:

> Hi!
> 
> On Fri, Jan 03, 2014 at 11:33:50AM +0100, Jakub Jelinek wrote:
> > On Fri, Jan 03, 2014 at 11:24:53AM +0100, Richard Biener wrote:
> 
> Anyway, back to the original patch, so do you prefer something like
> this instead?  I.e. handle only __builtin_unreachable and
> __cxa_pure_virtual specially, and not devirt for fold_stmt_inplace?
> 
> 2014-01-07  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/59622
> 	* gimple-fold.c (gimple_fold_call): Fix a typo in message.  Handle
> 	__cxa_pure_virtual similarly to __builtin_unreachable.  Don't
> 	devirtualize for inplace at all.
> 
> 	* g++.dg/opt/pr59622-2.C: New test.
> 
> --- gcc/gimple-fold.c.jj	2014-01-03 11:40:57.247320424 +0100
> +++ gcc/gimple-fold.c	2014-01-07 18:15:00.352601812 +0100
> @@ -1167,7 +1167,7 @@ gimple_fold_call (gimple_stmt_iterator *
>                                                   (OBJ_TYPE_REF_EXPR (callee)))))
>  	    {
>  	      fprintf (dump_file,
> -		       "Type inheritnace inconsistent devirtualization of ");
> +		       "Type inheritance inconsistent devirtualization of ");
>  	      print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
>  	      fprintf (dump_file, " to ");
>  	      print_generic_expr (dump_file, callee, TDF_SLIM);
> @@ -1177,26 +1177,35 @@ gimple_fold_call (gimple_stmt_iterator *
>  	  gimple_call_set_fn (stmt, OBJ_TYPE_REF_EXPR (callee));
>  	  changed = true;
>  	}
> -      else if (flag_devirtualize && virtual_method_call_p (callee))
> +      else if (flag_devirtualize && !inplace && virtual_method_call_p (callee))
>  	{
>  	  bool final;
>  	  vec <cgraph_node *>targets
>  	    = possible_polymorphic_call_targets (callee, &final);
>  	  if (final && targets.length () <= 1)
>  	    {
> +	      tree fndecl;
>  	      if (targets.length () == 1)
> +		fndecl = targets[0]->decl;
> +	      else
> +		fndecl = builtin_decl_implicit (BUILT_IN_UNREACHABLE);
> +
> +	      /* If fndecl (like __builtin_unreachable or
> +		 __cxa_pure_virtual) takes no arguments, doesn't have
> +		 return value and is noreturn, just add the call before
> +		 stmt and DCE will do it's job later on.  */
> +	      if (TREE_THIS_VOLATILE (fndecl)
> +		  && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fndecl)))
> +		  && TYPE_ARG_TYPES (TREE_TYPE (fndecl)) == void_list_node)
>  		{
> -		  gimple_call_set_fndecl (stmt, targets[0]->decl);
> -		  changed = true;
> -		}
> -	      else if (!inplace)
> -		{
> -		  tree fndecl = builtin_decl_implicit (BUILT_IN_UNREACHABLE);
>  		  gimple new_stmt = gimple_build_call (fndecl, 0);
>  		  gimple_set_location (new_stmt, gimple_location (stmt));
>  		  gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
>  		  return true;
>  		}
> +
> +	      gimple_call_set_fndecl (stmt, fndecl);

I prefer to always do this, not do the fancy insertion-before.  That
would do repeated folding for

   fold_stmt (gsi);
   fold_stmt (gsi);
   fold_stmt (gsi);

where the last two should be a no-op.

Richard.


> +	      changed = true;
>  	    }
>  	}
>      }
> --- gcc/testsuite/g++.dg/opt/pr59622-2.C.jj	2014-01-07 18:10:45.435904909 +0100
> +++ gcc/testsuite/g++.dg/opt/pr59622-2.C	2014-01-07 18:10:45.435904909 +0100
> @@ -0,0 +1,21 @@
> +// PR tree-optimization/59622
> +// { dg-do compile }
> +// { dg-options "-O2" }
> +
> +namespace
> +{
> +  struct A
> +  {
> +    A () {}
> +    virtual A *bar (int) = 0;
> +    A *baz (int x) { return bar (x); }
> +  };
> +}
> +
> +A *a;
> +
> +void
> +foo ()
> +{
> +  a->baz (0);
> +}
> 
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
GF: Jeff Hawn, Jennifer Guild, Felix Imend"orffer



More information about the Gcc-patches mailing list