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: [CFG] Loop unrolling


> Hello.
> 
> > > > > > I feel bit unconfortable to check in the code that is known to produce invalid
> > > > > > results even th te devel branch.
> > > > > 
> > > > > It should be correct in all useful cases. If someone relies on how program
> > > > > behave when counter overflows, he deserve his program not to work :-) But
> > > > > you're probably right with this.
> > > > 
> > > > Well, thats the matter of opinion. C stanrad specifies the overflow behaviour
> > > > on unisgned arithmetics, so it is perfectly correct to make unsigned loops
> > > > overflow and sometimes it even makes sense (when you need to iterate 2^32 times).
> > > 
> > > IMHO standard doesn't specify sizeof(int), so using it this way is not too
> > > reliable.  Also I do not optimize loops that use unsigned comparison in their
> > > exit condition at all now, exactly to avoid these problems. Unfortunately,
> > > if someone tests for equality and uses overflow, I may run into problems.
> > > I will look to it.
> > No, you can't rely on signedness of comparison. One can simply use insigned
> > counter and retype it to int.
> 
> And unless it is specified what happens if you retype value out of size of int
> (which probably isn't), I may do whatever I want.
I believe converison from unsigned larger than INT_MAX to negative value
is valid, curiously enought.
Aditionally you may just write the effect of signed comparison using two
unsigned comparisons and fold-consts will be able to notice that and put
in the signed code. It is not question whether sane code do this, we
must be correct in definition of people who write C compiler validation tests
that surely contain similar garbage.

GCC used to contain code that determines signedness (and overflowness) of
register this way in 2.7.2 but it had to be disabled. Even in some sane
cases it produced invalid code, unforutnately.
See loop* in execute testsuite for few.

Honza
> 
> Zdenek


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