This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Coalesce in more cases


Hi,

gimple_can_coalesce_p is rather picky about the conditions under which SSA 
names can be coalesced.  In particular, when it comes to the type, it's:

  /* 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)

or

  /* 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. 

     Note pointer types with different address spaces may have the same
     canonical type.  Those are rejected for coalescing by the
     types_compatible_p check.  */
  if (TYPE_CANONICAL (t1)
      && TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2)
      && types_compatible_p (t1, t2))
    goto check_modes;

The test on TYPE_CANONICAL looks overkill to me.  It's needed in the non-
optimized case (-fno-tree-coalesce-vars) as compute_samebase_partition_bases 
uses TYPE_CANONICAL to discriminate partitions, but it's not needed in the 
optimized case as compute_optimized_partition_bases uses the full information.
For example, in Ada it prevents subtypes from being coalesced with types and 
in C++ it prevents different pointer types from being coalesced.  Hence the 
attached patch, which lifts the restriction in the optimized case.

Tested on x86_64-suse-linux, OK for the mainline?


2016-05-05  Eric Botcazou  <ebotcazou@adacore.com>

	* tree-ssa-coalesce.c (gimple_can_coalesce_p): In the optimized case,
	allow coalescing if the types are compatible.

-- 
Eric Botcazou
Index: tree-ssa-coalesce.c
===================================================================
--- tree-ssa-coalesce.c	(revision 235900)
+++ tree-ssa-coalesce.c	(working copy)
@@ -1569,17 +1569,24 @@ gimple_can_coalesce_p (tree name1, tree
 			    var2 ? LOCAL_DECL_ALIGNMENT (var2) : TYPE_ALIGN (t2)))
     return false;
 
-  /* If the types are not the same, check for a canonical type match.  This
+  /* If the types are not the same, see whether they are compatible.  This
      (for example) allows coalescing when the types are fundamentally the
-     same, but just have different names. 
+     same, but just have different names.
 
-     Note pointer types with different address spaces may have the same
-     canonical type.  Those are rejected for coalescing by the
-     types_compatible_p check.  */
-  if (TYPE_CANONICAL (t1)
-      && TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2)
-      && types_compatible_p (t1, t2))
-    goto check_modes;
+     In the non-optimized case, we must first test TYPE_CANONICAL because
+     we use it to compute the partition_to_base_index of the map.  */
+  if (flag_tree_coalesce_vars)
+    {
+      if (types_compatible_p (t1, t2))
+	goto check_modes;
+    }
+  else
+    {
+      if (TYPE_CANONICAL (t1)
+	  && TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2)
+	  && types_compatible_p (t1, t2))
+	goto check_modes;
+    }
 
   return false;
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]