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: GCC optimizes integer overflow: bug or feature?


On Tue, 2006-12-19 at 03:42 -0500, Robert Dewar wrote:
> 
> When I worked on SPITBOL, people all the time were suggesting
> optimizations in letters to the SPITBOL newsletter. I imposed
> a rule saying that no one could propose an optimization unless
> they could show ONE example program where the optimization could
> plausibly save 5% execution time. I never got another suggestion.

http://gcc.gnu.org/bugzilla//show_bug.cgi?id=18527

A simple loop like:
int foo ()
{
  int a[N];
  int i;
  int n;

  for (i = 0; i <= n; i++)
      ca[i] = 2;
}

we cannot find how many iterations it runs without knowing that signed
types overflow.
And yes people write code like that, it shows up in GCC itself IIRC (as
the original testcase comes from GCC in SPEC).

I don't have the number of times this shows up or how much it helps but
it does help out on being able to vectorize this loop.

Another example (this time for "for (i=i0; i<=i1+1; ++i)" )
http://gcc.gnu.org/bugzilla//show_bug.cgi?id=26900
via:
http://gcc.gnu.org/bugzilla//show_bug.cgi?id=26899

which can only be done when signed overflow is undefined.

All of these do show up in real code, and since loops are now more
important to optimize than anything else, well knowing the number of
iterations is very important.

Thanks,
Andrew Pinski


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