Skip to content

Commit 7f034cf

Browse files
authored
Hoist the nullchecks for 'this' object (#68588)
* CSE nullcheck involving 'this' * Move the nullcheck to hoistable only * Minor fix to display IG01 weight correctly * Hoist nullcheck for other objects as well
1 parent 1047b63 commit 7f034cf

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/coreclr/jit/codegencommon.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,7 @@ void CodeGen::genGenerateMachineCode()
17391739
{
17401740
compiler->opts.disAsm = true;
17411741
}
1742+
compiler->compCurBB = compiler->fgFirstBB;
17421743

17431744
if (compiler->opts.disAsm)
17441745
{

src/coreclr/jit/morph.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5531,8 +5531,6 @@ GenTree* Compiler::fgMorphField(GenTree* tree, MorphAddrContext* mac)
55315531
GenTree* lclVar = gtNewLclvNode(lclNum, objRefType);
55325532
nullchk = gtNewNullCheck(lclVar, compCurBB);
55335533

5534-
nullchk->gtFlags |= GTF_DONT_CSE; // Don't try to create a CSE for these TYP_BYTE indirections
5535-
55365534
if (asg)
55375535
{
55385536
// Create the "comma" node.

src/coreclr/jit/optimizer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6516,6 +6516,15 @@ void Compiler::optHoistLoopBlocks(unsigned loopNum, ArrayStack<BasicBlock*>* blo
65166516
{
65176517
return false;
65186518
}
6519+
else if (node->OperIs(GT_NULLCHECK))
6520+
{
6521+
// If a null-check is for `this` object, it is safe to
6522+
// hoist it out of the loop. Assrtionprop will get rid
6523+
// of left over nullchecks present inside the loop. Also,
6524+
// since NULLCHECK has no value, it will never be CSE,
6525+
// hence this check is not present in optIsCSEcandidate().
6526+
return true;
6527+
}
65196528

65206529
// Tree must be a suitable CSE candidate for us to be able to hoist it.
65216530
return m_compiler->optIsCSEcandidate(node);

0 commit comments

Comments
 (0)