From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2136) id CADCA385840A; Mon, 24 Oct 2022 13:33:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CADCA385840A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666618437; bh=K+U4gIRAo/JKniAAYb1SnA/xWIJbs+ouJE7nACVZdQ4=; h=From:To:Subject:Date:From; b=odztfGjRy9P/2GMyfxR1aDYDnpTtsUsmoJgmJm+swAeASgsaPHW7FI7C0OvgzAcPX UQq1+619ZAWMgZgiXS2QARJvltDs+FORSddHR3lMGaDn8z4eA8EQHMvZe01ZouiCTh XvPCwv5mdpDtCK8CeJ/8Nnnc2T764WNw4L0fcgcQ= 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-3456] [PR tree-optimization/107355] Handle NANs in abs range-op entry. X-Act-Checkin: gcc X-Git-Author: Aldy Hernandez X-Git-Refname: refs/heads/master X-Git-Oldrev: 178ac530fe67e4f2fc439cc4ce89bc19d571ca31 X-Git-Newrev: 5bcd92d0d4029f3d1d2eacc0e2bff1685545b74f Message-Id: <20221024133357.CADCA385840A@sourceware.org> Date: Mon, 24 Oct 2022 13:33:57 +0000 (GMT) List-Id: https://gcc.gnu.org/g:5bcd92d0d4029f3d1d2eacc0e2bff1685545b74f commit r13-3456-g5bcd92d0d4029f3d1d2eacc0e2bff1685545b74f Author: Aldy Hernandez Date: Mon Oct 24 12:37:25 2022 +0200 [PR tree-optimization/107355] Handle NANs in abs range-op entry. The problem here is that the threader is coming up with a path where the only valid result is a NAN. When the abs op1_range entry is trying to add the negative posibility, it attempts to get the bounds of the working range. NANs don't have bounds so they need to be special cased. PR tree-optimization/107355 gcc/ChangeLog: * range-op-float.cc (foperator_abs::op1_range): Handle NAN. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr107355.c: New test. Diff: --- gcc/range-op-float.cc | 9 +++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr107355.c | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index 8777bc70d71..04208c88dd1 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -1269,6 +1269,15 @@ foperator_abs::op1_range (frange &r, tree type, positives.update_nan (/*sign=*/false); positives.intersect (lhs); r = positives; + // Add -NAN if relevant. + if (r.maybe_isnan ()) + { + frange neg_nan; + neg_nan.set_nan (type, true); + r.union_ (neg_nan); + } + if (r.known_isnan ()) + return true; // Then add the negative of each pair: // ABS(op1) = [5,20] would yield op1 => [-20,-5][5,20]. r.union_ (frange (type, diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107355.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107355.c new file mode 100644 index 00000000000..40796344bfb --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107355.c @@ -0,0 +1,13 @@ +// { dg-do compile } +// { dg-options "-O2 -fno-guess-branch-probability -fsanitize=float-cast-overflow --param=max-jump-thread-duplication-stmts=240" } + +float f; + +void +foo (double d) +{ + (char) f; + long l = __builtin_fabs (d); + (char) f; + (long) d; +}