public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5529] PR middle-end/103406: Check for Inf before simplifying x-x.
@ 2021-11-25 19:04 Roger Sayle
  0 siblings, 0 replies; only message in thread
From: Roger Sayle @ 2021-11-25 19:04 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6ea5fb3cc7f3cc9b731d72183c66c23543876f5a

commit r12-5529-g6ea5fb3cc7f3cc9b731d72183c66c23543876f5a
Author: Roger Sayle <roger@nextmovesoftware.com>
Date:   Thu Nov 25 19:02:06 2021 +0000

    PR middle-end/103406: Check for Inf before simplifying x-x.
    
    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.

Diff:
---
 gcc/match.pd                    |  4 +++-
 gcc/testsuite/gcc.dg/pr103406.c | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 39fd77ddc4a..fbb5a5a1eeb 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -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
index 00000000000..9c7b83b2e9e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr103406.c
@@ -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" } } */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-25 19:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-25 19:04 [gcc r12-5529] PR middle-end/103406: Check for Inf before simplifying x-x Roger Sayle

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).