diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index 8572b608e491dd..079734d5b4a5a1 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -1739,6 +1739,7 @@ void CodeGen::genGenerateMachineCode() { compiler->opts.disAsm = true; } + compiler->compCurBB = compiler->fgFirstBB; if (compiler->opts.disAsm) { diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 0272b91d73877c..565d885bca9dd7 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -5624,8 +5624,6 @@ GenTree* Compiler::fgMorphField(GenTree* tree, MorphAddrContext* mac) GenTree* lclVar = gtNewLclvNode(lclNum, objRefType); nullchk = gtNewNullCheck(lclVar, compCurBB); - nullchk->gtFlags |= GTF_DONT_CSE; // Don't try to create a CSE for these TYP_BYTE indirections - if (asg) { // Create the "comma" node. diff --git a/src/coreclr/jit/optimizer.cpp b/src/coreclr/jit/optimizer.cpp index 84c75a2cbb63c1..3b18e0d57a95b3 100644 --- a/src/coreclr/jit/optimizer.cpp +++ b/src/coreclr/jit/optimizer.cpp @@ -6521,6 +6521,15 @@ void Compiler::optHoistLoopBlocks(unsigned loopNum, ArrayStack* blo { return false; } + else if (node->OperIs(GT_NULLCHECK)) + { + // If a null-check is for `this` object, it is safe to + // hoist it out of the loop. Assrtionprop will get rid + // of left over nullchecks present inside the loop. Also, + // since NULLCHECK has no value, it will never be CSE, + // hence this check is not present in optIsCSEcandidate(). + return true; + } // Tree must be a suitable CSE candidate for us to be able to hoist it. return m_compiler->optIsCSEcandidate(node);