Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Remove GT_NULLCHECK #71707

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 0 additions & 6 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2727,11 +2727,6 @@ void Compiler::optAssertionGen(GenTree* tree)
assertionInfo = optCreateAssertion(tree->AsArrCommon()->ArrRef(), nullptr, OAK_NOT_EQUAL);
break;

case GT_NULLCHECK:
// Explicit null checks always create non-null assertions.
assertionInfo = optCreateAssertion(tree->AsIndir()->Addr(), nullptr, OAK_NOT_EQUAL);
break;

case GT_INTRINSIC:
if (tree->AsIntrinsic()->gtIntrinsicName == NI_System_Object_GetType)
{
Expand Down Expand Up @@ -5041,7 +5036,6 @@ GenTree* Compiler::optAssertionProp(ASSERT_VALARG_TP assertions, GenTree* tree,
case GT_OBJ:
case GT_BLK:
case GT_IND:
case GT_NULLCHECK:
case GT_STORE_DYN_BLK:
return optAssertionProp_Ind(assertions, tree, stmt);

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void genCodeForLclAddr(GenTreeLclVarCommon* lclAddrNode);
void genCodeForIndexAddr(GenTreeIndexAddr* tree);
void genCodeForIndir(GenTreeIndir* tree);
void genEmitCodeForUnusedIndir(GenTreeIndir* tree);
void genCodeForNegNot(GenTree* tree);
void genCodeForBswap(GenTree* tree);
bool genCanOmitNormalizationForBswap16(GenTree* tree);
Expand All @@ -1299,7 +1300,6 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void genCodeForCpBlkHelper(GenTreeBlk* cpBlkNode);
#endif
void genCodeForPhysReg(GenTreePhysReg* tree);
void genCodeForNullCheck(GenTreeIndir* tree);
void genCodeForCmpXchg(GenTreeCmpXchg* tree);

void genAlignStackBeforeCall(GenTreePutArgStk* putArgStk);
Expand Down
38 changes: 7 additions & 31 deletions src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,6 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
genCodeForPhysReg(treeNode->AsPhysReg());
break;

case GT_NULLCHECK:
genCodeForNullCheck(treeNode->AsIndir());
break;

case GT_CATCH_ARG:

noway_assert(handlerGetsXcptnObj(compiler->compCurBB->bbCatchTyp));
Expand Down Expand Up @@ -1453,30 +1449,6 @@ void CodeGen::genCodeForPhysReg(GenTreePhysReg* tree)
genProduceReg(tree);
}

//---------------------------------------------------------------------
// genCodeForNullCheck - generate code for a GT_NULLCHECK node
//
// Arguments
// tree - the GT_NULLCHECK node
//
// Return value:
// None
//
void CodeGen::genCodeForNullCheck(GenTreeIndir* tree)
{
#ifdef TARGET_ARM
assert(!"GT_NULLCHECK isn't supported for Arm32; use GT_IND.");
#else
assert(tree->OperIs(GT_NULLCHECK));
GenTree* op1 = tree->gtOp1;

genConsumeRegs(op1);
regNumber targetReg = REG_ZR;

GetEmitter()->emitInsLoadStoreOp(ins_Load(tree->TypeGet()), emitActualTypeSize(tree), targetReg, tree);
#endif
}

//------------------------------------------------------------------------
// genCodeForArrIndex: Generates code to bounds check the index for one dimension of an array reference,
// producing the effective index by subtracting the lower bound.
Expand Down Expand Up @@ -1770,9 +1742,13 @@ void CodeGen::genCodeForIndir(GenTreeIndir* tree)
}
#endif // FEATURE_SIMD

var_types type = tree->TypeGet();
instruction ins = ins_Load(type);
regNumber targetReg = tree->GetRegNum();
var_types type = tree->TypeGet();
instruction ins = ins_Load(type);
#ifdef TARGET_ARM64
regNumber targetReg = tree->IsUnusedValue() ? REG_ZR : tree->GetRegNum();
#else
regNumber targetReg = tree->GetRegNum();
#endif

genConsumeAddress(tree->Addr());

Expand Down
24 changes: 1 addition & 23 deletions src/coreclr/jit/codegenloongarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5592,10 +5592,6 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
genCodeForPhysReg(treeNode->AsPhysReg());
break;

case GT_NULLCHECK:
genCodeForNullCheck(treeNode->AsIndir());
break;

case GT_CATCH_ARG:

noway_assert(handlerGetsXcptnObj(compiler->compCurBB->bbCatchTyp));
Expand Down Expand Up @@ -6439,24 +6435,6 @@ void CodeGen::genCodeForPhysReg(GenTreePhysReg* tree)
genProduceReg(tree);
}

//---------------------------------------------------------------------
// genCodeForNullCheck - generate code for a GT_NULLCHECK node
//
// Arguments
// tree - the GT_NULLCHECK node
//
// Return value:
// None
//
void CodeGen::genCodeForNullCheck(GenTreeIndir* tree)
{
assert(tree->OperIs(GT_NULLCHECK));

genConsumeRegs(tree->gtOp1);

GetEmitter()->emitInsLoadStoreOp(ins_Load(tree->TypeGet()), emitActualTypeSize(tree), REG_R0, tree);
}

//------------------------------------------------------------------------
// genCodeForArrIndex: Generates code to bounds check the index for one dimension of an array reference,
// producing the effective index by subtracting the lower bound.
Expand Down Expand Up @@ -6829,7 +6807,7 @@ void CodeGen::genCodeForIndir(GenTreeIndir* tree)
var_types type = tree->TypeGet();
instruction ins = ins_Load(type);
instruction ins2 = INS_none;
regNumber targetReg = tree->GetRegNum();
regNumber targetReg = tree->IsUnusedValue() ? REG_R0 : tree->GetRegNum();
regNumber tmpReg = targetReg;
emitAttr attr = emitActualTypeSize(type);
int offset = 0;
Expand Down
64 changes: 40 additions & 24 deletions src/coreclr/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1873,10 +1873,6 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
genCodeForPhysReg(treeNode->AsPhysReg());
break;

case GT_NULLCHECK:
genCodeForNullCheck(treeNode->AsIndir());
break;

case GT_CATCH_ARG:

noway_assert(handlerGetsXcptnObj(compiler->compCurBB->bbCatchTyp));
Expand Down Expand Up @@ -4216,24 +4212,6 @@ void CodeGen::genCodeForPhysReg(GenTreePhysReg* tree)
genProduceReg(tree);
}

//---------------------------------------------------------------------
// genCodeForNullCheck - generate code for a GT_NULLCHECK node
//
// Arguments
// tree - the GT_NULLCHECK node
//
// Return value:
// None
//
void CodeGen::genCodeForNullCheck(GenTreeIndir* tree)
{
assert(tree->OperIs(GT_NULLCHECK));

assert(tree->gtOp1->isUsedFromReg());
regNumber reg = genConsumeReg(tree->gtOp1);
GetEmitter()->emitIns_AR_R(INS_cmp, emitTypeSize(tree), reg, reg, 0);
}

//------------------------------------------------------------------------
// genCodeForArrIndex: Generates code to bounds check the index for one dimension of an array reference,
// producing the effective index by subtracting the lower bound.
Expand Down Expand Up @@ -5126,13 +5104,51 @@ void CodeGen::genCodeForIndir(GenTreeIndir* tree)
else
{
genConsumeAddress(addr);
instruction loadIns = tree->DontExtend() ? INS_mov : ins_Load(targetType);
emit->emitInsLoadInd(loadIns, emitTypeSize(tree), tree->GetRegNum(), tree);

if (tree->IsUnusedValue())
{
genEmitCodeForUnusedIndir(tree);
}
else
{
instruction loadIns = tree->DontExtend() ? INS_mov : ins_Load(targetType);
emit->emitInsLoadInd(loadIns, emitTypeSize(tree), tree->GetRegNum(), tree);
}
}

genProduceReg(tree);
}

//---------------------------------------------------------------------
// genEmitCodeForUnusedIndir - emit code for an unused indirection
//
// Arguments
// tree - the indirection
//
// Return value:
// None
//
void CodeGen::genEmitCodeForUnusedIndir(GenTreeIndir* tree)
{
GenTree* addr = tree->Addr();
if (!addr->isContained())
{
GetEmitter()->emitIns_AR_R(INS_cmp, emitTypeSize(tree), REG_EAX, addr->GetRegNum(), 0);
return;
}

if (addr->OperIsLocalAddr())
{
GenTreeLclVarCommon* varNode = addr->AsLclVarCommon();
unsigned offset = varNode->GetLclOffs();
GetEmitter()->emitIns_S_R(INS_cmp, emitTypeSize(tree), REG_EAX, varNode->GetLclNum(), offset);
return;
}

assert(addr->OperIsAddrMode() || addr->IsCnsIntOrI());
GetEmitter()->emitIns_R_A(INS_cmp, emitTypeSize(tree), REG_EAX, tree);
}

//------------------------------------------------------------------------
// genCodeForStoreInd: Produce code for a GT_STOREIND node.
//
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9863,7 +9863,7 @@ var_types Compiler::gtTypeForNullCheck(GenTree* tree)
void Compiler::gtChangeOperToNullCheck(GenTree* tree, BasicBlock* block)
{
assert(tree->OperIs(GT_FIELD, GT_IND, GT_OBJ, GT_BLK));
tree->ChangeOper(GT_NULLCHECK);
tree->ChangeOper(GT_IND);
tree->ChangeType(gtTypeForNullCheck(tree));
block->bbFlags |= BBF_HAS_NULLCHECK;
optMethodFlags |= OMF_HAS_NULLCHECK;
Expand Down
15 changes: 6 additions & 9 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6962,21 +6962,19 @@ class Compiler
OPK_NULLCHECK
};

typedef JitHashTable<unsigned, JitSmallPrimitiveKeyFuncs<unsigned>, GenTree*> LocalNumberToNullCheckTreeMap;
typedef JitHashTable<unsigned, JitSmallPrimitiveKeyFuncs<unsigned>, GenTreeIndir*> LocalNumberToNullCheckTreeMap;

GenTree* getArrayLengthFromAllocation(GenTree* tree DEBUGARG(BasicBlock* block));
GenTree* optPropGetValueRec(unsigned lclNum, unsigned ssaNum, optPropKind valueKind, int walkDepth);
GenTree* optPropGetValue(unsigned lclNum, unsigned ssaNum, optPropKind valueKind);
GenTree* optEarlyPropRewriteTree(GenTree* tree, LocalNumberToNullCheckTreeMap* nullCheckMap);
bool optDoEarlyPropForBlock(BasicBlock* block);
bool optDoEarlyPropForFunc();
PhaseStatus optEarlyProp();
bool optFoldNullCheck(GenTree* tree, LocalNumberToNullCheckTreeMap* nullCheckMap);
GenTree* optFindNullCheckToFold(GenTree* tree, LocalNumberToNullCheckTreeMap* nullCheckMap);
bool optIsNullCheckFoldingLegal(GenTree* tree,
GenTree* nullCheckTree,
GenTree** nullCheckParent,
Statement** nullCheckStmt);
GenTreeIndir* optFindNullCheckToFold(GenTree* tree, LocalNumberToNullCheckTreeMap* nullCheckMap);
bool optIsNullCheckFoldingLegal(GenTree* tree,
GenTreeIndir* nullCheckTree,
GenTree** nullCheckParent,
Statement** nullCheckStmt);
bool optCanMoveNullCheckPastTree(GenTree* tree,
unsigned nullCheckLclNum,
bool isInsideTry,
Expand Down Expand Up @@ -10859,7 +10857,6 @@ class GenTreeVisitor
case GT_INIT_VAL:
case GT_JTRUE:
case GT_SWITCH:
case GT_NULLCHECK:
case GT_PUTARG_REG:
case GT_PUTARG_STK:
case GT_RETURNTRAP:
Expand Down
6 changes: 2 additions & 4 deletions src/coreclr/jit/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1294,12 +1294,11 @@ inline GenTreeIndir* Compiler::gtNewIndir(var_types typ, GenTree* addr)
// basicBlock - Basic block of the node
//
// Return Value:
// New GT_NULLCHECK node

// New GT_IND node
inline GenTree* Compiler::gtNewNullCheck(GenTree* addr, BasicBlock* basicBlock)
{
assert(fgAddrCouldBeNull(addr));
GenTree* nullCheck = gtNewOperNode(GT_NULLCHECK, TYP_BYTE, addr);
GenTree* nullCheck = gtNewOperNode(GT_IND, TYP_BYTE, addr);
nullCheck->gtFlags |= GTF_EXCEPT;
basicBlock->bbFlags |= BBF_HAS_NULLCHECK;
optMethodFlags |= OMF_HAS_NULLCHECK;
Expand Down Expand Up @@ -4235,7 +4234,6 @@ void GenTree::VisitOperands(TVisitor visitor)
case GT_ARR_ADDR:
case GT_JTRUE:
case GT_SWITCH:
case GT_NULLCHECK:
case GT_PUTARG_REG:
case GT_PUTARG_STK:
#if FEATURE_ARG_SPLIT
Expand Down
Loading