public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: Improve uncprop and coalescing
Date: Wed, 12 Jun 2013 04:44:00 -0000	[thread overview]
Message-ID: <51B7FCA4.4080201@redhat.com> (raw)
In-Reply-To: <CAFiYyc3nqON4KVMM0fwMZQGuj08K0pqNwHF3jbOfN+ZMu4wNrQ@mail.gmail.com>

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.
No it isn't.  types_compatible_p is far too permissive in this context 
without more surgery to tree-ssa-live.c.

So let's take two objects, P1 and P2 which are pointers to types T1 and 
T2 where T1 != T2.  Assume P1 and P2 are somehow connected by a copy or 
PHI node and that they are anonymously named objects.

types_compatible_p will return true for (T1, T2) unless T1 or T2 is a 
pointer to a function.  So if we used types_compatible_p we will try to 
coalesce P1 and P2 (which is seemingly a good thing).

Now in tree-ssa-live.c::var_map_base_init we have:

   /* Build the base variable list, and point partitions at their bases.  */
   for (x = 0; x < num_part; x++)
     {
       ...
       if (SSA_NAME_VAR (var))
         m->base.from = SSA_NAME_VAR (var);
       else
         /* This restricts what anonymous SSA names we can coalesce
            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);
       ...
     }

The way we set up base.from in var_map_base_init imposes requirements on 
what objects can be added to the coalescing lists.  We can only allow 
coalescing of objects with the same underlying SSA_NAME_VAR or anonymous 
objects with the same underlying TREE_TYPE (as the code is written 
today).  That's a side effect of restricting the sets we compute 
conflicts for.  If we don't compute the conflicts, then we'll assume P1 
and P2 don't conflict and happily coalesce them, regardless of whether 
or not they actually do conflict.

To use types_compatible_p to drive decisions in tree-ssa-coalesce.c, 
ISTM we'd have to change this code from tree-ssa-live.c to put all 
anonymous objects with a compatible type in the same hash entry.  I 
don't see a good way to do that without iterating over the hash table 
entries looking for a compatible match or completely reimplementing the 
hash.

By first checking if an anonymous variable's type has an underlying 
canonical type and using that instead to key decisions in 
var_map_base_init, we can allow more objects onto the coalescing lists 
in tree-ssa-coalesce.c.  In particular we can allow two anonymous 
objects where both have an underlying TYPE_CANONICAL that is the same.

>
>
> 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.
>
> Ok with that change.
Seems to make sense.  Though we still have a point of contention around 
whether or not we can use types_compatible_p to drive decisions in 
tree-ssa-coalesce.c.  I'm pretty sure we can't without some significant 
surgery in tree-ssa-live.c.

Jeff

  reply	other threads:[~2013-06-12  4:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-07  6:08 Jeff Law
2013-06-07  8:30 ` Steven Bosscher
2013-06-07 12:50   ` Jeff Law
2013-06-07  9:14 ` Richard Biener
2013-06-12  4:44   ` Jeff Law [this message]
2013-06-12 16:04   ` Jeff Law
2013-08-30 10:06     ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51B7FCA4.4080201@redhat.com \
    --to=law@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).