From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id 91E77385840F; Fri, 28 Apr 2023 14:27:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 91E77385840F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682692055; bh=0xpTg3IbQ5z32XAMnhBq0uTeML4QI87hwEFLiFXJNPs=; h=From:To:Subject:Date:From; b=vQYn5OynN5KDk4qm5yb2ukSQumxtR9cbWEAudmGxCMrCPO/MMP9nNJi2vSoUfzoZP W8PGDH0QcYuHl7OqKJy29pNVPQmxawVMi569LCYntZEwnEQIRQuFby6lD8SF+OFXUE didh2+/HIPnwPPRH3j1h30qBS8NBDuNd6+nfaRDw= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Pinski To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-337] MATCH: Add patterns from phiopt's minmax_replacement X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/trunk X-Git-Oldrev: b9b30dbaabc8076d9265cf685f45d3b0072a09df X-Git-Newrev: c43819a9b4cdaa7359e55f942f20d2ce6fd49da6 Message-Id: <20230428142735.91E77385840F@sourceware.org> Date: Fri, 28 Apr 2023 14:27:35 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c43819a9b4cdaa7359e55f942f20d2ce6fd49da6 commit r14-337-gc43819a9b4cdaa7359e55f942f20d2ce6fd49da6 Author: Andrew Pinski 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 : MIN/MAX . 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 : MIN/MAX ". 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 : minmax + to minmax, 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 @@ -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 #include