public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-3720] MATCH: Add `~MAX(~X, Y)` pattern: [PR96694]
@ 2023-09-05 20:57 Andrew Pinski
  0 siblings, 0 replies; only message in thread
From: Andrew Pinski @ 2023-09-05 20:57 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:244d1321340116b7780e78096356f69662fd0e18

commit r14-3720-g244d1321340116b7780e78096356f69662fd0e18
Author: Andrew Pinski <apinski@marvell.com>
Date:   Sun Sep 3 18:37:51 2023 +0000

    MATCH: Add `~MAX(~X, Y)` pattern: [PR96694]
    
    This adds `~MAX(~X, Y)` and `~MIN(~X, Y)` patterns
    that are like the `~(~a & b)` and `~(~a | b)` patterns
    and allows to reduce the number of ~ by 1.
    
    OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
    
            PR tree-optimization/96694
    
    gcc/ChangeLog:
    
            * match.pd (`~MAX(~X, Y)`, `~MIN(~X, Y)`): New patterns.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/tree-ssa/minmax-24.c: New test.

Diff:
---
 gcc/match.pd                              |  7 ++++++-
 gcc/testsuite/gcc.dg/tree-ssa/minmax-24.c | 31 +++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index da68286e0857..bccd227b7352 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3864,7 +3864,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  maxmin (max min)
  (simplify
   (minmax (bit_not:s@2 @0) (bit_not:s@3 @1))
-  (bit_not (maxmin @0 @1))))
+  (bit_not (maxmin @0 @1)))
+/* ~MAX(~X, Y) --> MIN(X, ~Y) */
+/* ~MIN(~X, Y) --> MAX(X, ~Y) */
+ (simplify
+  (bit_not (minmax:cs (bit_not @0) @1))
+  (maxmin @0 (bit_not @1))))
 
 /* MIN (X, Y) == X -> X <= Y  */
 (for minmax (min min max max)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-24.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-24.c
new file mode 100644
index 000000000000..2b21f94eecfc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-24.c
@@ -0,0 +1,31 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* PR tree-optimization/96694 */
+
+static inline int min(int a, int b)
+{
+  return a < b ? a : b;
+}
+
+static inline int max(int a, int b)
+{
+  return a > b ? a : b;
+}
+
+int max_not(int x, int y)
+{
+  return ~max(~x, y); // min (x, ~y)
+}
+/* { dg-final { scan-tree-dump "~y_\[0-9\]+.D.;" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "~x_\[0-9\]+.D.;" "optimized" } } */
+/* { dg-final { scan-tree-dump "MIN_EXPR <x_\[0-9\]+.D., _\[0-9\]+>|MIN_EXPR <_\[0-9\]+, x_\[0-9\]+.D.>" "optimized" } } */
+
+int min_not(int c, int d)
+{
+  return ~min(~c, d); // max (c, ~d)
+}
+/* { dg-final { scan-tree-dump "~d_\[0-9\]+.D.;" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "~c_\[0-9\]+.D.;" "optimized" } } */
+/* { dg-final { scan-tree-dump "MAX_EXPR <c_\[0-9\]+.D., _\[0-9\]+>|MIN_EXPR <_\[0-9\]+, c_\[0-9\]+.D.>" "optimized" } } */
+
+/* { dg-final { scan-tree-dump-times "~" 2 "optimized" } } */

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

only message in thread, other threads:[~2023-09-05 20:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-05 20:57 [gcc r14-3720] MATCH: Add `~MAX(~X, Y)` pattern: [PR96694] Andrew Pinski

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