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 (take 2)
On Sun, Feb 09, 2003 at 06:09:33AM -0700, Roger Sayle wrote:
> Think of it as "-A - B" -> "-(A+B)" -> "-(B+A)" -> "-B - A", which
> are each transforms that we'd be happy to make, but don't apply as
> they don't individually decrease the number of operations required.
This isn't really my area, so I may be off the wall here, but are those
really "transformations that we'd be happy to make"? What if A is
MAX_INT and B is 1; -A - B is legal, but -(A+B) overflows. All it
takes is a processor which traps on signed arithmetic overflow. I
don't know if we have one of those or not.
> But you do raise an excellent point, just because a commercial compiler
> targeting a single processor can apply a transformation, doesn't mean
> that GCC can do they same at the tree-level, without checking with
> optabs and/or the target description first.
>
>
> Its far easier for you to prove the transformation is "unsafe", you
> only have to find a single counter-example. I'm trying hard to convince
> you that I've thought of every eventuality, including the hazardous
> areas that you point out. Of course for GCC, I don't have to prove its
> safe, just persuade you that its an acceptable risk and promise to
> revert the patch in the event that it creates a problem.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer