Skip to content

JIT: Consistently use TypeIs/OperIs for type/oper checks #116141

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

Merged
merged 13 commits into from
Jun 3, 2025
Merged
72 changes: 36 additions & 36 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1, GenTree* op2, optAsser
op1 = op1->gtEffectiveVal();

ssize_t offset = 0;
while ((op1->gtOper == GT_ADD) && (op1->gtType == TYP_BYREF))
while (op1->OperIs(GT_ADD) && op1->TypeIs(TYP_BYREF))
{
if (op1->gtGetOp2()->IsCnsIntOrI())
{
Expand Down Expand Up @@ -1184,7 +1184,7 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1, GenTree* op2, optAsser

{
/* Skip over a GT_COMMA node(s), if necessary */
while (op2->gtOper == GT_COMMA)
while (op2->OperIs(GT_COMMA))
{
op2 = op2->AsOp()->gtOp2;
}
Expand Down Expand Up @@ -1229,7 +1229,7 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1, GenTree* op2, optAsser
assertion.op2.kind = op2Kind;
assertion.op2.vn = optConservativeNormalVN(op2);

if (op2->gtOper == GT_CNS_INT)
if (op2->OperIs(GT_CNS_INT))
{
ssize_t iconVal = op2->AsIntCon()->IconValue();
if (varTypeIsSmall(lclVar) && op1->OperIs(GT_STORE_LCL_VAR))
Expand All @@ -1245,7 +1245,7 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1, GenTree* op2, optAsser
}
else
{
noway_assert(op2->gtOper == GT_CNS_DBL);
noway_assert(op2->OperIs(GT_CNS_DBL));
/* If we have an NaN value then don't record it */
if (FloatingPointUtils::isNaN(op2->AsDblCon()->DconValue()))
{
Expand Down Expand Up @@ -1441,7 +1441,7 @@ bool Compiler::optIsTreeKnownIntValue(bool vnBased, GenTree* tree, ssize_t* pCon
// Is Local assertion prop?
if (!vnBased)
{
if (tree->OperGet() == GT_CNS_INT)
if (tree->OperIs(GT_CNS_INT))
{
*pConstant = tree->AsIntCon()->IconValue();
*pFlags = tree->GetIconHandleFlag();
Expand Down Expand Up @@ -2062,25 +2062,25 @@ AssertionInfo Compiler::optAssertionGenJtrue(GenTree* tree)
}

// Check for op1 or op2 to be lcl var and if so, keep it in op1.
if ((op1->gtOper != GT_LCL_VAR) && (op2->gtOper == GT_LCL_VAR))
if (!op1->OperIs(GT_LCL_VAR) && op2->OperIs(GT_LCL_VAR))
{
std::swap(op1, op2);
}

// If op1 is lcl and op2 is const or lcl, create assertion.
if ((op1->gtOper == GT_LCL_VAR) && (op2->OperIsConst() || (op2->gtOper == GT_LCL_VAR))) // Fix for Dev10 851483
if (op1->OperIs(GT_LCL_VAR) && (op2->OperIsConst() || op2->OperIs(GT_LCL_VAR))) // Fix for Dev10 851483
{
// Watch out for cases where long local(s) are implicitly truncated.
//
LclVarDsc* const lcl1Dsc = lvaGetDesc(op1->AsLclVarCommon());
if ((lcl1Dsc->TypeGet() == TYP_LONG) && (op1->TypeGet() != TYP_LONG))
if (lcl1Dsc->TypeIs(TYP_LONG) && !op1->TypeIs(TYP_LONG))
{
return NO_ASSERTION_INDEX;
}
if (op2->OperIs(GT_LCL_VAR))
{
LclVarDsc* const lcl2Dsc = lvaGetDesc(op2->AsLclVarCommon());
if ((lcl2Dsc->TypeGet() == TYP_LONG) && (op2->TypeGet() != TYP_LONG))
if (lcl2Dsc->TypeIs(TYP_LONG) && !op2->TypeIs(TYP_LONG))
{
return NO_ASSERTION_INDEX;
}
Expand All @@ -2101,19 +2101,19 @@ AssertionInfo Compiler::optAssertionGenJtrue(GenTree* tree)
}

// Check op1 and op2 for an indirection of a GT_LCL_VAR and keep it in op1.
if (((op1->gtOper != GT_IND) || (op1->AsOp()->gtOp1->gtOper != GT_LCL_VAR)) &&
((op2->gtOper == GT_IND) && (op2->AsOp()->gtOp1->gtOper == GT_LCL_VAR)))
if ((!op1->OperIs(GT_IND) || !op1->AsOp()->gtOp1->OperIs(GT_LCL_VAR)) &&
(op2->OperIs(GT_IND) && op2->AsOp()->gtOp1->OperIs(GT_LCL_VAR)))
{
std::swap(op1, op2);
}
// If op1 is ind, then extract op1's oper.
if ((op1->gtOper == GT_IND) && (op1->AsOp()->gtOp1->gtOper == GT_LCL_VAR))
if (op1->OperIs(GT_IND) && op1->AsOp()->gtOp1->OperIs(GT_LCL_VAR))
{
return optCreateJtrueAssertions(op1, op2, assertionKind);
}

// Look for a call to an IsInstanceOf helper compared to a nullptr
if ((op2->gtOper != GT_CNS_INT) && (op1->gtOper == GT_CNS_INT))
if (!op2->OperIs(GT_CNS_INT) && op1->OperIs(GT_CNS_INT))
{
std::swap(op1, op2);
}
Expand Down Expand Up @@ -2757,7 +2757,7 @@ GenTree* Compiler::optVNBasedFoldExpr(BasicBlock* block, GenTree* parent, GenTre
//
GenTree* Compiler::optVNBasedFoldConstExpr(BasicBlock* block, GenTree* parent, GenTree* tree)
{
if (tree->OperGet() == GT_JTRUE)
if (tree->OperIs(GT_JTRUE))
{
// Treat JTRUE separately to extract side effects into respective statements rather
// than using a COMMA separated op1.
Expand Down Expand Up @@ -2797,7 +2797,7 @@ GenTree* Compiler::optVNBasedFoldConstExpr(BasicBlock* block, GenTree* parent, G
{
float value = vnStore->ConstantValue<float>(vnCns);

if (tree->TypeGet() == TYP_INT)
if (tree->TypeIs(TYP_INT))
{
// Same sized reinterpretation of bits to integer
conValTree = gtNewIconNode(*(reinterpret_cast<int*>(&value)));
Expand All @@ -2815,7 +2815,7 @@ GenTree* Compiler::optVNBasedFoldConstExpr(BasicBlock* block, GenTree* parent, G
{
double value = vnStore->ConstantValue<double>(vnCns);

if (tree->TypeGet() == TYP_LONG)
if (tree->TypeIs(TYP_LONG))
{
conValTree = gtNewLconNode(*(reinterpret_cast<INT64*>(&value)));
}
Expand Down Expand Up @@ -2878,7 +2878,7 @@ GenTree* Compiler::optVNBasedFoldConstExpr(BasicBlock* block, GenTree* parent, G

case TYP_REF:
{
if (tree->TypeGet() == TYP_REF)
if (tree->TypeIs(TYP_REF))
{
const size_t value = vnStore->ConstantValue<size_t>(vnCns);
if (value == 0)
Expand Down Expand Up @@ -3724,7 +3724,7 @@ GenTree* Compiler::optAssertionProp_LocalStore(ASSERT_VALARG_TP assertions, GenT
// does not kill the zerobj assertion for s.
//
unsigned const dstLclNum = store->GetLclNum();
bool const dstLclIsStruct = lvaGetDesc(dstLclNum)->TypeGet() == TYP_STRUCT;
bool const dstLclIsStruct = lvaGetDesc(dstLclNum)->TypeIs(TYP_STRUCT);
AssertionIndex const dstIndex =
optLocalAssertionIsEqualOrNotEqual(O1K_LCLVAR, dstLclNum, dstLclIsStruct ? O2K_ZEROOBJ : O2K_CONST_INT, 0,
assertions);
Expand Down Expand Up @@ -4474,19 +4474,19 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions,
{
printf("%d\n", vnStore->ConstantValue<int>(vnCns));
}
else if (op1->TypeGet() == TYP_LONG)
else if (op1->TypeIs(TYP_LONG))
{
printf("%lld\n", vnStore->ConstantValue<INT64>(vnCns));
}
else if (op1->TypeGet() == TYP_DOUBLE)
else if (op1->TypeIs(TYP_DOUBLE))
{
printf("%f\n", vnStore->ConstantValue<double>(vnCns));
}
else if (op1->TypeGet() == TYP_FLOAT)
else if (op1->TypeIs(TYP_FLOAT))
{
printf("%f\n", vnStore->ConstantValue<float>(vnCns));
}
else if (op1->TypeGet() == TYP_REF)
else if (op1->TypeIs(TYP_REF))
{
// The only constant of TYP_REF that ValueNumbering supports is 'null'
if (vnStore->ConstantValue<size_t>(vnCns) == 0)
Expand All @@ -4498,7 +4498,7 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions,
printf("%d (gcref)\n", static_cast<target_ssize_t>(vnStore->ConstantValue<size_t>(vnCns)));
}
}
else if (op1->TypeGet() == TYP_BYREF)
else if (op1->TypeIs(TYP_BYREF))
{
printf("%d (byref)\n", static_cast<target_ssize_t>(vnStore->ConstantValue<size_t>(vnCns)));
}
Expand All @@ -4519,7 +4519,7 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions,
op1->gtFlags |= (vnStore->GetHandleFlags(vnCns) & GTF_ICON_HDL_MASK);
}
}
else if (op1->TypeGet() == TYP_LONG)
else if (op1->TypeIs(TYP_LONG))
{
op1->BashToConst(vnStore->ConstantValue<INT64>(vnCns));

Expand All @@ -4528,7 +4528,7 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions,
op1->gtFlags |= (vnStore->GetHandleFlags(vnCns) & GTF_ICON_HDL_MASK);
}
}
else if (op1->TypeGet() == TYP_DOUBLE)
else if (op1->TypeIs(TYP_DOUBLE))
{
double constant = vnStore->ConstantValue<double>(vnCns);
op1->BashToConst(constant);
Expand All @@ -4539,19 +4539,19 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions,
// assertion we have made.
allowReverse = !FloatingPointUtils::isNaN(constant);
}
else if (op1->TypeGet() == TYP_FLOAT)
else if (op1->TypeIs(TYP_FLOAT))
{
float constant = vnStore->ConstantValue<float>(vnCns);
op1->BashToConst(constant);

// See comments for TYP_DOUBLE.
allowReverse = !FloatingPointUtils::isNaN(constant);
}
else if (op1->TypeGet() == TYP_REF)
else if (op1->TypeIs(TYP_REF))
{
op1->BashToConst(static_cast<target_ssize_t>(vnStore->ConstantValue<size_t>(vnCns)), TYP_REF);
}
else if (op1->TypeGet() == TYP_BYREF)
else if (op1->TypeIs(TYP_BYREF))
{
op1->BashToConst(static_cast<target_ssize_t>(vnStore->ConstantValue<size_t>(vnCns)), TYP_BYREF);
}
Expand All @@ -4564,7 +4564,7 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions,

// set foldResult to either 0 or 1
bool foldResult = assertionKindIsEqual;
if (tree->gtOper == GT_NE)
if (tree->OperIs(GT_NE))
{
foldResult = !foldResult;
}
Expand Down Expand Up @@ -4644,19 +4644,19 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions,
*/
GenTree* Compiler::optAssertionPropLocal_RelOp(ASSERT_VALARG_TP assertions, GenTree* tree, Statement* stmt)
{
assert(tree->OperGet() == GT_EQ || tree->OperGet() == GT_NE);
assert(tree->OperIs(GT_EQ) || tree->OperIs(GT_NE));

GenTree* op1 = tree->AsOp()->gtOp1;
GenTree* op2 = tree->AsOp()->gtOp2;

// For Local AssertionProp we only can fold when op1 is a GT_LCL_VAR
if (op1->gtOper != GT_LCL_VAR)
if (!op1->OperIs(GT_LCL_VAR))
{
return nullptr;
}

// For Local AssertionProp we only can fold when op2 is a GT_CNS_INT
if (op2->gtOper != GT_CNS_INT)
if (!op2->OperIs(GT_CNS_INT))
{
return nullptr;
}
Expand Down Expand Up @@ -4716,7 +4716,7 @@ GenTree* Compiler::optAssertionPropLocal_RelOp(ASSERT_VALARG_TP assertions, GenT

// Return either CNS_INT 0 or CNS_INT 1.
bool foldResult = (constantIsEqual == assertionKindIsEqual);
if (tree->gtOper == GT_NE)
if (tree->OperIs(GT_NE))
{
foldResult = !foldResult;
}
Expand Down Expand Up @@ -6101,7 +6101,7 @@ ASSERT_TP* Compiler::optComputeAssertionGen()
{
for (GenTree* const tree : stmt->TreeList())
{
if (tree->gtOper == GT_JTRUE)
if (tree->OperIs(GT_JTRUE))
{
// A GT_TRUE is always the last node in a tree, so we can break here
assert((tree->gtNext == nullptr) && (stmt->GetNextStmt() == nullptr));
Expand Down Expand Up @@ -6324,7 +6324,7 @@ Compiler::fgWalkResult Compiler::optVNBasedFoldCurStmt(BasicBlock* block,

// Don't propagate floating-point constants into a TYP_STRUCT LclVar
// This can occur for HFA return values (see hfa_sf3E_r.exe)
if (tree->TypeGet() == TYP_STRUCT)
if (tree->TypeIs(TYP_STRUCT))
{
return WALK_CONTINUE;
}
Expand Down Expand Up @@ -6445,7 +6445,7 @@ void Compiler::optVnNonNullPropCurStmt(BasicBlock* block, Statement* stmt, GenTr
{
ASSERT_TP empty = BitVecOps::UninitVal();
GenTree* newTree = nullptr;
if (tree->OperGet() == GT_CALL)
if (tree->OperIs(GT_CALL))
{
newTree = optNonNullAssertionProp_Call(empty, tree->AsCall());
}
Expand Down
22 changes: 11 additions & 11 deletions src/coreclr/jit/async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ bool AsyncLiveness::IsLive(unsigned lclNum)

LclVarDsc* dsc = m_comp->lvaGetDesc(lclNum);

if (((dsc->TypeGet() == TYP_BYREF) && !dsc->IsImplicitByRef()) ||
((dsc->TypeGet() == TYP_STRUCT) && dsc->GetLayout()->HasGCByRef()))
if ((dsc->TypeIs(TYP_BYREF) && !dsc->IsImplicitByRef()) ||
(dsc->TypeIs(TYP_STRUCT) && dsc->GetLayout()->HasGCByRef()))
{
// Even if these are address exposed we expect them to be dead at
// suspension points. TODO: It would be good to somehow verify these
Expand Down Expand Up @@ -617,7 +617,7 @@ ContinuationLayout AsyncTransformation::LayOutContinuation(BasicBlock*
{
LclVarDsc* dsc = m_comp->lvaGetDesc(inf.LclNum);

if ((dsc->TypeGet() == TYP_STRUCT) || dsc->IsImplicitByRef())
if (dsc->TypeIs(TYP_STRUCT) || dsc->IsImplicitByRef())
{
ClassLayout* layout = dsc->GetLayout();
assert(!layout->HasGCByRef());
Expand All @@ -643,15 +643,15 @@ ContinuationLayout AsyncTransformation::LayOutContinuation(BasicBlock*
inf.GCDataCount = layout->GetGCPtrCount();
}
}
else if (dsc->TypeGet() == TYP_REF)
else if (dsc->TypeIs(TYP_REF))
{
inf.Alignment = TARGET_POINTER_SIZE;
inf.DataSize = 0;
inf.GCDataCount = 1;
}
else
{
assert(dsc->TypeGet() != TYP_BYREF);
assert(!dsc->TypeIs(TYP_BYREF));

inf.Alignment = genTypeAlignments[dsc->TypeGet()];
inf.DataSize = genTypeSize(dsc);
Expand Down Expand Up @@ -1005,7 +1005,7 @@ void AsyncTransformation::FillInGCPointersOnSuspension(const jitstd::vector<Live
}

LclVarDsc* dsc = m_comp->lvaGetDesc(inf.LclNum);
if (dsc->TypeGet() == TYP_REF)
if (dsc->TypeIs(TYP_REF))
{
GenTree* value = m_comp->gtNewLclvNode(inf.LclNum, TYP_REF);
GenTree* objectArr = m_comp->gtNewLclvNode(objectArrLclNum, TYP_REF);
Expand All @@ -1016,7 +1016,7 @@ void AsyncTransformation::FillInGCPointersOnSuspension(const jitstd::vector<Live
}
else
{
assert((dsc->TypeGet() == TYP_STRUCT) || dsc->IsImplicitByRef());
assert(dsc->TypeIs(TYP_STRUCT) || dsc->IsImplicitByRef());
ClassLayout* layout = dsc->GetLayout();
unsigned numSlots = layout->GetSlotCount();
unsigned gcRefIndex = 0;
Expand Down Expand Up @@ -1132,7 +1132,7 @@ void AsyncTransformation::FillInDataOnSuspension(const jitstd::vector<LiveLocalI
}

GenTree* store;
if ((dsc->TypeGet() == TYP_STRUCT) || dsc->IsImplicitByRef())
if (dsc->TypeIs(TYP_STRUCT) || dsc->IsImplicitByRef())
{
GenTree* cns = m_comp->gtNewIconNode((ssize_t)offset, TYP_I_IMPL);
GenTree* addr = m_comp->gtNewOperNode(GT_ADD, TYP_BYREF, byteArr, cns);
Expand Down Expand Up @@ -1311,7 +1311,7 @@ void AsyncTransformation::RestoreFromDataOnResumption(unsigned
GenTree* addr = m_comp->gtNewOperNode(GT_ADD, TYP_BYREF, byteArr, cns);

GenTree* value;
if ((dsc->TypeGet() == TYP_STRUCT) || dsc->IsImplicitByRef())
if (dsc->TypeIs(TYP_STRUCT) || dsc->IsImplicitByRef())
{
value = m_comp->gtNewLoadValueNode(dsc->GetLayout(), addr, GTF_IND_NONFAULTING);
}
Expand Down Expand Up @@ -1358,7 +1358,7 @@ void AsyncTransformation::RestoreFromGCPointersOnResumption(unsigned
}

LclVarDsc* dsc = m_comp->lvaGetDesc(inf.LclNum);
if (dsc->TypeGet() == TYP_REF)
if (dsc->TypeIs(TYP_REF))
{
GenTree* objectArr = m_comp->gtNewLclvNode(resumeObjectArrLclNum, TYP_REF);
unsigned offset = OFFSETOF__CORINFO_Array__data + (inf.GCDataIndex * TARGET_POINTER_SIZE);
Expand All @@ -1369,7 +1369,7 @@ void AsyncTransformation::RestoreFromGCPointersOnResumption(unsigned
}
else
{
assert((dsc->TypeGet() == TYP_STRUCT) || dsc->IsImplicitByRef());
assert(dsc->TypeIs(TYP_STRUCT) || dsc->IsImplicitByRef());
ClassLayout* layout = dsc->GetLayout();
unsigned numSlots = layout->GetSlotCount();
unsigned gcRefIndex = 0;
Expand Down
Loading
Loading