Skip to content
Open
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
48 changes: 35 additions & 13 deletions src/coreclr/jit/lclmorph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1142,21 +1142,43 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>
{
Value& rhs = TopValue(0);
Value& lhs = TopValue(1);
if (m_compiler->opts.OptimizationEnabled() && lhs.IsAddress() && rhs.IsAddress() &&
(lhs.LclNum() == rhs.LclNum()) && (rhs.Offset() <= lhs.Offset()) &&
FitsIn<int>(lhs.Offset() - rhs.Offset()))
if (m_compiler->opts.OptimizationEnabled() && lhs.IsAddress() && rhs.IsAddress())
{
// TODO-Bug: Due to inlining we may end up with incorrectly typed SUB trees here.
assert(node->TypeIs(TYP_I_IMPL, TYP_BYREF));
LclVarDsc* lhsDsc = m_compiler->lvaGetDesc(lhs.LclNum());
LclVarDsc* rhsDsc = m_compiler->lvaGetDesc(rhs.LclNum());

ssize_t result = (ssize_t)(lhs.Offset() - rhs.Offset());
node->BashToConst(result, TYP_I_IMPL);
INDEBUG(lhs.Consume());
INDEBUG(rhs.Consume());
PopValue();
PopValue();
m_stmtModified = true;
break;
unsigned lhsLclNum = lhs.LclNum();
unsigned rhsLclNum = rhs.LclNum();

unsigned lhsOffset = lhs.Offset();
unsigned rhsOffset = rhs.Offset();

if (lhsDsc->lvIsStructField)
{
lhsLclNum = lhsDsc->lvParentLcl;
lhsOffset += lhsDsc->lvFldOffset;
}

if (rhsDsc->lvIsStructField)
{
rhsLclNum = rhsDsc->lvParentLcl;
rhsOffset += rhsDsc->lvFldOffset;
}

if ((lhsLclNum == rhsLclNum) && (rhsOffset <= lhsOffset) && FitsIn<int>(lhsOffset - rhsOffset))
{
// TODO-Bug: Due to inlining we may end up with incorrectly typed SUB trees here.
assert(node->TypeIs(TYP_I_IMPL, TYP_BYREF));

ssize_t result = (ssize_t)(lhsOffset - rhsOffset);
node->BashToConst(result, TYP_I_IMPL);
INDEBUG(lhs.Consume());
INDEBUG(rhs.Consume());
PopValue();
PopValue();
m_stmtModified = true;
break;
}
}

EscapeValue(TopValue(0), node);
Expand Down
Loading