On 3/18/2022 7:16 AM, Andrew MacLeod wrote:
On 3/17/22 19:27, Jeff Law via Gcc-patches wrote:
On 3/15/2022 2:03 AM, Roger Sayle wrote:
-----Original Message-----
From: Richard Biener <richard.guent...@gmail.com>
Sent: 15 March 2022 07:29
To: Roger Sayle <ro...@nextmovesoftware.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Ignore (possible) signed zeros in operands of FP
comparisons.
On Mon, Mar 14, 2022 at 8:26 PM Roger Sayle
<ro...@nextmovesoftware.com> wrote:
I've been wondering about the possible
performance/missed-optimization
impact of my patch for PR middle-end/98420 and similar IEEE
correctness fixes that disable constant folding optimizations when
worrying
about -0.0.
In the common situation where the floating point result is used by a
FP comparison, there's no distinction between +0.0 and -0.0, so some
HONOR_SIGNED_ZEROS optimizations that we'd usually disable, are safe.
Consider the following interesting example:
int foo(int x, double y) {
return (x * 0.0) < y;
}
Although we know that x (when converted to double) can't be NaN or
Inf, we still worry that for negative values of x that (x * 0.0) may
be -0.0 and so perform the multiplication at run-time. But in this
case, the result of the comparison (-0.0 < y) will be exactly the
same
as (+0.0 < y) for any y, hence the above may be safely constant
folded to "0.0 <
y"
avoiding the multiplication at run-time.
I'm going to hazard a guess that this can be handled in the upcoming
floating point range support? there was a start of a conversation in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24021 about a month ago.
I know *zero* about floating point, but It seems like when we track
floating point ranges, we will naturally be able to integrate
_2 = _1 * 0.0;
_3 = _2 < y_5(D);
that _2 evaluates to +/- 0.0 and when we do look at (_2 < y_5)
that VRP can simplify that to 0.0 < y? (or any patch which uses
simplification and ranges). It seems like it should be
straightforward anyway.
Yea, I guess we'd pick it up that way and that's probably cleaner than
what I was originally thinking in this space.
We realize that 2 is +-0.0. Then we realize that for the comparison, we
can constant propagate +0.0 for _2 since +0.0 and -0.0 behave the same
way. Ideally that removes the last reference to _2 and we DCE away the
multiplication.
jeff