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: Re: gcj non-optimization curiosity


>>>>> "Bryce" == Bryce McKinlay <bryce@waitaki.otago.ac.nz> writes:

Thanks for looking into this.

Bryce> Where .L14 is the "throw ArrayBoundsException". The redundant
Bryce> bounds check is check is still there (it can never occur
Bryce> because the bounds of the loop are the same as the bounds of
Bryce> the array, so why can't the optimizer get rid of it?), but the
Bryce> generated code is much better than before.

The more-or-less equivalent C++ code, appended, also generates a
redundant bounds check.  Perhaps our optimizer simply can't do this
yet.

Tom

struct z
{
  const int length;
  int ary[0];
};
  
extern struct z *foo ();


int main ()
{
  struct z *l = foo ();
  int i;
  int x = 0;

  for (i = 0; i < l->length; ++i)
    {
      if ((unsigned) i >= (unsigned) (l->length))
	throw 1;
      x += l->ary[i];
    }

  return x;
}


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