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: [PATCH] Make sure copy-prop runs before forwprop, do not propagate ADDR_EXPRs to simple copy statements


On Thu, 15 Mar 2007, Diego Novillo wrote:

> Richard Guenther wrote on 03/15/07 08:56:
> 
> > where it would propagate &Foo.i[i] into all rhs.  This is bad as it
> > causes interesting optimization oscillations between this and the
> > previous form.
> 
> "interesting optimization oscillations"?  I have no idea what you are
> trying to fix here.  The PR log wasn't too illuminating either.

This was a side-issue I didn't file a PR about. It's basically (feed that
into g++):

int a[50];
void foobar(int*,int*,int*,int*);
void foo(int i)
{
  int *pi = &a[i];
  int *q1 = pi;
  int *q2 = pi;
  int *q3 = pi;
  int *q4 = pi;
  foobar(q1,q2,q3,q4);
}

.29t.forwprop1:  (we shouldn't do the following)

void foo(int) (i)
{
  int * q4;
  int * q3;
  int * q2;
  int * q1;

<bb 2>:
  i_2 = i_1(D);
  q1_4 = &a[i_2];
  q2_5 = &a[i_2];
  q3_6 = &a[i_2];
  q4_7 = &a[i_2];
  foobar (q1_4, q2_5, q3_6, q4_7);
  return;

}

.50t.fre:  (FRE is clever, nothing did clean it up before)

void foo(int) (i)
{
  int * q4;
  int * q3;
  int * q2;
  int * q1;

<bb 2>:
  q1_4 = &a[i_1(D)];
  q2_5 = q1_4;
  q3_6 = q1_4;
  q4_7 = q1_4;
  foobar (q1_4, q2_5, q3_6, q4_7);
  return;

}

.52t.forwprop2: (heh, forwprop again!)

void foo(int) (i)
{
  int * q4;
  int * q3;
  int * q2;
  int * q1;

<bb 2>:
  q1_4 = &a[i_1(D)];
  q2_5 = &a[i_1(D)];
  q3_6 = &a[i_1(D)];
  q4_7 = &a[i_1(D)];
  foobar (q1_4, q2_5, q3_6, q4_7);
  return;

}

.057t.dom1:  (dom also thinks it knows what to do, it for the first time
replaces the uses in the fncall)

void foo(int) (i)
{
  int * q4;
  int * q3;
  int * q2;
  int * q1;

<bb 2>:
  q1_4 = &a[i_1(D)];
  q2_5 = q1_4;
  q3_6 = q1_4;
  q4_7 = q1_4;
  foobar (q1_4, q1_4, q1_4, q1_4);
  return;

}

.071t.dce4:  (luckily dce4 is before forwprop3, so we finally get)

void foo(int) (i)
{
  int * q1;

<bb 2>:
  q1_4 = &a[i_1(D)];
  foobar (q1_4, q1_4, q1_4, q1_4);
  return;

}

Now, if forwprop1 didn't to this stupid thing, we'd get from dce1 
(because copyprop1 is inbetween forwprop1 and dce1):

void foo(int) (i)
{
  int * pi;

<bb 2>:
  pi_3 = &a[i_1(D)];
  foobar (pi_3, pi_3, pi_3, pi_3);
  return;

}

Which is much less work than the above ;)

No, the patch is not obvious, but non-algorithmic enough for my taste.
Do you disagree here?

Thanks,
Richard.


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