Skip to content

Commit cb29b08

Browse files
authored
JIT: Fix fgDebugCheckTypes assert + small clean up (#113920)
1 parent ef1a8ab commit cb29b08

11 files changed

+19
-70
lines changed

src/coreclr/jit/codegenarmarch.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -1481,13 +1481,10 @@ void CodeGen::genRangeCheck(GenTree* oper)
14811481
assert(!arrLen->isContained());
14821482
// For (index == 0), we can just test if (length == 0) as this is the only case that would throw.
14831483
// This may lead to an optimization by using cbz/tbnz.
1484-
genJumpToThrowHlpBlk(
1485-
bndsChk->gtThrowKind,
1486-
[&](BasicBlock* target, bool isInline) {
1484+
genJumpToThrowHlpBlk(bndsChk->gtThrowKind, [&](BasicBlock* target, bool isInline) {
14871485
genCompareImmAndJump(isInline ? GenCondition::NE : GenCondition::EQ, arrLen->GetRegNum(), 0,
14881486
emitActualTypeSize(arrLen), target);
1489-
},
1490-
bndsChk->gtIndRngFailBB);
1487+
});
14911488
return;
14921489
}
14931490
#endif
@@ -1509,7 +1506,7 @@ void CodeGen::genRangeCheck(GenTree* oper)
15091506
#endif // DEBUG
15101507

15111508
GetEmitter()->emitInsBinary(INS_cmp, emitActualTypeSize(bndsChkType), src1, src2);
1512-
genJumpToThrowHlpBlk(jmpKind, bndsChk->gtThrowKind, bndsChk->gtIndRngFailBB);
1509+
genJumpToThrowHlpBlk(jmpKind, bndsChk->gtThrowKind);
15131510
}
15141511

15151512
//---------------------------------------------------------------------
@@ -1717,7 +1714,7 @@ void CodeGen::genCodeForIndexAddr(GenTreeIndexAddr* node)
17171714
{
17181715
GetEmitter()->emitIns_R_R_I(INS_ldr, EA_4BYTE, tmpReg, base->GetRegNum(), node->gtLenOffset);
17191716
GetEmitter()->emitIns_R_R(INS_cmp, emitActualTypeSize(index->TypeGet()), indexReg, tmpReg);
1720-
genJumpToThrowHlpBlk(EJ_hs, SCK_RNGCHK_FAIL, node->gtIndRngFailBB);
1717+
genJumpToThrowHlpBlk(EJ_hs, SCK_RNGCHK_FAIL);
17211718
}
17221719

17231720
// Can we use a ScaledAdd instruction?

src/coreclr/jit/codegenloongarch64.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -5308,7 +5308,7 @@ void CodeGen::genRangeCheck(GenTree* oper)
53085308
assert(src1ChkType == TYP_INT || src1ChkType == TYP_LONG);
53095309
#endif // DEBUG
53105310

5311-
genJumpToThrowHlpBlk_la(bndsChk->gtThrowKind, INS_bgeu, reg1, bndsChk->gtIndRngFailBB, reg2);
5311+
genJumpToThrowHlpBlk_la(bndsChk->gtThrowKind, INS_bgeu, reg1, nullptr, reg2);
53125312
}
53135313

53145314
//---------------------------------------------------------------------
@@ -5542,7 +5542,7 @@ void CodeGen::genCodeForIndexAddr(GenTreeIndexAddr* node)
55425542
// IndRngFail:
55435543
// ...
55445544
// RngChkExit:
5545-
genJumpToThrowHlpBlk_la(SCK_RNGCHK_FAIL, INS_bgeu, index->GetRegNum(), node->gtIndRngFailBB, REG_R21);
5545+
genJumpToThrowHlpBlk_la(SCK_RNGCHK_FAIL, INS_bgeu, index->GetRegNum(), nullptr, REG_R21);
55465546
}
55475547

55485548
emitAttr attr = emitActualTypeSize(node);

src/coreclr/jit/codegenriscv64.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -5236,7 +5236,7 @@ void CodeGen::genRangeCheck(GenTree* oper)
52365236
assert(indexType == TYP_INT || indexType == TYP_LONG);
52375237
#endif // DEBUG
52385238

5239-
genJumpToThrowHlpBlk_la(bndsChk->gtThrowKind, INS_bgeu, indexReg, bndsChk->gtIndRngFailBB, lengthReg);
5239+
genJumpToThrowHlpBlk_la(bndsChk->gtThrowKind, INS_bgeu, indexReg, nullptr, lengthReg);
52405240
}
52415241

52425242
//---------------------------------------------------------------------
@@ -5512,7 +5512,7 @@ void CodeGen::genCodeForIndexAddr(GenTreeIndexAddr* node)
55125512
// IndRngFail:
55135513
// ...
55145514
// RngChkExit:
5515-
genJumpToThrowHlpBlk_la(SCK_RNGCHK_FAIL, INS_bgeu, index->GetRegNum(), node->gtIndRngFailBB, tempReg);
5515+
genJumpToThrowHlpBlk_la(SCK_RNGCHK_FAIL, INS_bgeu, index->GetRegNum(), nullptr, tempReg);
55165516
}
55175517

55185518
emitAttr attr = emitActualTypeSize(node);

src/coreclr/jit/codegenxarch.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -4678,7 +4678,7 @@ void CodeGen::genRangeCheck(GenTree* oper)
46784678
#endif // DEBUG
46794679

46804680
GetEmitter()->emitInsBinary(cmpKind, emitTypeSize(bndsChkType), src1, src2);
4681-
genJumpToThrowHlpBlk(jmpKind, bndsChk->gtThrowKind, bndsChk->gtIndRngFailBB);
4681+
genJumpToThrowHlpBlk(jmpKind, bndsChk->gtThrowKind);
46824682
}
46834683

46844684
//---------------------------------------------------------------------
@@ -5414,7 +5414,7 @@ void CodeGen::genCodeForIndexAddr(GenTreeIndexAddr* node)
54145414
GetEmitter()->emitIns_R_AR(INS_cmp, EA_4BYTE, indexReg, baseReg, static_cast<int>(node->gtLenOffset));
54155415
}
54165416

5417-
genJumpToThrowHlpBlk(EJ_jae, SCK_RNGCHK_FAIL, node->gtIndRngFailBB);
5417+
genJumpToThrowHlpBlk(EJ_jae, SCK_RNGCHK_FAIL);
54185418
}
54195419

54205420
#ifdef TARGET_64BIT

src/coreclr/jit/compiler.h

-11
Original file line numberDiff line numberDiff line change
@@ -7384,7 +7384,6 @@ class Compiler
73847384
#define OMF_HAS_EXPRUNTIMELOOKUP 0x00000080 // Method contains a runtime lookup to an expandable dictionary.
73857385
#define OMF_HAS_PATCHPOINT 0x00000100 // Method contains patchpoints
73867386
#define OMF_NEEDS_GCPOLLS 0x00000200 // Method needs GC polls
7387-
#define OMF_HAS_FROZEN_OBJECTS 0x00000400 // Method has frozen objects (REF constant int)
73887387
#define OMF_HAS_PARTIAL_COMPILATION_PATCHPOINT 0x00000800 // Method contains partial compilation patchpoints
73897388
#define OMF_HAS_TAILCALL_SUCCESSOR 0x00001000 // Method has potential tail call in a non BBJ_RETURN block
73907389
#define OMF_HAS_MDNEWARRAY 0x00002000 // Method contains 'new' of an MD array
@@ -7416,16 +7415,6 @@ class Compiler
74167415

74177416
void addFatPointerCandidate(GenTreeCall* call);
74187417

7419-
bool doesMethodHaveFrozenObjects() const
7420-
{
7421-
return (optMethodFlags & OMF_HAS_FROZEN_OBJECTS) != 0;
7422-
}
7423-
7424-
void setMethodHasFrozenObjects()
7425-
{
7426-
optMethodFlags |= OMF_HAS_FROZEN_OBJECTS;
7427-
}
7428-
74297418
bool doesMethodHaveStaticInit()
74307419
{
74317420
return (optMethodFlags & OMF_HAS_STATIC_INIT) != 0;

src/coreclr/jit/fgdiagnostic.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3286,7 +3286,7 @@ void Compiler::fgDebugCheckTypes(GenTree* tree)
32863286
if (!node->TypeIs(TYP_VOID))
32873287
{
32883288
m_compiler->gtDispTree(node);
3289-
assert("The tree is expected to be of TYP_VOID type");
3289+
assert(!"The tree is expected to be of TYP_VOID type");
32903290
}
32913291
break;
32923292

src/coreclr/jit/flowgraph.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,6 @@ GenTree* Compiler::fgGetCritSectOfStaticMethod()
12861286
CORINFO_OBJECT_HANDLE ptr = info.compCompHnd->getRuntimeTypePointer(info.compClassHnd);
12871287
if (ptr != NULL)
12881288
{
1289-
setMethodHasFrozenObjects();
12901289
tree = gtNewIconEmbHndNode((void*)ptr, nullptr, GTF_ICON_OBJ_HDL, nullptr);
12911290
}
12921291
else

src/coreclr/jit/gentree.cpp

+5-28
Original file line numberDiff line numberDiff line change
@@ -7734,27 +7734,20 @@ GenTree* Compiler::gtNewStringLiteralNode(InfoAccessType iat, void* pValue)
77347734
switch (iat)
77357735
{
77367736
case IAT_VALUE:
7737-
setMethodHasFrozenObjects();
77387737
tree = gtNewIconEmbHndNode(pValue, nullptr, GTF_ICON_OBJ_HDL, nullptr);
7739-
#ifdef DEBUG
7740-
tree->AsIntCon()->gtTargetHandle = (size_t)pValue;
7741-
#endif
7738+
INDEBUG(tree->AsIntCon()->gtTargetHandle = (size_t)pValue);
77427739
break;
77437740

77447741
case IAT_PVALUE: // The value needs to be accessed via an indirection
77457742
// Create an indirection
77467743
tree = gtNewIndOfIconHandleNode(TYP_REF, (size_t)pValue, GTF_ICON_STR_HDL, true);
7747-
#ifdef DEBUG
7748-
tree->gtGetOp1()->AsIntCon()->gtTargetHandle = (size_t)pValue;
7749-
#endif
7744+
INDEBUG(tree->gtGetOp1()->AsIntCon()->gtTargetHandle = (size_t)pValue);
77507745
break;
77517746

77527747
case IAT_PPVALUE: // The value needs to be accessed via a double indirection
77537748
// Create the first indirection.
77547749
tree = gtNewIndOfIconHandleNode(TYP_I_IMPL, (size_t)pValue, GTF_ICON_CONST_PTR, true);
7755-
#ifdef DEBUG
7756-
tree->gtGetOp1()->AsIntCon()->gtTargetHandle = (size_t)pValue;
7757-
#endif
7750+
INDEBUG(tree->gtGetOp1()->AsIntCon()->gtTargetHandle = (size_t)pValue);
77587751
// Create the second indirection.
77597752
tree = gtNewIndir(TYP_REF, tree, GTF_IND_NONFAULTING | GTF_IND_INVARIANT | GTF_IND_NONNULL);
77607753
break;
@@ -8112,11 +8105,7 @@ GenTree* Compiler::gtNewGenericCon(var_types type, uint8_t* cnsVal)
81128105
}
81138106
else
81148107
{
8115-
// Even if the caller doesn't need the resulting tree let's still conservatively call
8116-
// setMethodHasFrozenObjects here to make caller's life easier.
8117-
setMethodHasFrozenObjects();
8118-
GenTree* tree = gtNewIconEmbHndNode((void*)val, nullptr, GTF_ICON_OBJ_HDL, nullptr);
8119-
return tree;
8108+
return gtNewIconEmbHndNode((void*)val, nullptr, GTF_ICON_OBJ_HDL, nullptr);
81208109
}
81218110
}
81228111
#ifdef FEATURE_SIMD
@@ -9528,7 +9517,6 @@ GenTree* Compiler::gtCloneExpr(GenTree* tree)
95289517
GenTreeIndexAddr(asIndAddr->Arr(), asIndAddr->Index(), asIndAddr->gtElemType,
95299518
asIndAddr->gtStructElemClass, asIndAddr->gtElemSize, asIndAddr->gtLenOffset,
95309519
asIndAddr->gtElemOffset, asIndAddr->IsBoundsChecked());
9531-
copy->AsIndexAddr()->gtIndRngFailBB = asIndAddr->gtIndRngFailBB;
95329520
}
95339521
break;
95349522

@@ -9626,8 +9614,7 @@ GenTree* Compiler::gtCloneExpr(GenTree* tree)
96269614
copy = new (this, GT_BOUNDS_CHECK)
96279615
GenTreeBoundsChk(tree->AsBoundsChk()->GetIndex(), tree->AsBoundsChk()->GetArrayLength(),
96289616
tree->AsBoundsChk()->gtThrowKind);
9629-
copy->AsBoundsChk()->gtIndRngFailBB = tree->AsBoundsChk()->gtIndRngFailBB;
9630-
copy->AsBoundsChk()->gtInxType = tree->AsBoundsChk()->gtInxType;
9617+
copy->AsBoundsChk()->gtInxType = tree->AsBoundsChk()->gtInxType;
96319618
break;
96329619

96339620
case GT_LEA:
@@ -11031,15 +11018,8 @@ void Compiler::gtDispNodeName(GenTree* tree)
1103111018
switch (tree->AsBoundsChk()->gtThrowKind)
1103211019
{
1103311020
case SCK_RNGCHK_FAIL:
11034-
{
1103511021
bufp += SimpleSprintf_s(bufp, buf, sizeof(buf), " %s_Rng", name);
11036-
if (tree->AsBoundsChk()->gtIndRngFailBB != nullptr)
11037-
{
11038-
bufp += SimpleSprintf_s(bufp, buf, sizeof(buf), " -> " FMT_BB,
11039-
tree->AsBoundsChk()->gtIndRngFailBB->bbNum);
11040-
}
1104111022
break;
11042-
}
1104311023
case SCK_ARG_EXCPN:
1104411024
sprintf_s(bufp, sizeof(buf), " %s_Arg", name);
1104511025
break;
@@ -12026,7 +12006,6 @@ void Compiler::gtDispConst(GenTree* tree)
1202612006
}
1202712007
else
1202812008
{
12029-
assert(doesMethodHaveFrozenObjects());
1203012009
printf(" 0x%llx", dspIconVal);
1203112010
}
1203212011
}
@@ -33412,8 +33391,6 @@ bool Compiler::gtCanSkipCovariantStoreCheck(GenTree* value, GenTree* array)
3341233391
}
3341333392
// Non-0 const refs can only occur with frozen objects
3341433393
assert(value->IsIconHandle(GTF_ICON_OBJ_HDL));
33415-
assert(doesMethodHaveFrozenObjects() ||
33416-
(compIsForInlining() && impInlineInfo->InlinerCompiler->doesMethodHaveFrozenObjects()));
3341733394
}
3341833395

3341933396
// Try and get a class handle for the array

src/coreclr/jit/gentree.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -7374,8 +7374,6 @@ struct GenTreeIndexAddr : public GenTreeOp
73747374

73757375
CORINFO_CLASS_HANDLE gtStructElemClass; // If the element type is a struct, this is the struct type.
73767376

7377-
BasicBlock* gtIndRngFailBB; // Basic block to jump to for array-index-out-of-range
7378-
73797377
var_types gtElemType; // The element type of the array.
73807378
unsigned gtElemSize; // size of elements in the array
73817379
unsigned gtLenOffset; // The offset from the array's base address to its length.
@@ -7391,7 +7389,6 @@ struct GenTreeIndexAddr : public GenTreeOp
73917389
bool boundsCheck)
73927390
: GenTreeOp(GT_INDEX_ADDR, TYP_BYREF, arr, ind)
73937391
, gtStructElemClass(structElemClass)
7394-
, gtIndRngFailBB(nullptr)
73957392
, gtElemType(elemType)
73967393
, gtElemSize(elemSize)
73977394
, gtLenOffset(lenOffset)
@@ -7588,8 +7585,7 @@ struct GenTreeMDArr : public GenTreeArrCommon
75887585
//
75897586
struct GenTreeBoundsChk : public GenTreeOp
75907587
{
7591-
BasicBlock* gtIndRngFailBB; // Basic block to jump to for index-out-of-range
7592-
SpecialCodeKind gtThrowKind; // Kind of throw block to branch to on failure
7588+
SpecialCodeKind gtThrowKind; // Kind of throw block to branch to on failure
75937589

75947590
// Store some information about the array element type that was in the GT_INDEX_ADDR node before morphing.
75957591
// Note that this information is also stored in the ARR_ADDR node of the morphed tree, but that can be hard
@@ -7598,7 +7594,6 @@ struct GenTreeBoundsChk : public GenTreeOp
75987594

75997595
GenTreeBoundsChk(GenTree* index, GenTree* length, SpecialCodeKind kind)
76007596
: GenTreeOp(GT_BOUNDS_CHECK, TYP_VOID, index, length)
7601-
, gtIndRngFailBB(nullptr)
76027597
, gtThrowKind(kind)
76037598
, gtInxType(TYP_UNKNOWN)
76047599
{

src/coreclr/jit/morph.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -6469,7 +6469,6 @@ GenTree* Compiler::fgMorphCall(GenTreeCall* call)
64696469
CORINFO_OBJECT_HANDLE ptr = info.compCompHnd->getRuntimeTypePointer(hClass);
64706470
if (ptr != NULL)
64716471
{
6472-
setMethodHasFrozenObjects();
64736472
GenTree* retNode = gtNewIconEmbHndNode((void*)ptr, nullptr, GTF_ICON_OBJ_HDL, nullptr);
64746473
return fgMorphTree(retNode);
64756474
}
@@ -11802,6 +11801,7 @@ void Compiler::fgKillDependentAssertions(unsigned lclNum DEBUGARG(GenTree* tree)
1180211801
//
1180311802
void Compiler::fgAssertionGen(GenTree* tree)
1180411803
{
11804+
assert(optLocalAssertionProp);
1180511805
INDEBUG(unsigned oldAssertionCount = optAssertionCount;);
1180611806
optAssertionGen(tree);
1180711807

@@ -11843,7 +11843,7 @@ void Compiler::fgAssertionGen(GenTree* tree)
1184311843
//
1184411844
auto addImpliedAssertions = [=](AssertionIndex index, ASSERT_TP& assertions) {
1184511845
AssertionDsc* const assertion = optGetAssertion(index);
11846-
if (optLocalAssertionProp && (assertion->assertionKind == OAK_EQUAL) && (assertion->op1.kind == O1K_LCLVAR) &&
11846+
if ((assertion->assertionKind == OAK_EQUAL) && (assertion->op1.kind == O1K_LCLVAR) &&
1184711847
(assertion->op2.kind == O2K_CONST_INT))
1184811848
{
1184911849
LclVarDsc* const lclDsc = lvaGetDesc(assertion->op1.lclNum);

src/coreclr/jit/valuenum.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -11622,7 +11622,6 @@ void Compiler::fgValueNumberTreeConst(GenTree* tree)
1162211622
}
1162311623
else
1162411624
{
11625-
assert(doesMethodHaveFrozenObjects());
1162611625
tree->gtVNPair.SetBoth(
1162711626
vnStore->VNForHandle(ssize_t(tree->AsIntConCommon()->IconValue()), tree->GetIconHandleFlag()));
1162811627

@@ -12065,10 +12064,6 @@ bool Compiler::fgValueNumberConstLoad(GenTreeIndir* tree)
1206512064
if (info.compCompHnd->getStaticFieldContent(fieldHandle, buffer, size, (int)byteOffset))
1206612065
{
1206712066
ValueNum vn = vnStore->VNForGenericCon(tree->TypeGet(), buffer);
12068-
if (vnStore->IsVNObjHandle(vn))
12069-
{
12070-
setMethodHasFrozenObjects();
12071-
}
1207212067
tree->gtVNPair.SetBoth(vn);
1207312068
return true;
1207412069
}
@@ -12866,7 +12861,6 @@ void Compiler::fgValueNumberIntrinsic(GenTree* tree)
1286612861
CORINFO_OBJECT_HANDLE typeObj = info.compCompHnd->getRuntimeTypePointer(cls);
1286712862
if (typeObj != nullptr)
1286812863
{
12869-
setMethodHasFrozenObjects();
1287012864
ValueNum handleVN = vnStore->VNForHandle((ssize_t)typeObj, GTF_ICON_OBJ_HDL);
1287112865
intrinsic->gtVNPair = vnStore->VNPWithExc(ValueNumPair(handleVN, handleVN), arg0VNPx);
1287212866
return;
@@ -13606,7 +13600,6 @@ bool Compiler::fgValueNumberSpecialIntrinsic(GenTreeCall* call)
1360613600
CORINFO_OBJECT_HANDLE obj = info.compCompHnd->getRuntimeTypePointer((CORINFO_CLASS_HANDLE)clsHandle);
1360713601
if (obj != nullptr)
1360813602
{
13609-
setMethodHasFrozenObjects();
1361013603
call->gtVNPair.SetBoth(vnStore->VNForHandle((ssize_t)obj, GTF_ICON_OBJ_HDL));
1361113604
return true;
1361213605
}
@@ -14049,7 +14042,6 @@ bool Compiler::fgValueNumberHelperCall(GenTreeCall* call)
1404914042
CORINFO_OBJECT_HANDLE typeObj = info.compCompHnd->getRuntimeTypePointer(cls);
1405014043
if (typeObj != nullptr)
1405114044
{
14052-
setMethodHasFrozenObjects();
1405314045
ValueNum typeObjVN = vnStore->VNForHandle((ssize_t)typeObj, GTF_ICON_OBJ_HDL);
1405414046
call->gtVNPair.SetBoth(vnStore->VNForBitCast(typeObjVN, TYP_STRUCT, genTypeSize(TYP_REF)));
1405514047
return false;

0 commit comments

Comments
 (0)