From: Andrew Pinski <apinski@marvell.com>
To: <gcc-patches@gcc.gnu.org>
Cc: Andrew Pinski <apinski@marvell.com>
Subject: [PATCH] PHIOPT: Update comment about what the pass now does
Date: Mon, 1 May 2023 09:37:00 -0700 [thread overview]
Message-ID: <20230501163700.797083-1-apinski@marvell.com> (raw)
I noticed I didn't update the comment about how the pass
works after I initially added match_simplify_replacement.
Anyways this updates the comment to be the current state
of the pass.
OK?
gcc/ChangeLog:
* tree-ssa-phiopt.cc: Update comment about
how the transformation are implemented.
---
gcc/tree-ssa-phiopt.cc | 67 +++++++++++++++++++++++-------------------
1 file changed, 36 insertions(+), 31 deletions(-)
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index 147e8f186ce..47ca354fabe 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -3730,31 +3730,55 @@ gate_hoist_loads (void)
}
/* This pass tries to replaces an if-then-else block with an
- assignment. We have four kinds of transformations. Some of these
- transformations are also performed by the ifcvt RTL optimizer.
+ assignment. We have different kinds of transformations.
+ Some of these transformations are also performed by the ifcvt
+ RTL optimizer.
- Conditional Replacement
+ PHI-OPT using Match-and-simplify infrastructure
-----------------------
- This transformation, implemented in match_simplify_replacement,
- replaces
+ The PHI-OPT pass will try to use match-and-simplify infrastructure
+ (gimple_simplify) to do transformations. This is implemented in
+ match_simplify_replacement.
+ The way it works is it replaces:
bb0:
if (cond) goto bb2; else goto bb1;
bb1:
bb2:
- x = PHI <0 (bb1), 1 (bb0), ...>;
+ x = PHI <a (bb1), b (bb0), ...>;
- with
+ with a statement if it gets simplified from `cond ? b : a`.
bb0:
- x' = cond;
- goto bb2;
+ x1 = cond ? b : a;
bb2:
- x = PHI <x' (bb0), ...>;
+ x = PHI <a (bb1), x1 (bb0), ...>;
+ Bb1 might be removed as it becomes unreachable when doing the replacement.
+ Though bb1 does not have to be considered a forwarding basic block from bb0.
+
+ Will try to see if `(!cond) ? a : b` gets simplified (iff !cond simplifies);
+ this is done not to have an explosion of patterns in match.pd.
+ Note bb1 does not need to be completely empty, it can contain
+ one statement which is known not to trap.
- We remove bb1 as it becomes unreachable. This occurs often due to
- gimplification of conditionals.
+ It also can handle the case where we have two forwarding bbs (diamond):
+ bb0:
+ if (cond) goto bb2; else goto bb1;
+ bb1: goto bb3;
+ bb2: goto bb3;
+ bb3:
+ x = PHI <a (bb1), b (bb2), ...>;
+ And that is replaced with a statement if it is simplified
+ from `cond ? b : a`.
+ Again bb1 and bb2 does not have to be completely empty but
+ each can contain one statement which is known not to trap.
+ But in this case bb1/bb2 can only be forwarding basic blocks.
+
+ This fully replaces the old "Conditional Replacement",
+ "ABS Replacement" transformations as they are now
+ implmeneted in match.pd.
+ Some parts of the "MIN/MAX Replacement" are re-implemented in match.pd.
Value Replacement
-----------------
@@ -3796,25 +3820,6 @@ gate_hoist_loads (void)
t3 = t1 & t2;
x = a;
- ABS Replacement
- ---------------
-
- This transformation, implemented in match_simplify_replacement, replaces
-
- bb0:
- if (a >= 0) goto bb2; else goto bb1;
- bb1:
- x = -a;
- bb2:
- x = PHI <x (bb1), a (bb0), ...>;
-
- with
-
- bb0:
- x' = ABS_EXPR< a >;
- bb2:
- x = PHI <x' (bb0), ...>;
-
MIN/MAX Replacement
-------------------
--
2.31.1
next reply other threads:[~2023-05-01 16:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-01 16:37 Andrew Pinski [this message]
2023-05-01 17:41 ` Jeff Law
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230501163700.797083-1-apinski@marvell.com \
--to=apinski@marvell.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).