diff options
author | Sergey Andreenko <seandree@microsoft.com> | 2018-06-08 10:30:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-08 10:30:43 -0700 |
commit | 16169a8738ab7332a0fc2f2e48937997932798ef (patch) | |
tree | 1cecc8bdc87b650a6538c18fb2bc2dcb19a3b7ab /src/jit/assertionprop.cpp | |
parent | 443597ff871c06354894a4efa8cd87cb870ceff0 (diff) | |
download | coreclr-16169a8738ab7332a0fc2f2e48937997932798ef.tar.gz coreclr-16169a8738ab7332a0fc2f2e48937997932798ef.tar.bz2 coreclr-16169a8738ab7332a0fc2f2e48937997932798ef.zip |
Workaround for compiler.hpp (1848) - Assertion failed 'lvRefCnt' (#18292)
* add test
* clean fgRemoveStmt a bit
* fix the issue (more like a workaround).
Diffstat (limited to 'src/jit/assertionprop.cpp')
-rw-r--r-- | src/jit/assertionprop.cpp | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/jit/assertionprop.cpp b/src/jit/assertionprop.cpp index 3d0aa943fe..c445bdb71c 100644 --- a/src/jit/assertionprop.cpp +++ b/src/jit/assertionprop.cpp @@ -4687,7 +4687,24 @@ GenTree* Compiler::optVNConstantPropOnJTrue(BasicBlock* block, GenTree* stmt, Ge // Prepare the tree for replacement so any side effects can be extracted. GenTree* sideEffList = optPrepareTreeForReplacement(test, nullptr); - while (sideEffList) + // Transform the relop's operands to be both zeroes. + ValueNum vnZero = vnStore->VNZeroForType(TYP_INT); + relop->gtOp.gtOp1 = gtNewIconNode(0); + relop->gtOp.gtOp1->gtVNPair = ValueNumPair(vnZero, vnZero); + relop->gtOp.gtOp2 = gtNewIconNode(0); + relop->gtOp.gtOp2->gtVNPair = ValueNumPair(vnZero, vnZero); + + // Update the oper and restore the value numbers. + ValueNum vnCns = relop->gtVNPair.GetConservative(); + ValueNum vnLib = relop->gtVNPair.GetLiberal(); + bool evalsToTrue = (vnStore->CoercedConstantValue<INT64>(vnCns) != 0); + relop->SetOper(evalsToTrue ? GT_EQ : GT_NE); + relop->gtVNPair = ValueNumPair(vnLib, vnCns); + + // Insert side effects back after they were removed from the JTrue stmt. + // It is important not to allow duplicates exist in the IR, that why we delete + // these side effects from the JTrue stmt before insert them back here. + while (sideEffList != nullptr) { GenTree* newStmt; if (sideEffList->OperGet() == GT_COMMA) @@ -4700,24 +4717,11 @@ GenTree* Compiler::optVNConstantPropOnJTrue(BasicBlock* block, GenTree* stmt, Ge newStmt = fgInsertStmtNearEnd(block, sideEffList); sideEffList = nullptr; } - + // fgMorphBlockStmt could potentially affect stmts after the current one, + // for example when it decides to fgRemoveRestOfBlock. fgMorphBlockStmt(block, newStmt->AsStmt() DEBUGARG(__FUNCTION__)); } - // Transform the relop's operands to be both zeroes. - ValueNum vnZero = vnStore->VNZeroForType(TYP_INT); - relop->gtOp.gtOp1 = gtNewIconNode(0); - relop->gtOp.gtOp1->gtVNPair = ValueNumPair(vnZero, vnZero); - relop->gtOp.gtOp2 = gtNewIconNode(0); - relop->gtOp.gtOp2->gtVNPair = ValueNumPair(vnZero, vnZero); - - // Update the oper and restore the value numbers. - ValueNum vnCns = relop->gtVNPair.GetConservative(); - ValueNum vnLib = relop->gtVNPair.GetLiberal(); - bool evalsToTrue = vnStore->CoercedConstantValue<INT64>(vnCns) != 0; - relop->SetOper(evalsToTrue ? GT_EQ : GT_NE); - relop->gtVNPair = ValueNumPair(vnLib, vnCns); - return test; } @@ -4821,6 +4825,8 @@ Compiler::fgWalkResult Compiler::optVNConstantPropCurStmt(BasicBlock* block, Gen // Successful propagation, mark as assertion propagated and skip // sub-tree (with side-effects) visits. + // TODO #18291: at that moment stmt could be already removed from the stmt list. + optAssertionProp_Update(newTree, tree, stmt); JITDUMP("After constant propagation on [%06u]:\n", tree->gtTreeID); |