Patchwork Fix ICE in expand_cse_reciprocals (PR tree-optimization/42078)

login
register
mail settings
Submitter Alexandre Oliva
Date June 3, 2011, 2:28 p.m.
Message ID <or39jrm1ju.fsf@livre.localdomain>
Download mbox | patch
Permalink /patch/98588/
State New
Headers show

Comments

Alexandre Oliva - June 3, 2011, 2:28 p.m.
According to http://gcc.gnu.org/ml/gcc-patches/2009-11/msg01082.html
on Nov 20, 2009, Alexandre Oliva <aoliva@redhat.com> wrote:

> On Nov 19, 2009, Richard Guenther <richard.guenther@gmail.com> wrote:
>> In fact this exchanging of the LHS (or rather invalidating of the
>> SSA name value) should be a helper function that knows
>> the implementation details and avoids going through releasing
>> and allocating the name.

> Okie dokie, here's a sequence of patches that implements helper
> functions for this sort of stuff.

> The first patch introduces machinery to propagate “dying” DEFs into
> debug stmts, while replacing them with other SSA_NAMEs.

This is already in.

> The second extends it so as to enable the old LHS to be redefined
> e.g. in terms of the new LHS.  IIRC this may be useful in some other
> transformations that, in the process of introducing VTA, I changed from
> modifying stmts in place to inserting new stmts and removing others.  I
> haven't looked for them yet.

> The third uses this new feature for the case at hand, while avoiding
> computing the reciprocal expression if we know it won't be used.

Updated versions of these follow.  Regstrapped on x86_64-linux-gnu and
i686-linux-gnu.  Ok to install?

Patch

for  gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR tree-optimization/42078
	* tree-ssa-math-opts.c (execute_cse_reciprocals): Compute reciprocal
	value for debug stmts.  

Index: gcc/tree-ssa-math-opts.c
===================================================================
--- gcc/tree-ssa-math-opts.c.orig	2011-06-03 01:29:09.427075107 -0300
+++ gcc/tree-ssa-math-opts.c	2011-06-03 01:30:25.688009048 -0300
@@ -574,6 +574,7 @@  execute_cse_reciprocals (void)
 		  bool md_code, fail;
 		  imm_use_iterator ui;
 		  use_operand_p use_p;
+		  tree value;
 
 		  code = DECL_FUNCTION_CODE (fndecl);
 		  md_code = DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD;
@@ -603,13 +604,24 @@  execute_cse_reciprocals (void)
 		  if (fail)
 		    continue;
 
-		  gimple_replace_lhs (stmt1, arg1, NULL);
+		  if (gimple_replace_lhs_wants_value ())
+		    {
+		      tree t = TREE_TYPE (arg1);
+
+		      value = build2 (RDIV_EXPR, t, build_one_cst (t), arg1);
+		    }
+		  else
+		    value = NULL;
+
+		  gimple_replace_lhs (stmt1, arg1, value);
 		  gimple_call_set_fndecl (stmt1, fndecl);
 		  update_stmt (stmt1);
 		  reciprocal_stats.rfuncs_inserted++;
 
 		  FOR_EACH_IMM_USE_STMT (stmt, ui, arg1)
 		    {
+		      if (is_gimple_debug (stmt))
+			continue;
 		      gimple_assign_set_rhs_code (stmt, MULT_EXPR);
 		      fold_stmt_inplace (stmt);
 		      update_stmt (stmt);