aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2022-10-24 12:37:25 +0200
committerAldy Hernandez <aldyh@redhat.com>2022-10-24 15:33:43 +0200
commit5bcd92d0d4029f3d1d2eacc0e2bff1685545b74f (patch)
tree68f2f856bf8e594612e3fd2725c0d2d38b167fc5 /gcc
parent178ac530fe67e4f2fc439cc4ce89bc19d571ca31 (diff)
downloadgcc-5bcd92d0d4029f3d1d2eacc0e2bff1685545b74f.zip
gcc-5bcd92d0d4029f3d1d2eacc0e2bff1685545b74f.tar.gz
gcc-5bcd92d0d4029f3d1d2eacc0e2bff1685545b74f.tar.bz2
[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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/range-op-float.cc9
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr107355.c13
2 files changed, 22 insertions, 0 deletions
diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 8777bc70..04208c8 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 0000000..4079634
--- /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;
+}