On 11/11/22 11:47, Jakub Jelinek wrote:
On Fri, Nov 11, 2022 at 11:01:38AM +0100, Aldy Hernandez wrote:
I've tried following, but it suffers from various issues:
1) we don't handle __builtin_signbit (whatever) == 0 (or != 0) as guarantee
that in the guarded code whatever has signbit 0 or 1
We have a range-op entry for __builtin_signbit in cfn_signbit. Is this a
shortcoming of this code, or something else?
Dunno, I admit I haven't investigated it much. I just saw it when putting
a breakpoint on the mult fold_range.
Could you send me a small testcase. I can look into that.
2) __builtin_isinf (x) > 0 is lowered to x > DBL_MAX, but unfortunately we don't
infer from that [INF,INF] range, but [DBL_MAX, INF] range
3) what I wrote above, I think we don't handle [0, 2] * [INF, INF] right but
due to 2) we can't see it
Doesn't this boil down to a representation issue? I wonder if we should
bite the bullet and tweak build_gt() and build_lt() to represent open
ranges. In theory it should be one more/less ULP, while adjusting for
HONOR_INFINITIES.
At least with the exception of MODE_COMPOSITE_P, I think we don't need
to introduce open ranges (and who cares about MODE_COMPOSITE_P if it is
conservatively correct).
For other floats, I think
x > cst
is always equivalent to
x >= nextafter (cst, inf)
and
x < cst
is always equivalent to
x <= nextafter (cst, -inf)
except for the signed zero cases which needs tiny bit more thought.
So, if we have
if (x > DBL_MAX)
then in code guarded by that we can just use [INF, INF] as range.
Yeah, yeah. That's exactly what I meant... using nextafter. I'll look
into that, as there seems there's more than one issue related to our
lack of precision in representing < and >.
If the signbit issue were resolved and we could represent > and < properly,
would that allow us to write proper testcases without having to writing a
plug-in (which I assume is a lot harder)?
I don't know, we'd need to see.
First work out on all the issues that result on the testcase the operand
ranges aren't exactly what we want (whether on the testcase side or on the
range-ops side or wherever) and once that looks ok, see if the ranges
on the rN/sN vars are correct and if so, watch what hasn't been folded away
and why.
I think the plugin would be 100-200 lines of code and then we could just
write multiple testcases against the plugin.
If you think the plug-in will get better test coverage, by all means. I
was just trying to save you/us some work.
Andrew, do you have any thoughts on the plug-in?
Aldy