This is the mail archive of the gcc@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]

Re: [tree-ssa] DCE and conditionals


On Mon, 2003-05-05 at 16:11, Diego Novillo wrote:
> On Mon, May 05, 2003 at 08:31:47AM -0400, Andrew MacLeod wrote:

> > 
> > if (t_5>0)
> >   a_2 = a_1;
> > else
> >   a_3 = a_0;
> > lab:
> >   a5 = PHI (a_2, a_3, a_4)  /* a_4 comes in from a goto lab:.  */
> > 
> After fixing the flow graph linearizer, this should be converted
> into:
> 
> 	if ((void)0)
> 	  (void)0;
> 	else
> 	  (void)0;
> 	lab:
> 	  a_5 = PHI <a_1, a_0, a_4>
> 
> Note how the COND_EXPR is only kept because it provides the
> structure needed to feed that PHI node.  If all 'a's coalesce
> together, then SSA->normal could remove the empty skeleton for
> the if().
> 

No, this isnt quite correct. This demonstrates the exact problem I am
having. You need to keep the condition in the if (cond) as well.

If a_1 and a_0 do not coalesce, then a_5 needs to have a copy on one of
the 2 branches of the conditional in order to calculate the PHI node. 
And in order to do that, you have to know what the original condition
was.

so :

a_1 = func(1);
a_0 = func(2);
t_4= foo();
t_5 = t_4 * 2;
if (t_5>0)
  a_2 = a_1;
else
  a_3 = a_0;
lab:
a5 = PHI (a_2, a_3, a_4);

What you suggested would result in:

      a_1 = func(1);
      a_0 = func(2);
      t_4 = foo ();
      t_5 = t_4 * 2;
      if ((void)0)
        (void)0;
      else
        (void)0;
      lab:
      a_5 = PHI <a_1, a_0, a_4>

And for fun, lets make a_5 coalesce with a_0. a_1 and a_0 interefere,
so  a_1 stays on its own.

That means I have to insert a copy on the 'Then' side of the if in order
to get the right value into a_5:

      a_1 = func(1);
      a_0 = func(2);
      t_4 = foo ();
      if ((void)0)
        a_5 = a_1
      else
        (void)0;
      lab:
      
But the conditional is gone now, so it doesn't mean anything. we have to
leave the (t_5 > 0) in the if as well, plus anything which feeds it. If
all the a_X's did coalesce, we'd still be left with the conditional in
the code, plus anything feeding it even though its not needed.

And that brings me back to what I was talking about. We can't get rid of
that condition as is... Which is why I want to run DCE on the coalesced
registers before I rewrite... And in order for that to be effective, we
should look at phi removal when possible since thats what ends up
keeping the conditions alive... 

Andrew



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