This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: optimization request: (-a)*(-b) => a*b
- To: Sylvain Pion <Sylvain dot Pion at sophia dot inria dot fr>
- Subject: Re: optimization request: (-a)*(-b) => a*b
- From: Nathan Sidwell <nathan at acm dot org>
- Date: Thu, 04 Mar 1999 11:39:09 +0000
- CC: egcs at egcs dot cygnus dot com
- Organization: University of Bristol
- References: <19990304113339.A661@rigel.inria.fr> <19990304114730.B661@rigel.inria.fr>
- Reply-To: nathan at compsci dot bristol dot ac dot uk
Sylvain Pion wrote:
>
> While I am at it, I also think the following kind of tests can be optimized:
> (-a)>0 => a<0
>
> Am I right ? Is it doable ?
Depends on what the type and representation of a is.
If it is a floating point type with ieee representation, there is a +0 and a
-0. ieee semantics are a bit strange here and there is some interaction with
rounding modes IIR. It depends on how closely your trying to get ieee
semantics.
If a is an unsigned integral type, -a >0 -> a != 0.
If a is a signed integral type, it depends on the semantics defined for signed
integral overflow. The problem is we're dealing with bounded integers, and
we've defined what happens when the mathematically correct result lies outside
the representable range. Although the standard makes this implementation
defined for signed integral types, most (all?) gcc implementationd define
signed integral arithmetic as wrapping (just as unsigned arithmetic is mandated
to). The problem with transforming (-a)>0 into a<0 is that mostneg int is
tranformed incorrectly. For a 32bit 2's complement system, this has a as value
-2^31, the negation operation gives the same value result (by truncating the
true result, and then reinterpreting the bit pattern), unfortunately. So for
this value (-(-2^31))>0 is false, yet your proposed transform (-2^31)<0 is
true.
If you're happy changing the semantics of overflowing signed arithmetic from
implentation defined to undefined, then the suggested optimization is ok.
nathan
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
You can up the bandwidth, but you can't up the speed of light
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk