[Bug rtl-optimization/59999] [4.9 Regression] Sign extension in loop regression blocks generation of zero overhead loop
paulo@matos-sorge.com
gcc-bugzilla@gcc.gnu.org
Thu Feb 6 13:04:00 GMT 2014
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59999
--- Comment #17 from Paulo J. Matos <paulo@matos-sorge.com> ---
(In reply to rguenther@suse.de from comment #15)
> On Thu, 6 Feb 2014, paulo@matos-sorge.com wrote:
>
> > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59999
> >
> > --- Comment #14 from Paulo J. Matos <paulo@matos-sorge.com> ---
> > Something like this which looks much simpler hits the same problem:
> > extern int arr[];
> >
> > void
> > foo32 (int limit)
> > {
> > short i;
> > for (i = 0; (int)i < limit; i++)
> > arr[i] += 1;
> > }
>
> Exactly the same problem. C integral type promotion rules make
> that i = (short)((int)i + 1) again. Note that (int)i + 1
> does not overflow, (short) ((int)i + 1) invokes implementation-defined
> behavior which in our case is modulo-2 reduction.
>
> Nothing guarantees that (short)i + 1 does not overflow.
I am being thick... indeed I forgot to notice that i++ also invokes undefined
behaviour. I guess then GCC sorts that out by casting i into unsigned short for
the addition and all the remaining issues then unfold.
More information about the Gcc-bugs
mailing list