From 5dc2e33320cada5471dfa0fa219c302d367b75c1 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Fri, 30 Sep 2005 14:33:53 +0000
Subject: [PATCH] re PR tree-optimization/21430 (Quadratic behavior with
 constant initializers)

2005-09-30  Andrew Macleod  <amacleod@redat.com>

	PR tree-optimization/21430
	* tree-ssa-operands.c (set_virtual_use_link): New. Link new virtual
	use operands, and set stmt pointer if need be.
	(FINALIZE_CORRECT_USE: New. Macro to call appropriate use fixup routine.
	tree-ssa-opfinalize.h (FINALIZE_FUNC): Call FINALIZE_CORRECT_USE if
	present.

From-SVN: r104816
---
 gcc/ChangeLog             |  9 +++++++++
 gcc/tree-ssa-operands.c   | 22 ++++++++++++++++++++++
 gcc/tree-ssa-opfinalize.h |  5 +++--
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 636014b040ed..6ff4c0fdbf97 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2005-09-30  Andrew Macleod  <amacleod@redat.com>
+
+	PR tree-optimization/21430
+	* tree-ssa-operands.c (set_virtual_use_link): New. Link new virtual
+	use operands, and set stmt pointer if need be.
+	(FINALIZE_CORRECT_USE: New. Macro to call appropriate use fixup routine.
+	tree-ssa-opfinalize.h (FINALIZE_FUNC): Call FINALIZE_CORRECT_USE if
+	present.
+
 2005-09-29  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>
 
 	PR middle-end/24053
diff --git a/gcc/tree-ssa-operands.c b/gcc/tree-ssa-operands.c
index 5b1e4454e4d9..1c592573e819 100644
--- a/gcc/tree-ssa-operands.c
+++ b/gcc/tree-ssa-operands.c
@@ -511,6 +511,24 @@ correct_use_link (use_operand_p ptr, tree stmt)
 }
 
 
+/* This routine makes sure that PTR is in an immediate use list, and makes
+   sure the stmt pointer is set to the current stmt.  Virtual uses do not need
+   the overhead of correct_use_link since they cannot be directly manipulated
+   like a real use can be.  (They don't exist in the TREE_OPERAND nodes.)  */
+static inline void
+set_virtual_use_link (use_operand_p ptr, tree stmt)
+{
+  /*  Fold_stmt () may have changed the stmt pointers.  */
+  if (ptr->stmt != stmt)
+    ptr->stmt = stmt;
+
+  /* If this use isn't in a list, add it to the correct list.  */
+  if (!ptr->prev)
+    link_imm_use (ptr, *(ptr->use));
+}
+
+
+
 #define FINALIZE_OPBUILD		build_defs
 #define FINALIZE_OPBUILD_BASE(I)	opbuild_elem_real (&build_defs, (I))
 #define FINALIZE_OPBUILD_ELEM(I)	opbuild_elem_real (&build_defs, (I))
@@ -553,6 +571,7 @@ finalize_ssa_defs (tree stmt)
 #define FINALIZE_ELEM(PTR)	((PTR)->use_ptr.use)
 #define FINALIZE_OPS		USE_OPS
 #define FINALIZE_USE_PTR(PTR)	USE_OP_PTR (PTR)
+#define FINALIZE_CORRECT_USE	correct_use_link
 #define FINALIZE_BASE(VAR)	VAR
 #define FINALIZE_BASE_TYPE	tree *
 #define FINALIZE_BASE_ZERO	NULL
@@ -596,6 +615,7 @@ finalize_ssa_uses (tree stmt)
 #define FINALIZE_ELEM(PTR)	MAYDEF_RESULT (PTR)
 #define FINALIZE_OPS		MAYDEF_OPS
 #define FINALIZE_USE_PTR(PTR)	MAYDEF_OP_PTR (PTR)
+#define FINALIZE_CORRECT_USE	set_virtual_use_link
 #define FINALIZE_BASE_ZERO	0
 #define FINALIZE_BASE(VAR)	((TREE_CODE (VAR) == SSA_NAME)		\
 				? DECL_UID (SSA_NAME_VAR (VAR)) : DECL_UID ((VAR)))
@@ -647,6 +667,7 @@ cleanup_v_may_defs (void)
 #define FINALIZE_ELEM(PTR)	VUSE_OP (PTR)
 #define FINALIZE_OPS		VUSE_OPS
 #define FINALIZE_USE_PTR(PTR)	VUSE_OP_PTR (PTR)
+#define FINALIZE_CORRECT_USE	set_virtual_use_link
 #define FINALIZE_BASE_ZERO	0
 #define FINALIZE_BASE(VAR)	((TREE_CODE (VAR) == SSA_NAME)		\
 				? DECL_UID (SSA_NAME_VAR (VAR)) : DECL_UID ((VAR)))
@@ -740,6 +761,7 @@ finalize_ssa_vuses (tree stmt)
 #define FINALIZE_ELEM(PTR)	MUSTDEF_RESULT (PTR)
 #define FINALIZE_OPS		MUSTDEF_OPS
 #define FINALIZE_USE_PTR(PTR)	MUSTDEF_KILL_PTR (PTR)
+#define FINALIZE_CORRECT_USE	set_virtual_use_link
 #define FINALIZE_BASE_ZERO	0
 #define FINALIZE_BASE(VAR)	((TREE_CODE (VAR) == SSA_NAME)		\
 				? DECL_UID (SSA_NAME_VAR (VAR)) : DECL_UID ((VAR)))
diff --git a/gcc/tree-ssa-opfinalize.h b/gcc/tree-ssa-opfinalize.h
index 4c5b3fb53827..f58c93f3a197 100644
--- a/gcc/tree-ssa-opfinalize.h
+++ b/gcc/tree-ssa-opfinalize.h
@@ -86,8 +86,8 @@ FINALIZE_FUNC (tree stmt)
 	  /* if variables are the same, reuse this node.  */
 	  last->next = old_ops;
 	  last = old_ops;
-#ifdef FINALIZE_USE_PTR
-	  correct_use_link (FINALIZE_USE_PTR (last), stmt);
+#ifdef FINALIZE_CORRECT_USE
+	  FINALIZE_CORRECT_USE (FINALIZE_USE_PTR (last), stmt);
 #endif
 	  old_ops = old_ops->next;
 	  new_i = opbuild_next (&FINALIZE_OPBUILD, new_i);
@@ -173,3 +173,4 @@ FINALIZE_FUNC (tree stmt)
 #undef FINALIZE_OPBUILD_ELEM
 #undef FINALIZE_OPBUILD_BASE
 #undef FINALIZE_BASE_ZERO
+#undef FINALIZE_CORRECT_USE
-- 
GitLab