public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] Coalesce in more cases
@ 2016-05-05 15:08 Eric Botcazou
  2016-05-06 10:43 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Botcazou @ 2016-05-05 15:08 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1616 bytes --]

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

[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 1389 bytes --]

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;
 }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch] Coalesce in more cases
  2016-05-05 15:08 [patch] Coalesce in more cases Eric Botcazou
@ 2016-05-06 10:43 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2016-05-06 10:43 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: GCC Patches

On Thu, May 5, 2016 at 5:08 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
> 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?

Ok.

Richard.

>
> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-05-06 10:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-05 15:08 [patch] Coalesce in more cases Eric Botcazou
2016-05-06 10:43 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).