LTGT_EXPR hasn't been handling relations, especially with NANs as a possibility. This handles them while documenting how relations work in a world with NANs.
Basically we need to special case VREL_EQ before calling frelop_early_resolve. Note that VREL_EQ on entry to a range-op entry is really VREL_EQ U NAN, but to make sure about the NAN possibility, one must look at the operands. However, even VREL_EQ U NAN is false for LTGT_EXPR since the latter is just NE_EXPR without a NAN. After we handle VREL_EQ, we drop down to frelop_early_resolve pretending to be a NE_EXPR, and everything should just map correctly. 2023-08-28 Aldy Hernandez <al...@redhat.com> * range-op-float.cc (fold_range): Handle relations. --- gcc/range-op-float.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index 14199647744..eebc73f9918 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -2204,8 +2204,23 @@ class foperator_ltgt : public range_operator public: bool fold_range (irange &r, tree type, const frange &op1, const frange &op2, - relation_trio rel = TRIO_VARYING) const final override + relation_trio trio = TRIO_VARYING) const final override { + relation_kind rel = trio.op1_op2 (); + + // VREL_EQ is really VREL_(UN)EQ because we could have a NAN in + // the operands, but since LTGT_EXPR is really a NE_EXPR without + // the NAN, VREL_EQ & LTGT_EXPR is an impossibility. + if (rel == VREL_EQ) + { + r = range_false (type); + return true; + } + // ...otherwise pretend we're trying to resolve a NE_EXPR and + // everything will "just work". + if (frelop_early_resolve (r, type, op1, op2, trio, VREL_NE)) + return true; + if (op1.known_isnan () || op2.known_isnan ()) { r = range_false (type); @@ -2218,7 +2233,7 @@ public: if (op2.maybe_isnan ()) op2_no_nan.clear_nan (); if (!range_op_handler (NE_EXPR).fold_range (r, type, op1_no_nan, - op2_no_nan, rel)) + op2_no_nan, trio)) return false; // The result is the same as the ordered version when the // comparison is true or when the operands cannot be NANs. -- 2.41.0