diff options
author | Andrew Pinski <apinski@marvell.com> | 2023-07-20 17:36:29 -0700 |
---|---|---|
committer | Andrew Pinski <apinski@marvell.com> | 2023-07-21 00:33:39 -0700 |
commit | 6d449531a60b56ed0f4aeb640aa9e46e4ec35208 (patch) | |
tree | 0fd483bea3519274c60f081359221a2899eaa399 /gcc | |
parent | 9a8782e63790842d1bfa03e12eecf73c4aaeb1f8 (diff) | |
download | gcc-6d449531a60b56ed0f4aeb640aa9e46e4ec35208.zip gcc-6d449531a60b56ed0f4aeb640aa9e46e4ec35208.tar.gz gcc-6d449531a60b56ed0f4aeb640aa9e46e4ec35208.tar.bz2 |
MATCH: Add Max<Max<a,b>,a> -> Max<a,b> simplifcation
This adds a simple match pattern to simplify
`max<max<a,b>,a>` to `max<a,b>`. Reassociation handles
this already (r0-77700-ge969dbde29bfd396259357) but
seems like we should be able to handle this even before
reassociation.
This fixes part of PR tree-optimization/80574 but more
work is needed fix it the rest of the way. The original
testcase there is fixed but the RTL level is what fixes
it the rest of the way.
OK? Bootstrapped and tested on x86_64-linux-gnu.
gcc/ChangeLog:
* match.pd (minmax<minmax<a,b>,a>->minmax<a,b>): New
transformation.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/reassoc-12.c: Disable all of
the passes that enables match-and-simplify.
* gcc.dg/tree-ssa/minmax-23.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/match.pd | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/minmax-23.c | 22 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/reassoc-12.c | 3 |
3 files changed, 29 insertions, 2 deletions
diff --git a/gcc/match.pd b/gcc/match.pd index 4dfe926..bfd15d6 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3503,7 +3503,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (for minmax (min max) (simplify (minmax @0 @0) - @0)) + @0) +/* max(max(x,y),x) -> max(x,y) */ + (simplify + (minmax:c (minmax:c@2 @0 @1) @0) + @2)) /* For fmin() and fmax(), skip folding when both are sNaN. */ (for minmax (FMIN_ALL FMAX_ALL) (simplify diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-23.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-23.c new file mode 100644 index 0000000..0b7e51b --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-23.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fno-tree-reassoc -fdump-tree-optimized" } */ + + +#define MAX(a,b) (a)>=(b) ? (a) : (b) + +#define MIN(a,b) (a)<=(b) ? (a) : (b) + +int test1(int a, int b) +{ + int d = MAX(a,b); + return MAX(a,d); +} +int test2(int a, int b) +{ + int d = MIN(a,b); + return MIN(a,d); +} + +/* We should be optimize these two functions even without reassociation. */ +/* { dg-final { scan-tree-dump-times "MAX_EXPR " 1 "optimized"} } */ +/* { dg-final { scan-tree-dump-times "MIN_EXPR " 1 "optimized"} } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-12.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-12.c index 9a138eb..2238147 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-12.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-12.c @@ -1,5 +1,6 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-reassoc1-details" } */ +/* Match-and-simplify can handle now MAX<MAX<a,b>,a>->MAX<a,b>, disable all of the passes that uses that. */ +/* { dg-options "-O1 -fdump-tree-reassoc1-details -fno-tree-ccp -fno-tree-ccp -fno-tree-forwprop -fno-tree-fre" } */ int f(int a, int b) { /* MAX_EXPR <a, a> should cause it to be equivalent to a. */ |