From d15adbeb3f73ab2765c7f700c576410445d144fd Mon Sep 17 00:00:00 2001
From: Richard Guenther <rguenther@suse.de>
Date: Tue, 24 Aug 2010 13:25:25 +0000
Subject: [PATCH] re PR middle-end/45379 (~10% slowdown on test_fpu at revision
 163278)

2010-08-24  Richard Guenther  <rguenther@suse.de>

	PR middle-end/45379
	* tree-ssa-address.c (create_mem_ref_raw): Drop to MEM_REF
	if addr->index is NULL or zero.
	* tree-ssa-alias.c (indirect_refs_may_alias_p): Handle
	TARGET_MEM_REF more properly.
	(indirect_ref_may_alias_decl_p): Likewise.
	* emit-rtl.c (set_mem_attributes_minus_bitpos): Keep TARGET_MEM_REFs.
	* alias.c (ao_ref_from_mem): Handle TARGET_MEM_REF more
	properly.

From-SVN: r163519
---
 gcc/ChangeLog          | 12 ++++++++++++
 gcc/alias.c            | 16 ++++++++++++++++
 gcc/emit-rtl.c         |  1 +
 gcc/tree-ssa-address.c |  3 +--
 gcc/tree-ssa-alias.c   | 36 +++++++++++++++++++++++++++---------
 5 files changed, 57 insertions(+), 11 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 8b62c47b0b4b..259fe053ba21 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,15 @@
+2010-08-24  Richard Guenther  <rguenther@suse.de>
+
+	PR middle-end/45379
+	* tree-ssa-address.c (create_mem_ref_raw): Drop to MEM_REF
+	if addr->index is NULL or zero.
+	* tree-ssa-alias.c (indirect_refs_may_alias_p): Handle
+	TARGET_MEM_REF more properly.
+	(indirect_ref_may_alias_decl_p): Likewise.
+	* emit-rtl.c (set_mem_attributes_minus_bitpos): Keep TARGET_MEM_REFs.
+	* alias.c (ao_ref_from_mem): Handle TARGET_MEM_REF more
+	properly.
+
 2010-08-23  Anatoly Sokolov  <aesok@post.ru>
 
 	* config/m32c/m32c.c (m32c_function_value_regno_p): Make static.
diff --git a/gcc/alias.c b/gcc/alias.c
index 6defc79d7a04..fac5a024c46d 100644
--- a/gcc/alias.c
+++ b/gcc/alias.c
@@ -283,6 +283,10 @@ ao_ref_from_mem (ao_ref *ref, const_rtx mem)
        || TREE_CODE (base) == MEM_REF)
       && TREE_CODE (TREE_OPERAND (base, 0)) != SSA_NAME)
     return false;
+  if (TREE_CODE (base) == TARGET_MEM_REF
+      && TMR_BASE (base)
+      && TREE_CODE (TMR_BASE (base)) != SSA_NAME)
+    return false;
 
   /* If this is a reference based on a partitioned decl replace the
      base with an INDIRECT_REF of the pointer representative we
@@ -296,6 +300,18 @@ ao_ref_from_mem (ao_ref *ref, const_rtx mem)
       if (namep)
 	ref->base = build_simple_mem_ref (*(tree *)namep);
     }
+  else if (TREE_CODE (base) == TARGET_MEM_REF
+	   && TMR_SYMBOL (base)
+	   && TREE_CODE (TMR_SYMBOL (base)) == VAR_DECL
+	   && ! TREE_STATIC (TMR_SYMBOL (base))
+	   && cfun->gimple_df->decls_to_pointers != NULL)
+    {
+      void *namep;
+      namep = pointer_map_contains (cfun->gimple_df->decls_to_pointers,
+				    TMR_SYMBOL (base));
+      if (namep)
+	ref->base = build_simple_mem_ref (*(tree *)namep);
+    }
 
   ref->ref_alias_set = MEM_ALIAS_SET (mem);
 
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index 267d63462f0a..9f96abf76d26 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -1788,6 +1788,7 @@ set_mem_attributes_minus_bitpos (rtx ref, tree t, int objectp,
 
       /* If this is an indirect reference, record it.  */
       else if (TREE_CODE (t) == MEM_REF 
+	       || TREE_CODE (t) == TARGET_MEM_REF
 	       || TREE_CODE (t) == MISALIGNED_INDIRECT_REF)
 	{
 	  expr = t;
diff --git a/gcc/tree-ssa-address.c b/gcc/tree-ssa-address.c
index 77dfa60000de..ffc5541179e4 100644
--- a/gcc/tree-ssa-address.c
+++ b/gcc/tree-ssa-address.c
@@ -357,8 +357,7 @@ create_mem_ref_raw (tree type, tree alias_ptr_type, struct mem_address *addr)
 
   /* If possible use a plain MEM_REF instead of a TARGET_MEM_REF.  */
   if (alias_ptr_type
-      && !addr->index
-      && !addr->step
+      && (!addr->index || integer_zerop (addr->index))
       && (!addr->base || POINTER_TYPE_P (TREE_TYPE (addr->base))))
     {
       tree base;
diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c
index 849c25004e6d..a8d580e88ad3 100644
--- a/gcc/tree-ssa-alias.c
+++ b/gcc/tree-ssa-alias.c
@@ -672,10 +672,16 @@ indirect_ref_may_alias_decl_p (tree ref1 ATTRIBUTE_UNUSED, tree base1,
 
   if (TREE_CODE (base1) == TARGET_MEM_REF)
     {
-      if (!TMR_BASE (base1)
-	  || !POINTER_TYPE_P (TMR_BASE (base1)))
+      if (TMR_BASE (base1))
+	{
+	  if (!POINTER_TYPE_P (TREE_TYPE (TMR_BASE (base1))))
+	    return true;
+	  ptr1 = TMR_BASE (base1);
+	}
+      else if (TMR_SYMBOL (base1))
+	ptr1 = build_fold_addr_expr (TMR_SYMBOL (base1));
+      else
 	return true;
-      ptr1 = TMR_BASE (base1);
     }
   else
     ptr1 = TREE_OPERAND (base1, 0);
@@ -808,20 +814,32 @@ indirect_refs_may_alias_p (tree ref1 ATTRIBUTE_UNUSED, tree base1,
 
   if (TREE_CODE (base1) == TARGET_MEM_REF)
     {
-      if (!TMR_BASE (base1)
-	  || !POINTER_TYPE_P (TMR_BASE (base1)))
+      if (TMR_BASE (base1))
+	{
+	  if (!POINTER_TYPE_P (TREE_TYPE (TMR_BASE (base1))))
+	    return true;
+	  ptr1 = TMR_BASE (base1);
+	}
+      else if (TMR_SYMBOL (base1))
+	ptr1 = build_fold_addr_expr (TMR_SYMBOL (base1));
+      else
 	return true;
-      ptr1 = TMR_BASE (base1);
     }
   else
     ptr1 = TREE_OPERAND (base1, 0);
 
   if (TREE_CODE (base2) == TARGET_MEM_REF)
     {
-      if (!TMR_BASE (base2)
-	  || !POINTER_TYPE_P (TMR_BASE (base2)))
+      if (TMR_BASE (base2))
+	{
+	  if (!POINTER_TYPE_P (TREE_TYPE (TMR_BASE (base2))))
+	    return true;
+	  ptr2 = TMR_BASE (base2);
+	}
+      else if (TMR_SYMBOL (base2))
+	ptr2 = build_fold_addr_expr (TMR_SYMBOL (base2));
+      else
 	return true;
-      ptr2 = TMR_BASE (base2);
     }
   else
     ptr2 = TREE_OPERAND (base2, 0);
-- 
GitLab