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] Constant fold -A - B as -B - A


On Wed, 15 Jan 2003, Richard Earnshaw wrote:

> This doesn't make sense.  Firstly, the semantics of the C language 
> shouldn't be propagating beyond the front end -- are you suggesting an 
> optimization shouldn't be done for Fortran simply because it shouldn't be 
> done for C?  What about vice versa?

It's a fact that various middle-end optimisations do apply C rules - it's
presumed that trees (I don't know about RTL) have C semantics - part of
the heritage from GCC originally being just a compiler for C-family
languages (and I think these cases are undefined in Fortran as well).  As
previously noted, it would be desirable for a proper language-independent
representation to have overflow semantics represented explicitly, but we
don't have that now.

And fold-const.c is, at this point, being used on C language trees, as
well as those from other languages, not some language-independent
representation.

> Secondly, if the result is identical to not having done the transformation 
> then there is no problem -- this is simply applying the "as if" rule.  And 
> if we want the overflow behaviour then there will be something else in the 
> RTL/Tree that will indicate this and we can suppress the optimization in 
> that case.  Indeed, in the cited case, there's little point in doing the 
> transformation if D - E is not dead after the operation.

The problem is where the result isn't identical - where there's an
overflow after the transformation that wasn't there before.  (The other
way round we don't care about except with -ftrapv.)

-- 
Joseph S. Myers
jsm28@cam.ac.uk


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