The following attempts to set a MEM_BASE from set_mem_attributes_minus_bitpos
which is often first called on the expanded base of a complicated memory
reference.  For now simply preserve a SYMBOL_REF (fancy unwrapping to be
implemented).

The commented code would transfer some points-to info.

        * emit-rtl.cc (set_mem_attributes_minus_bitpos): If ref
        is suitable as base, record it.
---
 gcc/emit-rtl.cc | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/gcc/emit-rtl.cc b/gcc/emit-rtl.cc
index 1cf238d9571..3fb52a87e08 100644
--- a/gcc/emit-rtl.cc
+++ b/gcc/emit-rtl.cc
@@ -2027,6 +2027,12 @@ set_mem_attributes_minus_bitpos (rtx ref, tree t, int 
objectp,
   if (objectp || TREE_CODE (t) == INDIRECT_REF)
     attrs.align = MAX (attrs.align, TYPE_ALIGN (type));
 
+  /* We usually expand the base of a complicated ref first, so record any
+     base value we can determine.  ???  Probably should use a simplified
+     find_base_value here to unwrap a contained SYMBOL_REF.  */
+  if (GET_CODE (ref) == SYMBOL_REF)
+    attrs.base = copy_rtx (ref);
+
   /* If the size is known, we can set that.  */
   tree new_size = TYPE_SIZE_UNIT (type);
 
@@ -2074,6 +2080,24 @@ set_mem_attributes_minus_bitpos (rtx ref, tree t, int 
objectp,
                                                                      0))));
          else
            as = TYPE_ADDR_SPACE (TREE_TYPE (base));
+
+#if 0
+         /* Set the base RTX based on points-to info.  */
+         if (!attrs.base
+             && (TREE_CODE (base) == MEM_REF
+                 || TREE_CODE (base) == TARGET_MEM_REF)
+             && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME
+             && SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0)))
+           {
+             auto pt = &SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0))->pt;
+             if (pt->nonlocal
+                 && !pt->anything
+                 && !pt->escaped
+                 && !pt->ipa_escaped
+                 && bitmap_empty_p (pt->vars))
+               attrs.base = arg_base_value;
+           }
+#endif
        }
 
       /* If this expression uses it's parent's alias set, mark it such
-- 
2.35.3

Reply via email to