]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR middle-end/103406: Check for Inf before simplifying x-x.
authorRoger Sayle <roger@nextmovesoftware.com>
Thu, 25 Nov 2021 19:02:06 +0000 (19:02 +0000)
committerRoger Sayle <roger@nextmovesoftware.com>
Thu, 25 Nov 2021 19:02:06 +0000 (19:02 +0000)
This is a simple one line fix to the regression PR middle-end/103406,
where x - x is being folded to 0.0 even when x is +Inf or -Inf.
In GCC 11 and previously, we'd check whether the type honored NaNs
(which implicitly covered the case where the type honors infinities),
but my patch to test whether the operand could potentially be NaN
failed to also check whether the operand could potentially be Inf.

2021-11-25  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
PR middle-end/103406
* match.pd (minus @0 @0): Check tree_expr_maybe_infinite_p.

gcc/testsuite/ChangeLog
PR middle-end/103406
* gcc.dg/pr103406.c: New test case.

gcc/match.pd
gcc/testsuite/gcc.dg/pr103406.c [new file with mode: 0644]

index 39fd77ddc4a1cdeae74f9f1597289004308b83cc..fbb5a5a1eeb98d114589ed3435313b135e9e44a4 100644 (file)
@@ -233,7 +233,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
    is volatile.  */
 (simplify
  (minus @0 @0)
- (if (!FLOAT_TYPE_P (type) || !tree_expr_maybe_nan_p (@0))
+ (if (!FLOAT_TYPE_P (type)
+      || (!tree_expr_maybe_nan_p (@0)
+         && !tree_expr_maybe_infinite_p (@0)))
   { build_zero_cst (type); }))
 (simplify
  (pointer_diff @@0 @0)
diff --git a/gcc/testsuite/gcc.dg/pr103406.c b/gcc/testsuite/gcc.dg/pr103406.c
new file mode 100644 (file)
index 0000000..9c7b83b
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#define HUGE __DBL_MAX__
+#define INF (HUGE + HUGE)
+#define NAN (INF - INF)
+
+double foo() {
+  double x = -NAN;
+  double y = NAN;
+  return x + y;
+}
+
+/* { dg-final { scan-tree-dump-not "return 0\.0" "optimized" } } */