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

[JIT] LclMorph GT_IND(GT_LCL_VAR_ADDR) => GT_CAST(GT_LCL_VAR) narrow-cast only #81454

Merged
merged 30 commits into from
Feb 17, 2023
Merged
Changes from 17 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e05deac
Experiment with folding IND(GT_LCL_VAR_ADDR)
TIHan Feb 1, 2023
afdf056
Fix assertion
TIHan Feb 1, 2023
19f19ef
Remove duplicate code
TIHan Feb 1, 2023
c17e46c
Handling long types
TIHan Feb 1, 2023
343d827
Handling long types
TIHan Feb 1, 2023
3a141c0
Handling long types
TIHan Feb 1, 2023
af037ec
Handling long types
TIHan Feb 1, 2023
936dbae
Trying to fix build
TIHan Feb 1, 2023
69ff4b2
Trying to fix build
TIHan Feb 1, 2023
be3674c
Trying to fix builds
TIHan Feb 3, 2023
56dd025
Merge remote-tracking branch 'upstream/main' into fold-gt-lcl-var-addr
TIHan Feb 3, 2023
832666e
Added IndirTransform::CastOfLclVar
TIHan Feb 4, 2023
579b415
Fixing build
TIHan Feb 4, 2023
054c955
Some formatting
TIHan Feb 4, 2023
04429cb
Skip isDef
TIHan Feb 4, 2023
3a96f83
Formatting
TIHan Feb 4, 2023
9e12992
Fixed AV
TIHan Feb 4, 2023
e40b1b7
Enable long
TIHan Feb 6, 2023
e81aad1
Renamed CastOfLclVar to NarrowCastOfLclVar
TIHan Feb 7, 2023
a4b8bd8
Trying out wide-cast ind(lcl_var_addr) => cast(lcl_var)
TIHan Feb 7, 2023
8ebd1ef
Formatting
TIHan Feb 7, 2023
73ffc26
Remove widening
TIHan Feb 7, 2023
aa91384
Merge remote-tracking branch 'upstream/main' into fold-gt-lcl-var-addr
TIHan Feb 14, 2023
97b7bf1
Added a comment. Added disasm tests.
TIHan Feb 14, 2023
d48d744
Fixing tests
TIHan Feb 14, 2023
ccc56b1
Rename NarrowCastOfLclVar to NarrowCast
TIHan Feb 14, 2023
4ac5f4c
Feedback
TIHan Feb 15, 2023
7e695f3
Feedback
TIHan Feb 15, 2023
a3c0ab8
Merge remote-tracking branch 'upstream/main' into fold-gt-lcl-var-addr
TIHan Feb 15, 2023
93d81b6
Update src/coreclr/jit/lclmorph.cpp
TIHan Feb 15, 2023
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
43 changes: 41 additions & 2 deletions src/coreclr/jit/lclmorph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>
WithElement,
#endif // FEATURE_HW_INTRINSICS
LclVar,
LclFld
LclFld,
CastOfLclVar
};

ArrayStack<Value> m_valueStack;
Expand Down Expand Up @@ -1138,6 +1139,11 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>
unsigned lclNum = val.LclNum();
LclVarDsc* varDsc = m_compiler->lvaGetDesc(lclNum);
GenTreeLclVarCommon* lclNode = nullptr;
bool isDef = (user != nullptr) && user->OperIs(GT_ASG) && (user->AsOp()->gtGetOp1() == indir);

#ifdef DEBUG
bool removeIndir = false;
#endif // DEBUG
TIHan marked this conversation as resolved.
Show resolved Hide resolved

switch (transform)
{
Expand Down Expand Up @@ -1236,6 +1242,19 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>
lclNode = indir->AsLclVarCommon();
break;

case IndirTransform::CastOfLclVar:
assert(varTypeIsSmall(indir));
assert(varTypeIsIntegral(varDsc));
assert(*val.Use() == indir);
TIHan marked this conversation as resolved.
Show resolved Hide resolved
assert(!isDef);

#ifdef DEBUG
removeIndir = true;
#endif // DEBUG
lclNode = BashToLclVar(indir->gtGetOp1(), lclNum);
*val.Use() = m_compiler->gtNewCastNode(TYP_INT, lclNode, false, indir->TypeGet());
break;

case IndirTransform::LclFld:
indir->ChangeOper(GT_LCL_FLD);
indir->AsLclFld()->SetLclNum(lclNum);
Expand All @@ -1258,7 +1277,7 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>

GenTreeFlags lclNodeFlags = GTF_EMPTY;

if (user->OperIs(GT_ASG) && (user->AsOp()->gtGetOp1() == indir))
if (isDef)
{
lclNodeFlags |= (GTF_VAR_DEF | GTF_DONT_CSE);

Expand All @@ -1276,6 +1295,15 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>

lclNode->gtFlags = lclNodeFlags;
m_stmtModified = true;

#ifdef DEBUG
if (removeIndir)
{
DEBUG_DESTROY_NODE(indir);
}
#endif // DEBUG
TIHan marked this conversation as resolved.
Show resolved Hide resolved

return;
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -1333,6 +1361,15 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>
return IndirTransform::LclFld;
}

#ifdef TARGET_64BIT
if (!isDef && varTypeIsSmall(indir) && varTypeIsIntegral(varDsc) && !varTypeIsLong(varDsc))
#else // TARGET_64BIT
if (!isDef && varTypeIsSmall(indir) && varTypeIsIntegral(varDsc) && !varTypeIsLong(varDsc))
TIHan marked this conversation as resolved.
Show resolved Hide resolved
#endif // !TARGET_64BIT
{
return IndirTransform::CastOfLclVar;
}

#ifdef FEATURE_HW_INTRINSICS
if (varTypeIsSIMD(varDsc))
{
Expand Down Expand Up @@ -1502,6 +1539,8 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>
m_stmtModified = true;
}
}

return;
}

//------------------------------------------------------------------------
Expand Down