From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2136) id B18E73853D55; Thu, 17 Nov 2022 17:43:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B18E73853D55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668707003; bh=uQMY035yCzYWQeyaTpGo0DzTmj8ZUtovnJghyEqN0Js=; h=From:To:Subject:Date:From; b=yFOJZ5/59fIJItXYjggTDPEe2SysxkoiCStNXLy7hgGxw48je4aEyyxumqru1rt/N 7J0BlZFHKiA9gtOyOoeFKmYkqYLGL9OS3oz9iX8O+NE1AwPr0rAtmpurkFcrjMlLeG jK6AT2ytY+V0vTeM3le0tf16vVRRbEQSpjSUrHtY= 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-4131] [PR tree-optimization/107732] [range-ops] Handle attempt to abs() negatives. X-Act-Checkin: gcc X-Git-Author: Aldy Hernandez X-Git-Refname: refs/heads/master X-Git-Oldrev: f9ed1d24ee46f5ca759c35a1f51fa163d7529ea6 X-Git-Newrev: 4e306222f442f8d4c6fc6da997ab756a5e43e36e Message-Id: <20221117174323.B18E73853D55@sourceware.org> Date: Thu, 17 Nov 2022 17:43:23 +0000 (GMT) List-Id: https://gcc.gnu.org/g:4e306222f442f8d4c6fc6da997ab756a5e43e36e commit r13-4131-g4e306222f442f8d4c6fc6da997ab756a5e43e36e Author: Aldy Hernandez Date: Thu Nov 17 16:47:17 2022 +0100 [PR tree-optimization/107732] [range-ops] Handle attempt to abs() negatives. The threader is creating a scenario where we are trying to solve: [NEGATIVES] = abs(x) While solving this we have an intermediate value of UNDEFINED because we have no positive numbers. But then we try to union the negative pair to the final result by querying the bounds. Since neither UNDEFINED nor NAN have bounds, they need to be specially handled. PR tree-optimization/107732 gcc/ChangeLog: * range-op-float.cc (foperator_abs::op1_range): Early exit when result is undefined. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr107732.c: New test. Diff: --- gcc/range-op-float.cc | 2 +- gcc/testsuite/gcc.dg/tree-ssa/pr107732.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index adb0cbaa6d5..ee88511eba0 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -1407,7 +1407,7 @@ foperator_abs::op1_range (frange &r, tree type, neg_nan.set_nan (type, true); r.union_ (neg_nan); } - if (r.known_isnan ()) + if (r.known_isnan () || r.undefined_p ()) return true; // Then add the negative of each pair: // ABS(op1) = [5,20] would yield op1 => [-20,-5][5,20]. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107732.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107732.c new file mode 100644 index 00000000000..b216f38db0e --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107732.c @@ -0,0 +1,13 @@ +// { dg-do compile } +// { dg-options "-O2" } + +double sqrt(double); +double a, b, c; +void d() { + for (;;) { + c = __builtin_fabs(a); + sqrt(c); + if (a) + a = b; + } +}