aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2022-11-17 16:47:17 +0100
committerAldy Hernandez <aldyh@redhat.com>2022-11-17 18:42:56 +0100
commit4e306222f442f8d4c6fc6da997ab756a5e43e36e (patch)
tree7f97f1642131f7f6b94aba3359a887afa5482dc1 /gcc
parentf9ed1d24ee46f5ca759c35a1f51fa163d7529ea6 (diff)
downloadgcc-4e306222f442f8d4c6fc6da997ab756a5e43e36e.zip
gcc-4e306222f442f8d4c6fc6da997ab756a5e43e36e.tar.gz
gcc-4e306222f442f8d4c6fc6da997ab756a5e43e36e.tar.bz2
[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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/range-op-float.cc2
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr107732.c13
2 files changed, 14 insertions, 1 deletions
diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index adb0cba..ee88511 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 0000000..b216f38
--- /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;
+ }
+}