Skip to content

Commit ff9040a

Browse files
Treat INDEX_ADDRs as non-null (#69209)
* Treat INDEX_ADDRs as non-null If they range check that is. * Also use IsBoundsChecked in more places
1 parent e8a18e2 commit ff9040a

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

src/coreclr/jit/codegenarmarch.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,7 @@ void CodeGen::genCodeForIndexAddr(GenTreeIndexAddr* node)
17961796
const regNumber tmpReg = node->GetSingleTempReg();
17971797

17981798
// Generate the bounds check if necessary.
1799-
if ((node->gtFlags & GTF_INX_RNGCHK) != 0)
1799+
if (node->IsBoundsChecked())
18001800
{
18011801
GetEmitter()->emitIns_R_R_I(INS_ldr, EA_4BYTE, tmpReg, base->GetRegNum(), node->gtLenOffset);
18021802
GetEmitter()->emitIns_R_R(INS_cmp, emitActualTypeSize(index->TypeGet()), index->GetRegNum(), tmpReg);

src/coreclr/jit/codegenloongarch64.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6744,7 +6744,7 @@ void CodeGen::genCodeForIndexAddr(GenTreeIndexAddr* node)
67446744
assert(index->isUsedFromReg());
67456745

67466746
// Generate the bounds check if necessary.
6747-
if ((node->gtFlags & GTF_INX_RNGCHK) != 0)
6747+
if (node->IsBoundsChecked())
67486748
{
67496749
GetEmitter()->emitIns_R_R_I(INS_ld_w, EA_4BYTE, REG_R21, base->GetRegNum(), node->gtLenOffset);
67506750
// if (index >= REG_R21)

src/coreclr/jit/codegenxarch.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4893,7 +4893,7 @@ void CodeGen::genCodeForIndexAddr(GenTreeIndexAddr* node)
48934893
#endif
48944894

48954895
// Generate the bounds check if necessary.
4896-
if ((node->gtFlags & GTF_INX_RNGCHK) != 0)
4896+
if (node->IsBoundsChecked())
48974897
{
48984898
#ifdef TARGET_64BIT
48994899
// The CLI Spec allows an array to be indexed by either an int32 or a native int. In the case that the index

src/coreclr/jit/flowgraph.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,10 @@ bool Compiler::fgAddrCouldBeNull(GenTree* addr)
945945
{
946946
return false;
947947
}
948+
else if (addr->OperIs(GT_INDEX_ADDR))
949+
{
950+
return !addr->AsIndexAddr()->IsNotNull();
951+
}
948952
else if (addr->OperIs(GT_ARR_ADDR))
949953
{
950954
return (addr->gtFlags & GTF_ARR_ADDR_NONNULL) == 0;

src/coreclr/jit/gentree.h

+10
Original file line numberDiff line numberDiff line change
@@ -6169,6 +6169,16 @@ struct GenTreeIndexAddr : public GenTreeOp
61696169
{
61706170
}
61716171
#endif
6172+
6173+
bool IsBoundsChecked() const
6174+
{
6175+
return (gtFlags & GTF_INX_RNGCHK) != 0;
6176+
}
6177+
6178+
bool IsNotNull() const
6179+
{
6180+
return IsBoundsChecked();
6181+
}
61726182
};
61736183

61746184
// GenTreeArrAddr - GT_ARR_ADDR, carries information about the array type from morph to VN.

0 commit comments

Comments
 (0)