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] Fix optimization regression in constant folder


Hi,

On Thu, 11 Oct 2007, Richard Kenner wrote:

> > E.g. one transformation it does is (X*c1)/c2 to X*(c1/c2) if c1%c2==0, for 
> > sizetypes (und OVERFLOW_UNDEFINED ones).
> > 
> > Suppose that X is the latter part of Marks reassociated expression, C-B, 
> > with B large, so that (C-B)*c1 would overflow.
> 
> I'm having trouble following your example.  It seems it would be 
> converting an expression that *did* overflow into one that doesn't.  

The point is that (X*c1)/c2 and X*(c1/c2) are _different_ for some values 
of X,c1 and c2 (namely sometimes but not all the time when X*c1 
overflows).  Assuming that the first value was the correct one (for 
instance zero) we will have introduced a miscompilation.  We have two ways 
for fixing this:
1) declare the precondition (the initial overflow) to be invalid.
2) don't do the transformation in flow

Solution (1) would require that overflow in sizetype is not ignored, but 
undefined.  Then we couldn't have done the reassociation which created 
this problem.  But that is something you explicitely didn't want.

Solution (2) would require removing the exception for sizetype, at which 
point it again looks more like an unsigned wrapping type.


Ciao,
Michael.


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