From d239a9ad13a4d8d30658b9dd1e9a135c1a9f3e98 Mon Sep 17 00:00:00 2001
From: kazu <kazu@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 27 Jan 2005 23:00:19 +0000
Subject: [PATCH] 	* cse.c: (find_best_addr): Don't call copy_rtx before
 calling 	fold_rtx.  Save cost recomputation if fold_rtx did nothing. 
 (fold_rtx) <ASM_OPERANDS>: Don't do anything if INSN is 	NULL_RTX.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@94345 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog |  8 ++++++++
 gcc/cse.c     | 36 +++++++++++++++++++++---------------
 2 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 6689e89996e6..0d063b0e3c85 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2005-01-27  Arend Bayer  <arend.bayer@web.de>
+	    Kazu Hirata  <kazu@cs.umass.edu>
+
+	* cse.c: (find_best_addr): Don't call copy_rtx before calling
+	fold_rtx.  Save cost recomputation if fold_rtx did nothing.
+	(fold_rtx) <ASM_OPERANDS>: Don't do anything if INSN is
+	NULL_RTX.
+
 2005-01-27  Jeff Law  <law@redhat.com>
 
 	* tree-into-ssa.c (ssa_rewrite_initialize_block): Do not register
diff --git a/gcc/cse.c b/gcc/cse.c
index febf243f9326..54d184aa2956 100644
--- a/gcc/cse.c
+++ b/gcc/cse.c
@@ -2844,18 +2844,21 @@ find_best_addr (rtx insn, rtx *loc, enum machine_mode mode)
      be valid and produce better code.  */
   if (!REG_P (addr))
     {
-      rtx folded = fold_rtx (copy_rtx (addr), NULL_RTX);
-      int addr_folded_cost = address_cost (folded, mode);
-      int addr_cost = address_cost (addr, mode);
-
-      if ((addr_folded_cost < addr_cost
-	   || (addr_folded_cost == addr_cost
-	       /* ??? The rtx_cost comparison is left over from an older
-		  version of this code.  It is probably no longer helpful.  */
-	       && (rtx_cost (folded, MEM) > rtx_cost (addr, MEM)
-		   || approx_reg_cost (folded) < approx_reg_cost (addr))))
-	  && validate_change (insn, loc, folded, 0))
-	addr = folded;
+      rtx folded = fold_rtx (addr, NULL_RTX);
+      if (folded != addr)
+	{
+	  int addr_folded_cost = address_cost (folded, mode);
+	  int addr_cost = address_cost (addr, mode);
+
+	  if ((addr_folded_cost < addr_cost
+	       || (addr_folded_cost == addr_cost
+		   /* ??? The rtx_cost comparison is left over from an older
+		      version of this code.  It is probably no longer helpful.*/
+		   && (rtx_cost (folded, MEM) > rtx_cost (addr, MEM)
+		       || approx_reg_cost (folded) < approx_reg_cost (addr))))
+	      && validate_change (insn, loc, folded, 0))
+	    addr = folded;
+	}
     }
 
   /* If this address is not in the hash table, we can't look for equivalences
@@ -3608,9 +3611,12 @@ fold_rtx (rtx x, rtx insn)
 #endif
 
     case ASM_OPERANDS:
-      for (i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--)
-	validate_change (insn, &ASM_OPERANDS_INPUT (x, i),
-			 fold_rtx (ASM_OPERANDS_INPUT (x, i), insn), 0);
+      if (insn)
+	{
+	  for (i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--)
+	    validate_change (insn, &ASM_OPERANDS_INPUT (x, i),
+			     fold_rtx (ASM_OPERANDS_INPUT (x, i), insn), 0);
+	}
       break;
 
     default:
-- 
GitLab