]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[PR tree-optimization/107732] [range-ops] Handle attempt to abs() negatives.
authorAldy Hernandez <aldyh@redhat.com>
Thu, 17 Nov 2022 15:47:17 +0000 (16:47 +0100)
committerAldy Hernandez <aldyh@redhat.com>
Thu, 17 Nov 2022 17:42:56 +0000 (18:42 +0100)
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
gcc/testsuite/gcc.dg/tree-ssa/pr107732.c [new file with mode: 0644]

index adb0cbaa6d58e8a7397f07560c4ccca1f825ea66..ee88511eba0b4b02425c936b38a3406d97426bae 100644 (file)
@@ -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 (file)
index 0000000..b216f38
--- /dev/null
@@ -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;
+  }
+}