From: Aldy Hernandez <aldyh@redhat.com>
To: GCC patches <gcc-patches@gcc.gnu.org>
Cc: Andrew MacLeod <amacleod@redhat.com>, Aldy Hernandez <aldyh@redhat.com>
Subject: [COMMITTED] [PR tree-optimization/107732] [range-ops] Handle attempt to abs() negatives.
Date: Thu, 17 Nov 2022 18:44:49 +0100 [thread overview]
Message-ID: <20221117174449.825329-1-aldyh@redhat.com> (raw)
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.
---
gcc/range-op-float.cc | 2 +-
gcc/testsuite/gcc.dg/tree-ssa/pr107732.c | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr107732.c
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;
+ }
+}
--
2.38.1
reply other threads:[~2022-11-17 17:44 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221117174449.825329-1-aldyh@redhat.com \
--to=aldyh@redhat.com \
--cc=amacleod@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).