public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5458] Re: [PATCH] PR tree-optimization/96779 Adding a missing pattern to match.pd
@ 2021-11-23  0:48 Jeff Law
  0 siblings, 0 replies; only message in thread
From: Jeff Law @ 2021-11-23  0:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:e888bea2384a0d8d29a6545c4f57f41cb49df0a6

commit r12-5458-ge888bea2384a0d8d29a6545c4f57f41cb49df0a6
Author: Navid Rahimi <navidrahimi@microsoft.com>
Date:   Mon Nov 22 19:46:17 2021 -0500

    Re: [PATCH] PR tree-optimization/96779 Adding a missing pattern to match.pd
    
            PR tree-optimization/96779
    gcc/
            * match.pd (-x == x) -> (x == 0): New optimization.
    
    gcc/testsuite
            * gcc.dg/tree-ssa/pr96779.c: Testcase for this optimization.
            * gcc.dg/tree-ssa/pr96779-disabled.c: Testcase for this optimization
            when -fwrapv passed.

Diff:
---
 gcc/match.pd                                     |  8 +++
 gcc/testsuite/gcc.dg/tree-ssa/pr96779-disabled.c | 84 ++++++++++++++++++++++++
 gcc/testsuite/gcc.dg/tree-ssa/pr96779.c          | 79 ++++++++++++++++++++++
 3 files changed, 171 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index f059b477f58..5d71a4f907c 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -242,6 +242,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (mult @0 integer_zerop@1)
  @1)
 
+/* -x == x -> x == 0 */
+(for cmp (eq ne)
+ (simplify
+  (cmp:c @0 (negate @0))
+   (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
+        && !TYPE_OVERFLOW_WRAPS (TREE_TYPE(@0)))
+    (cmp @0 { build_zero_cst (TREE_TYPE(@0)); }))))
+
 /* Maybe fold x * 0 to 0.  The expressions aren't the same
    when x is NaN, since x * 0 is also NaN.  Nor are they the
    same in modes with signed zeros, since multiplying a
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr96779-disabled.c b/gcc/testsuite/gcc.dg/tree-ssa/pr96779-disabled.c
new file mode 100644
index 00000000000..205133d8e0c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr96779-disabled.c
@@ -0,0 +1,84 @@
+/* PR tree-optimization/96779 */
+/* { dg-do run } */
+/* { dg-options "-O -fdump-tree-optimized -fwrapv" } */
+
+#include <stdbool.h>
+
+bool __attribute__ ((noipa)) f_func(int a)
+{
+    return -a == a;
+}
+
+bool __attribute__ ((noipa)) g_func(unsigned int a)
+{
+    return -a == a;
+}
+
+bool __attribute__ ((noipa)) h_func(short a)
+{
+    return -a == a;
+}
+
+bool __attribute__ ((noipa)) k_func(long a)
+{
+    return -a == a;
+}
+
+int
+main (void)
+{
+  // few randomly generated test cases
+  if (f_func (71856034))
+    {
+      __builtin_abort ();
+    }
+  if (g_func (71856034))
+    {
+      __builtin_abort ();
+    }
+  if (h_func (1744))
+    {
+      __builtin_abort ();
+    }
+  if (k_func (68268386))
+    {
+      __builtin_abort ();
+    }
+  if (f_func (-112237))
+    {
+      __builtin_abort ();
+    }
+  if (g_func (-787116))
+    {
+      __builtin_abort ();
+    }
+  if (h_func (-863))
+    {
+      __builtin_abort ();
+    }
+  if (k_func (-787116))
+    {
+      __builtin_abort ();
+    }
+  if (!f_func (0))
+    {
+      __builtin_abort ();
+    }
+  if (!g_func (0))
+    {
+      __builtin_abort ();
+    }
+  if (!h_func (0))
+    {
+      __builtin_abort ();
+    }
+  if (!k_func (0))
+    {
+      __builtin_abort ();
+    }
+
+  return 0;
+}
+
+/* Verify that we have *not* transfered "= -" pattern in any of those functions.  */
+/* { dg-final { scan-tree-dump-times "= -" 4 "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr96779.c b/gcc/testsuite/gcc.dg/tree-ssa/pr96779.c
new file mode 100644
index 00000000000..0d46e8eeb15
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr96779.c
@@ -0,0 +1,79 @@
+/* PR tree-optimization/96779 */
+/* { dg-do run } */
+/* { dg-options "-O -fdump-tree-optimized" } */
+
+#include <stdbool.h>
+
+bool __attribute__ ((noipa)) f_func(int a)
+{
+    return -a == a;
+}
+
+bool __attribute__ ((noipa)) h_func(short a)
+{
+    return -a == a;
+}
+
+bool __attribute__ ((noipa)) k_func(long a)
+{
+    return -a == a;
+}
+
+int
+main (void)
+{
+  // few randomly generated test cases
+  if (f_func (71856034))
+    {
+      __builtin_abort ();
+    }
+  if (f_func (71856034))
+    {
+      __builtin_abort ();
+    }
+  if (h_func (1744))
+    {
+      __builtin_abort ();
+    }
+  if (k_func (68268386))
+    {
+      __builtin_abort ();
+    }
+  if (f_func (-112237))
+    {
+      __builtin_abort ();
+    }
+  if (f_func (-787116))
+    {
+      __builtin_abort ();
+    }
+  if (h_func (-863))
+    {
+      __builtin_abort ();
+    }
+  if (k_func (-787116))
+    {
+      __builtin_abort ();
+    }
+  if (!f_func (0))
+    {
+      __builtin_abort ();
+    }
+  if (!f_func (0))
+    {
+      __builtin_abort ();
+    }
+  if (!h_func (0))
+    {
+      __builtin_abort ();
+    }
+  if (!k_func (0))
+    {
+      __builtin_abort ();
+    }
+
+  return 0;
+}
+
+/* Verify that we transfered to "= -" pattern from "_2 = -_1;".  */
+/* { dg-final { scan-tree-dump-not "= -" "optimized" } } */


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

only message in thread, other threads:[~2021-11-23  0:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-23  0:48 [gcc r12-5458] Re: [PATCH] PR tree-optimization/96779 Adding a missing pattern to match.pd Jeff Law

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