summaryrefslogtreecommitdiff
path: root/src/jit/earlyprop.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/jit/earlyprop.cpp')
-rw-r--r--src/jit/earlyprop.cpp42
1 files changed, 20 insertions, 22 deletions
diff --git a/src/jit/earlyprop.cpp b/src/jit/earlyprop.cpp
index 70d1012aa0..51de631d19 100644
--- a/src/jit/earlyprop.cpp
+++ b/src/jit/earlyprop.cpp
@@ -189,8 +189,7 @@ void Compiler::optEarlyProp()
// Walk the stmt tree in linear order to rewrite any array length reference with a
// constant array length.
- bool isRewritten = false;
- bool bbHasNullCheck = (block->bbFlags & BBF_HAS_NULLCHECK) != 0;
+ bool isRewritten = false;
for (GenTreePtr tree = stmt->gtStmt.gtStmtList; tree != nullptr; tree = tree->gtNext)
{
if (optEarlyPropRewriteTree(tree))
@@ -238,12 +237,8 @@ bool Compiler::optEarlyPropRewriteTree(GenTreePtr tree)
objectRefPtr = tree->gtOp.gtOp1;
propKind = optPropKind::OPK_ARRAYLEN;
}
- else if ((tree->OperGet() == GT_IND) && !varTypeIsStruct(tree))
+ else if (tree->OperIsIndir())
{
- // TODO-1stClassStructs: The above condition should apply equally to all indirections,
- // but previously the implicit indirections due to a struct assignment were not
- // considered, so we are currently limiting it to non-structs to preserve existing
- // behavior.
// optFoldNullCheck takes care of updating statement info if a null check is removed.
optFoldNullCheck(tree);
@@ -259,7 +254,7 @@ bool Compiler::optEarlyPropRewriteTree(GenTreePtr tree)
return false;
}
- objectRefPtr = tree->gtOp.gtOp1;
+ objectRefPtr = tree->AsIndir()->Addr();
propKind = optPropKind::OPK_OBJ_GETTYPE;
}
else
@@ -511,15 +506,23 @@ void Compiler::optFoldNullCheck(GenTreePtr tree)
// |
// x
- assert(tree->OperGet() == GT_IND);
- if (tree->gtGetOp1()->OperGet() == GT_LCL_VAR)
+ if ((compCurBB->bbFlags & BBF_HAS_NULLCHECK) == 0)
+ {
+ return;
+ }
+
+ assert(tree->OperIsIndir());
+
+ GenTree* const addr = tree->AsIndir()->Addr();
+ if (addr->OperGet() == GT_LCL_VAR)
{
// Check if we have the pattern above and find the nullcheck node if we do.
// Find the definition of the indirected local (x in the picture)
- GenTreePtr indLocalTree = tree->gtGetOp1();
- unsigned lclNum = indLocalTree->AsLclVarCommon()->GetLclNum();
- unsigned ssaNum = indLocalTree->AsLclVarCommon()->GetSsaNum();
+ GenTreeLclVarCommon* const lclVarNode = addr->AsLclVarCommon();
+
+ const unsigned lclNum = lclVarNode->GetLclNum();
+ const unsigned ssaNum = lclVarNode->GetSsaNum();
if (ssaNum != SsaConfig::RESERVED_SSA_NUM)
{
@@ -557,7 +560,7 @@ void Compiler::optFoldNullCheck(GenTreePtr tree)
{
// Walk from the use to the def in reverse execution order to see
// if any nodes have unsafe side effects.
- GenTreePtr currentTree = indLocalTree->gtPrev;
+ GenTreePtr currentTree = lclVarNode->gtPrev;
bool isInsideTry = compCurBB->hasTryIndex();
bool canRemoveNullCheck = true;
const unsigned maxNodesWalked = 25;
@@ -612,13 +615,8 @@ void Compiler::optFoldNullCheck(GenTreePtr tree)
additionNode->gtFlags & (GTF_EXCEPT | GTF_DONT_CSE);
// Re-morph the statement.
- fgMorphBlockStmt(compCurBB, curStmt DEBUGARG("optFoldNullCheck"));
-
- // Recalculate the gtCostSz, etc...
- gtSetStmtInfo(curStmt);
-
- // Re-thread the nodes
- fgSetStmtSeq(curStmt);
+ fgMorphBlockStmt(compCurBB,
+ curStmt->AsStmt() DEBUGARG("optFoldNullCheck"));
}
}
}
@@ -668,4 +666,4 @@ bool Compiler::optCanMoveNullCheckPastTree(GenTreePtr tree, bool isInsideTry)
}
}
return result;
-} \ No newline at end of file
+}