Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
address feedback
  • Loading branch information
EgorBo authored and github-actions committed Sep 13, 2022
commit caf0d40e047b3065bc3235bf0a2b48587ff24efe
15 changes: 6 additions & 9 deletions src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1379,18 +1379,15 @@ bool CodeGen::genCreateAddrMode(
}

// Special case: constant array index (that is range-checked)
if (fold && rv2->OperIs(GT_MUL, GT_LSH) && (rv2->gtGetOp2()->IsCnsIntOrI()))
if (fold)
{
// For valuetype arrays where we can't use the scaled address
// mode, rv2 will point to the scaled index. So we have to do
// more work
GenTree* index;
ssize_t indexScale = compiler->optGetArrayRefScaleAndIndex(rv2, &index DEBUGARG(false));
// By default, assume index is rv2 and indexScale is mul (or 1 if mul is zero)
GenTree* index = rv2;
ssize_t indexScale = mul == 0 ? 1 : mul;

// Apply accumulated scale if it exists
if (mul)
if (rv2->OperIs(GT_MUL, GT_LSH) && (rv2->gtGetOp2()->IsCnsIntOrI()))
{
indexScale *= mul;
indexScale *= compiler->optGetArrayRefScaleAndIndex(rv2, &index DEBUGARG(false));
}

// "index * 0" means index is zero
Expand Down