Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Hoist nullcheck for other objects as well
  • Loading branch information
kunalspathak committed Apr 29, 2022
commit d02af75217cd62467bca1bfb0b6e9ab3d413945d
6 changes: 0 additions & 6 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5624,12 +5624,6 @@ GenTree* Compiler::fgMorphField(GenTree* tree, MorphAddrContext* mac)
GenTree* lclVar = gtNewLclvNode(lclNum, objRefType);
nullchk = gtNewNullCheck(lclVar, compCurBB);

if (lclNum != info.compThisArg)
{
// Don't try to create a CSE for these TYP_BYTE indirections unless it was a "this" pointer.
nullchk->gtFlags |= GTF_DONT_CSE;
}

if (asg)
{
// Create the "comma" node.
Expand Down
18 changes: 6 additions & 12 deletions src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6523,18 +6523,12 @@ void Compiler::optHoistLoopBlocks(unsigned loopNum, ArrayStack<BasicBlock*>* blo
}
else if (node->OperIs(GT_NULLCHECK))
{
GenTreeLclVar* lclVar;
if (node->AsUnOp()->gtGetOp1()->OperIs(GT_LCL_VAR))
{
// If a null-check is for `this` object, it is safe to
// hoist it out of the loop.
//
// TODO-CQ: Identify more scenarios where we can hoist
// the null-checks
lclVar = node->AsUnOp()->gtGetOp1()->AsLclVar();
return lclVar->GetLclNum() == m_compiler->info.compThisArg;
}
return false;
// 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.
Expand Down