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 Tue, 14 Jan 2003, Roger Sayle wrote:

> Not only is it also safe for integer constants, but also for
> other forms of expressions that are cheaply negated.  The obvious
> case is where B is a negation, i.e. -C, would transform -A - -C
> into C - A, but this is already handled by constant folding.
> A more interesting case is where B is a subtraction D-E, then
> -A - (D-E) becomes (E-D) - A, which saves a negation.

But this isn't safe if D-E is the most negative integer.  Various code in
GCC knows that signed integer overflow is undefined and this
transformation could run into such code, whether present now or added
later.

-- 
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]