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]

Re: [tree-ssa] PATCH to improve optimization at ssa rewrite time



On Tuesday, May 13, 2003, at 03:36 PM, Andrew MacLeod wrote:


On Tue, 2003-05-13 at 15:26, Daniel Berlin wrote:
This is very useful in conjunction with expression temporaries, which
produce a lot of redundant statements.


Actually, as I pointed out to Diego privately, doing all these
redundancy eliminations is really screwing up PRE.
I've come up with tons of cases where we'd be able to eliminate the
entire function if we didn't do these optimizations when going into SSA
(because PRE would enable CCP to constant convert everything), but we
are left with computations because we did.


As soon as PRE is on by default, i'm going to be looking at switching
off some of these into-SSA optimizations.


How much of that will be taken care of though when we start propagating
constants into the PHI nodes?
Not much, actually.
We lose a lot of load PRE and strength reduction opportunities in particular.
Here's an example i showed Diego:


Original code
int main(void)
{
        int a;
        int b;
        int c;
        a = 5;
        b = a * 5;
        if (c)
        {
                a = a + 1;
        }
        else
        {
                a = a + 2;
        }
        b = a * 5;
}
We can SSAPRE + strength reduce this into:
{
  int pretmp.1;
  int a;
  int b;
  int c;

  a_2 = 5;
  pretmp.1_8 = a_2 * 5;
  b_3 = pretmp.1_8;
  if (c_4 != 0)
    {
      {
        a_5 = a_2 + 1;
        pretmp.1_10 = pretmp.1_8 + 5
      }
    }
  else
    {
      {
        a_6 = a_2 + 2;
        pretmp.1_11 = pretmp.1_8 + 10
      }
    };
  #   a_1 = PHI <a_5(1), a_6(2)>;
  #   pretmp.1_9 = PHI <pretmp.1_10(1), pretmp.1_11(2)>;
  b_7 = pretmp.1_9
}
CCP after SSAPRE then transforms this into:

{
  int pretmp.1;
  int a;
  int b;
  int c;

  a_2 = 5;
  pretmp.1_8 = 25
  b_3 = 25;
  if (c_4 != 0)
    {
      {
        a_5 = 6;
        pretmp.1_10 = 30;
      }
    }
  else
    {
      {
        a_6 = 7;
        pretmp.1_11 = 35;
      }
    };
  #   a_1 = PHI <a_5(1), a_6(2)>;
  #   pretmp.1_9 = PHI <pretmp.1_10(1), pretmp.1_11(2)>;
  b_7 = pretmp.1_9
}

Note that assuming b_7 was used, all we'd need to add would be the copies.
We've removed all computation in the procedure.


*However*, doing simple const-prop during SSA-rewriting (as we do now)
transforms the original into:
;; Function main (main)

main ()
{
  int a;
  int b;
  int c;

  a_2 = 5;
  b_3 = 25
  if (c_4 != 0)
    {
      {
        a_5 = 6;
      }
    }
  else
    {
      {
        a_6 = 7;
      }
    };
  #   a_1 = PHI <a_5(1), a_6(2)>;
  b_7 = a_1 * 5
}

We can't SSAPRE this at *all*, and therefore, are left with the multiply.
Propping the constants into the phi won't help you here, because it's different on each branch.


Every single strength reduction test and load PRE test I have won't optimize away completely anymore (when they should) because of into-ssa optimizations.
Even the trivial ones don't optimize away anymore, which doesn't bode well for more complex ones.
If I turn off the into-ssa optimizations, they all optimize away completely again.


This doesn't even touch the problem of non-optimal placements we now get in all forms of PRE.


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