Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndy Ayers <andya@microsoft.com>2022-10-01 18:16:53 +0300
committerGitHub <noreply@github.com>2022-10-01 18:16:53 +0300
commit65a15783e334039dfc303fa62b22dcc872029257 (patch)
treefccd42ce2b9b3a74861e3de23d85db8dac0335fc /src
parentdc3c200c8f588faf8739c8ccf9e68f5f96289fd9 (diff)
JIT: allow forward sub of QMARK nodes (#76476)
There is often a single-def single use temp consuming a QMARK (which in turn often comes from expansion of `isinst` and friends). This temp assignment tends to stay around and can inhibit redundant branch opts in a number of interesting cases. It may also serve as an attractive nuisance for copy prop. While it would be ideal to generalize RBO to handle assignment side effects, doing so appears quite challenging, as we would need to rewrite possibly large chunks of the SSA and VN graphs. Forward sub eliminates the temp and so clears the way for the existing RBO to remove more branches. Addresses aspects of the "side effect" enhancements for RBO (see #48115).
Diffstat (limited to 'src')
-rw-r--r--src/coreclr/jit/forwardsub.cpp42
1 files changed, 36 insertions, 6 deletions
diff --git a/src/coreclr/jit/forwardsub.cpp b/src/coreclr/jit/forwardsub.cpp
index f4750576d59..7e30100e573 100644
--- a/src/coreclr/jit/forwardsub.cpp
+++ b/src/coreclr/jit/forwardsub.cpp
@@ -434,15 +434,13 @@ bool Compiler::fgForwardSubStatement(Statement* stmt)
GenTree* const rhsNode = rootNode->gtGetOp2();
GenTree* fwdSubNode = rhsNode;
- // Can't substitute a qmark (unless the use is RHS of an assign... could check for this)
// Can't substitute GT_CATCH_ARG.
// Can't substitute GT_LCLHEAP.
//
// Don't substitute a no return call (trips up morph in some cases).
- //
- if (fwdSubNode->OperIs(GT_QMARK, GT_CATCH_ARG, GT_LCLHEAP))
+ if (fwdSubNode->OperIs(GT_CATCH_ARG, GT_LCLHEAP))
{
- JITDUMP(" tree to sub is qmark, catch arg, or lcl heap\n");
+ JITDUMP(" tree to sub is catch arg, or lcl heap\n");
return false;
}
@@ -511,6 +509,40 @@ bool Compiler::fgForwardSubStatement(Statement* stmt)
JITDUMP(" [%06u] is only use of [%06u] (V%02u) ", dspTreeID(fsv.GetNode()), dspTreeID(lhsNode), lclNum);
+ // Qmarks must replace top-level uses. Also, restrict to GT_ASG.
+ // And also to where neither local is normalize on store, otherwise
+ // something downstream may add a cast over the qmark.
+ //
+ GenTree* const nextRootNode = nextStmt->GetRootNode();
+ if (fwdSubNode->OperIs(GT_QMARK))
+ {
+ if ((fsv.GetParentNode() != nextRootNode) || !nextRootNode->OperIs(GT_ASG))
+ {
+ JITDUMP(" can't fwd sub qmark as use is not top level ASG\n");
+ return false;
+ }
+
+ if (varDsc->lvNormalizeOnStore())
+ {
+ JITDUMP(" can't fwd sub qmark as V%02u is normalize on store\n", lclNum);
+ return false;
+ }
+
+ GenTree* const nextRootNodeLHS = nextRootNode->gtGetOp1();
+
+ if (nextRootNodeLHS->OperIs(GT_LCL_VAR))
+ {
+ const unsigned lhsLclNum = nextRootNodeLHS->AsLclVarCommon()->GetLclNum();
+ LclVarDsc* const lhsVarDsc = lvaGetDesc(lhsLclNum);
+
+ if (lhsVarDsc->lvNormalizeOnStore())
+ {
+ JITDUMP(" can't fwd sub qmark as V%02u is normalize on store\n", lhsLclNum);
+ return false;
+ }
+ }
+ }
+
// If next statement already has a large tree, hold off
// on making it even larger.
//
@@ -527,8 +559,6 @@ bool Compiler::fgForwardSubStatement(Statement* stmt)
// Next statement seems suitable.
// See if we can forward sub without changing semantics.
//
- GenTree* const nextRootNode = nextStmt->GetRootNode();
-
// Bail if types disagree.
// Might be able to tolerate these by retyping.
//