From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2136) id A636138515C3; Tue, 6 Sep 2022 11:48:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A636138515C3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662464901; bh=ql/4V8e+wWq5gSDBhGsjgEFnYf2d77wWSleTX2Muyi4=; h=From:To:Subject:Date:From; b=FV3w3uBLrGFGswFNZhNzW5EY6ftLHta4q0hafvPaL7eBLbsYufUiu5Ert/yTFPnJP VV+dLf6FK3b1jt8FyzYpR+yQrXEnXvrVAL6pSexPDBHoADEA4lRzHAshBJwNQ2YI7W cj3t4UglQvFYkJbPgSUIGvJsm/FJNAv6ADQi7nss= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Aldy Hernandez To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-2498] Handle > INF and < INF correctly in range-op-float.cc X-Act-Checkin: gcc X-Git-Author: Aldy Hernandez X-Git-Refname: refs/heads/master X-Git-Oldrev: 12f0783111067b68673284665a886cdd0c8f55c3 X-Git-Newrev: f5dc9da0a97734ab68a4af34875640ed1ca0c7d1 Message-Id: <20220906114821.A636138515C3@sourceware.org> Date: Tue, 6 Sep 2022 11:48:21 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f5dc9da0a97734ab68a4af34875640ed1ca0c7d1 commit r13-2498-gf5dc9da0a97734ab68a4af34875640ed1ca0c7d1 Author: Aldy Hernandez Date: Tue Sep 6 08:20:54 2022 +0200 Handle > INF and < INF correctly in range-op-float.cc The gfortran.dg/minlocval*.f90 tests are generating conditionals past the infinities. For example: if (x <= +Inf) foo (x); else bar (x); It seems to me that the only possible value for x on the false side is either NAN or undefined (for !HONOR_NANS). gcc/ChangeLog: * range-op-float.cc (build_le): Handle NANs and going past infinity. (build_lt): Same. (build_ge): Same. (build_gt): Same. (foperator_lt::op1_range): Avoid adjustments to range if build_* returned false. (foperator_lt::op2_range): Same. (foperator_le::op1_range): Same. (foperator_le::op2_range): Same. (foperator_gt::op1_range): Same. (foperator_gt::op2_range): Same. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/vrp-float-inf-1.c: New test. Diff: --- gcc/range-op-float.cc | 99 +++++++++++++++++++------ gcc/testsuite/gcc.dg/tree-ssa/vrp-float-inf-1.c | 15 ++++ 2 files changed, 90 insertions(+), 24 deletions(-) diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index 050f07a9867..5fbbaa1fb36 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -224,36 +224,79 @@ frange_drop_ninf (frange &r, tree type) // (X <= VAL) produces the range of [-INF, VAL]. -static void +static bool build_le (frange &r, tree type, const REAL_VALUE_TYPE &val) { + if (real_isnan (&val)) + { + r.set_undefined (); + return false; + } r.set (type, dconstninf, val); + return true; } // (X < VAL) produces the range of [-INF, VAL). -static void +static bool build_lt (frange &r, tree type, const REAL_VALUE_TYPE &val) { + if (real_isnan (&val)) + { + r.set_undefined (); + return false; + } + // < -INF is outside the range. + if (real_isinf (&val, 1)) + { + if (HONOR_NANS (type)) + frange_set_nan (r, type); + else + r.set_undefined (); + return false; + } // Hijack LE because we only support closed intervals. build_le (r, type, val); + return true; } // (X >= VAL) produces the range of [VAL, +INF]. -static void +static bool build_ge (frange &r, tree type, const REAL_VALUE_TYPE &val) { + if (real_isnan (&val)) + { + r.set_undefined (); + return false; + } r.set (type, val, dconstinf); + return true; } // (X > VAL) produces the range of (VAL, +INF]. -static void +static bool build_gt (frange &r, tree type, const REAL_VALUE_TYPE &val) { + if (real_isnan (&val)) + { + r.set_undefined (); + return false; + } + // > +INF is outside the range. + if (real_isinf (&val, 0)) + { + if (HONOR_NANS (type)) + frange_set_nan (r, type); + else + r.set_undefined (); + return false; + } + // Hijack GE because we only support closed intervals. build_ge (r, type, val); + return true; } @@ -520,10 +563,12 @@ foperator_lt::op1_range (frange &r, switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: - build_lt (r, type, op2.upper_bound ()); - r.set_nan (fp_prop::NO); - // x < y implies x is not +INF. - frange_drop_inf (r, type); + if (build_lt (r, type, op2.upper_bound ())) + { + r.set_nan (fp_prop::NO); + // x < y implies x is not +INF. + frange_drop_inf (r, type); + } break; case BRS_FALSE: @@ -546,10 +591,12 @@ foperator_lt::op2_range (frange &r, switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: - build_gt (r, type, op1.lower_bound ()); - r.set_nan (fp_prop::NO); - // x < y implies y is not -INF. - frange_drop_ninf (r, type); + if (build_gt (r, type, op1.lower_bound ())) + { + r.set_nan (fp_prop::NO); + // x < y implies y is not -INF. + frange_drop_ninf (r, type); + } break; case BRS_FALSE: @@ -618,8 +665,8 @@ foperator_le::op1_range (frange &r, switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: - build_le (r, type, op2.upper_bound ()); - r.set_nan (fp_prop::NO); + if (build_le (r, type, op2.upper_bound ())) + r.set_nan (fp_prop::NO); break; case BRS_FALSE: @@ -642,8 +689,8 @@ foperator_le::op2_range (frange &r, switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: - build_ge (r, type, op1.lower_bound ()); - r.set_nan (fp_prop::NO); + if (build_ge (r, type, op1.lower_bound ())) + r.set_nan (fp_prop::NO); break; case BRS_FALSE: @@ -712,10 +759,12 @@ foperator_gt::op1_range (frange &r, switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: - build_gt (r, type, op2.lower_bound ()); - r.set_nan (fp_prop::NO); - // x > y implies x is not -INF. - frange_drop_ninf (r, type); + if (build_gt (r, type, op2.lower_bound ())) + { + r.set_nan (fp_prop::NO); + // x > y implies x is not -INF. + frange_drop_ninf (r, type); + } break; case BRS_FALSE: @@ -738,10 +787,12 @@ foperator_gt::op2_range (frange &r, switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: - build_lt (r, type, op1.upper_bound ()); - r.set_nan (fp_prop::NO); - // x > y implies y is not +INF. - frange_drop_inf (r, type); + if (build_lt (r, type, op1.upper_bound ())) + { + r.set_nan (fp_prop::NO); + // x > y implies y is not +INF. + frange_drop_inf (r, type); + } break; case BRS_FALSE: diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-inf-1.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-inf-1.c new file mode 100644 index 00000000000..1d21cce41e6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-inf-1.c @@ -0,0 +1,15 @@ +// { dg-do compile } +// { dg-options "-O2 -fdump-tree-evrp-details" } + +void foo (); +void bar (double); + +void funky(double f, double g) +{ + if (f <= __builtin_inf ()) + foo (); + else + bar (f); +} + +// { dg-final { scan-tree-dump-not " Inf, Inf" "evrp" } }