public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-337] MATCH: Add patterns from phiopt's minmax_replacement
@ 2023-04-28 14:27 Andrew Pinski
0 siblings, 0 replies; only message in thread
From: Andrew Pinski @ 2023-04-28 14:27 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:c43819a9b4cdaa7359e55f942f20d2ce6fd49da6
commit r14-337-gc43819a9b4cdaa7359e55f942f20d2ce6fd49da6
Author: Andrew Pinski <apinski@marvell.com>
Date: Sat Apr 1 05:13:31 2023 +0000
MATCH: Add patterns from phiopt's minmax_replacement
This adds a few patterns from phiopt's minmax_replacement
for (A CMP B) ? MIN/MAX<A, C> : MIN/MAX <B, C> .
It is progress to remove minmax_replacement from phiopt.
There are still some more cases dealing with constants on the
edges (0/INT_MAX) to handle in match.
OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
gcc/ChangeLog:
* match.pd: Add patterns for
"(A CMP B) ? MIN/MAX<A, C> : MIN/MAX <B, C>".
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/minmax-16.c: Update testcase slightly.
* gcc.dg/tree-ssa/split-path-1.c: Also disable tree-loop-if-convert
as that now does the combining.
Diff:
---
gcc/match.pd | 16 ++++++++++++++++
gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c | 10 ++++++++--
gcc/testsuite/gcc.dg/tree-ssa/split-path-1.c | 3 ++-
3 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/gcc/match.pd b/gcc/match.pd
index fad337a9697..31fe5093218 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4843,6 +4843,22 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(convert @c0))))))))
#endif
+/* These was part of minmax phiopt. */
+/* Optimize (a CMP b) ? minmax<a, c> : minmax<b, c>
+ to minmax<min/max<a, b>, c> */
+(for minmax (min max)
+ (for cmp (lt le gt ge)
+ (simplify
+ (cond (cmp @1 @3) (minmax:c @1 @4) (minmax:c @2 @4))
+ (with
+ {
+ tree_code code = minmax_from_comparison (cmp, @1, @2, @1, @3);
+ }
+ (if (code == MIN_EXPR)
+ (minmax (min @1 @2) @4)
+ (if (code == MAX_EXPR)
+ (minmax (max @1 @2) @4)))))))
+
/* X != C1 ? -X : C2 simplifies to -X when -C1 == C2. */
(simplify
(cond (ne @0 INTEGER_CST@1) (negate@3 @0) INTEGER_CST@2)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c
index 4febd092d83..623b12b3f74 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c
@@ -1,5 +1,5 @@
/* { dg-do run } */
-/* { dg-options "-O -fdump-tree-phiopt -g" } */
+/* { dg-options "-O -fdump-tree-phiopt -fdump-tree-optimized -g" } */
#include <stdint.h>
@@ -25,5 +25,11 @@ main (void)
return 0;
}
-/* { dg-final { scan-tree-dump-times "MIN_EXPR" 3 "phiopt1" } } */
+/* After phiopt1, there really should be only 3 MIN_EXPR in the IR (including debug statements).
+ But the way phiopt does not cleanup the CFG all the time, the PHI might still reference the
+ alternative bb's moved statement.
+ Note in the end, we do dce the statement and other debug statements to end up with only 2 MIN_EXPR.
+ So check that too. */
+/* { dg-final { scan-tree-dump-times "MIN_EXPR" 4 "phiopt1" } } */
+/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "optimized" } } */
/* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "phiopt1" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/split-path-1.c b/gcc/testsuite/gcc.dg/tree-ssa/split-path-1.c
index 902dde44a50..b670dee8d10 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/split-path-1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/split-path-1.c
@@ -1,5 +1,6 @@
/* { dg-do run } */
-/* { dg-options "-O2 -fsplit-paths -fdump-tree-split-paths-details --param max-jump-thread-duplication-stmts=20 -fno-ssa-phiopt" } */
+/* Note both PHI-OPT and the loop if conversion pass converts the inner if to be branchless using min/max. */
+/* { dg-options "-O2 -fsplit-paths -fdump-tree-split-paths-details --param max-jump-thread-duplication-stmts=20 -fno-ssa-phiopt -fno-tree-loop-if-convert" } */
#include <stdio.h>
#include <stdlib.h>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-04-28 14:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-28 14:27 [gcc r14-337] MATCH: Add patterns from phiopt's minmax_replacement 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).