On 06/07/13 03:14, Richard Biener wrote:

+/* Given SSA_NAMEs NAME1 and NAME2, return true if they are candidates for
+   coalescing together, false otherwise.
+
+   This must stay consistent with the code in tree-ssa-live.c which
+   sets up base values in the var map.  */
+
+bool
+gimple_can_coalesce_p (tree name1, tree name2)
+{
+  /* First check the SSA_NAME's associated DECL.  We only want to
+     coalesce if they have the same DECL or both have no associated DECL.
*/
+  if (SSA_NAME_VAR (name1) != SSA_NAME_VAR (name2))
+    return false;
+
+  /* Now check the types.  If the types are the same, then we should
+     try to coalesce V1 and V2.  */
+  tree t1 = TREE_TYPE (name1);
+  tree t2 = TREE_TYPE (name2);
+  if (t1 == t2)
+    return true;
+
+  /* If the types are not the same, check for a canonical type match.  This
+     (for example) allows coalescing when the types are fundamentally the
+     same, but just have different names.  */
+  if (TYPE_CANONICAL (t1) && TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2))

Please use types_compatible_p (t1, t2) here, that's the correct API to use
here.

+    return true;
+
+  return false;
+}
diff --git a/gcc/tree-ssa-live.c b/gcc/tree-ssa-live.c
index 83a52a0..a624d00 100644
--- a/gcc/tree-ssa-live.c
+++ b/gcc/tree-ssa-live.c
@@ -111,8 +111,12 @@ var_map_base_init (var_map map)
            as it restricts the sets we compute conflicts for.
            Using TREE_TYPE to generate sets is the easies as
            type equivalency also holds for SSA names with the same
-          underlying decl.  */
-       m->base.from = TREE_TYPE (var);
+          underlying decl.
+
+          Check gimple_can_coalesce_p when changing this code.  */
+       m->base.from = (TYPE_CANONICAL (TREE_TYPE (var))
+                       ? TYPE_CANONICAL (TREE_TYPE (var))
+                       : TREE_TYPE (var));

eh, but it's made complicated here ... so above do


if (TYPE_CANONICAL (t1) && TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2)
     && types_compatible_p (t1, t2))

because looking at useless_type_conversion_p it looks like pointer types
with different address-spaces may have the same canonical type.  A comment
on why we check both, refering to var_map_base_init should also be added.
Reading this again after a night of sleep, it appears you're agreeing that we can't just use types_compatible_p to drive what objects are put on the coalesce list. The only code change you're asking for is to make sure we properly reject pointer types with different address spaces (which can be done via types_compatible_p).


Right?

jeff


Reply via email to