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

Treat INDEX_ADDRs as non-null #69209

Merged
merged 2 commits into from
May 12, 2022
Merged
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
2 changes: 1 addition & 1 deletion src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,7 @@ void CodeGen::genCodeForIndexAddr(GenTreeIndexAddr* node)
const regNumber tmpReg = node->GetSingleTempReg();

// Generate the bounds check if necessary.
if ((node->gtFlags & GTF_INX_RNGCHK) != 0)
if (node->IsBoundsChecked())
{
GetEmitter()->emitIns_R_R_I(INS_ldr, EA_4BYTE, tmpReg, base->GetRegNum(), node->gtLenOffset);
GetEmitter()->emitIns_R_R(INS_cmp, emitActualTypeSize(index->TypeGet()), index->GetRegNum(), tmpReg);
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/codegenloongarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6744,7 +6744,7 @@ void CodeGen::genCodeForIndexAddr(GenTreeIndexAddr* node)
assert(index->isUsedFromReg());

// Generate the bounds check if necessary.
if ((node->gtFlags & GTF_INX_RNGCHK) != 0)
if (node->IsBoundsChecked())
{
GetEmitter()->emitIns_R_R_I(INS_ld_w, EA_4BYTE, REG_R21, base->GetRegNum(), node->gtLenOffset);
// if (index >= REG_R21)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4893,7 +4893,7 @@ void CodeGen::genCodeForIndexAddr(GenTreeIndexAddr* node)
#endif

// Generate the bounds check if necessary.
if ((node->gtFlags & GTF_INX_RNGCHK) != 0)
if (node->IsBoundsChecked())
{
#ifdef TARGET_64BIT
// The CLI Spec allows an array to be indexed by either an int32 or a native int. In the case that the index
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,10 @@ bool Compiler::fgAddrCouldBeNull(GenTree* addr)
{
return false;
}
else if (addr->OperIs(GT_INDEX_ADDR))
{
return !addr->AsIndexAddr()->IsNotNull();
}
else if (addr->OperIs(GT_ARR_ADDR))
{
return (addr->gtFlags & GTF_ARR_ADDR_NONNULL) == 0;
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -6178,6 +6178,16 @@ struct GenTreeIndexAddr : public GenTreeOp
{
}
#endif

bool IsBoundsChecked() const
{
return (gtFlags & GTF_INX_RNGCHK) != 0;
}

bool IsNotNull() const
{
return IsBoundsChecked();
}
};

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