Use simplify_replace_rtx rather than wrap_constant

Richard Sandiford rdsandiford@googlemail.com
Sun Oct 11 19:36:00 GMT 2009


Bernd Schmidt <bernds_cb1@t-online.de> writes:
> Richard Sandiford wrote:
>> 
>> loop-iv.c:replace_single_def_regs()
>> loop-iv.c:replace_in_expr()
>> loop-iv.c:implies_p()
>> loop-iv.c:simplify_using_condition()
>
> I think all of these are ok right now since we don't put the rtl we
> create back into an insn - all of this code is designed to simplify an
> expression to a constant, and we won't use the result otherwise.

I agree they're probably OK, but it's the probably that worries me.
I think it's dangerous to have shared subrtxes floating around
in this way.  E.g. simplify_using_initial_values can apply a
substitution to one expression while still holding the result
of the same substitution on another expression, so the routines
we call during that period mustn't assume valid sharing of the
"to" value.

It might be better to make the sharing rules apply across the board, not
just to rtxes in the insn stream, since that way we could destructively
modify rtxes more often (and thus create less garbage rtl).  But that's
obviously only for the brave.

> I guess I can live with the change; thanks for posting the cases you
> found.  OK, but please do install this change as a separate commit.

Thanks.  Here's what I installed after bootstrapping and
regression-testing on x86_64-linux-gnu.  I'll revise the main
patch with the change Paolo suggested and repost.

Richard


gcc/
	* simplify-rtx.c (simplify_replace_rtx): Use rtx_equal_p for
	all OLD_RTXes, not just REGs.  Use copy_rtx to create the
	replacement value.

Index: gcc/simplify-rtx.c
===================================================================
--- gcc/simplify-rtx.c	2009-10-11 17:12:45.000000000 +0100
+++ gcc/simplify-rtx.c	2009-10-11 17:13:09.000000000 +0100
@@ -365,8 +365,8 @@ simplify_replace_rtx (rtx x, const_rtx o
      to build a new expression substituting recursively.  If we can't do
      anything, return our input.  */
 
-  if (x == old_rtx)
-    return new_rtx;
+  if (rtx_equal_p (x, old_rtx))
+    return copy_rtx (new_rtx);
 
   switch (GET_RTX_CLASS (code))
     {
@@ -445,11 +445,6 @@ simplify_replace_rtx (rtx x, const_rtx o
 	    return x;
 	  return gen_rtx_LO_SUM (mode, op0, op1);
 	}
-      else if (code == REG)
-	{
-	  if (rtx_equal_p (x, old_rtx))
-	    return new_rtx;
-	}
       break;
 
     default:



More information about the Gcc-patches mailing list