public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR middle-end/103406: Check for Inf before simplifying x-x.
@ 2021-11-25 11:29 Roger Sayle
  2021-11-25 12:02 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Roger Sayle @ 2021-11-25 11:29 UTC (permalink / raw)
  To: 'GCC Patches'

[-- Attachment #1: Type: text/plain, Size: 948 bytes --]


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.

This patch doesn't address the issue of NaN signedness from binary
arithmetic operations, just the regression.

This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
and make -k check with no new failures.  Ok for mainline?


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.

Thanks in advance (and sorry for the inconvenience),
Roger
--


[-- Attachment #2: patchz.txt --]
[-- Type: text/plain, Size: 980 bytes --]

diff --git a/gcc/match.pd b/gcc/match.pd
index f059b47..d28dfe2 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -232,7 +232,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 0000000..9c7b83b
--- /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] 2+ messages in thread

* Re: [PATCH] PR middle-end/103406: Check for Inf before simplifying x-x.
  2021-11-25 11:29 [PATCH] PR middle-end/103406: Check for Inf before simplifying x-x Roger Sayle
@ 2021-11-25 12:02 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2021-11-25 12:02 UTC (permalink / raw)
  To: Roger Sayle; +Cc: GCC Patches

On Thu, Nov 25, 2021 at 12:30 PM Roger Sayle <roger@nextmovesoftware.com> wrote:
>
>
> 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.
>
> This patch doesn't address the issue of NaN signedness from binary
> arithmetic operations, just the regression.
>
> This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
> and make -k check with no new failures.  Ok for mainline?

OK.

Thanks,
Richard.

>
> 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.
>
> Thanks in advance (and sorry for the inconvenience),
> Roger
> --
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-25 12:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-25 11:29 [PATCH] PR middle-end/103406: Check for Inf before simplifying x-x Roger Sayle
2021-11-25 12:02 ` Richard Biener

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