PATCH: Re: gcj non-optimization curiosity

Tom Tromey tromey@redhat.com
Mon Dec 17 14:28:00 GMT 2001


>>>>> "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;
}



More information about the Gcc-patches mailing list