This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Constant fold -A - B as -B - A
- From: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- To: Roger Sayle <roger at www dot eyesopen dot com>
- Cc: <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 15 Jan 2003 08:41:18 +0000 (GMT)
- Subject: 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