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: Support some assignment decomposition in physical promotion #85105

Merged
Merged
2 changes: 2 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,7 @@ class LclVarDsc
unsigned short lvRefCnt(RefCountState state = RCS_NORMAL) const;
void incLvRefCnt(unsigned short delta, RefCountState state = RCS_NORMAL);
void setLvRefCnt(unsigned short newValue, RefCountState state = RCS_NORMAL);
void incLvRefCntSaturating(unsigned short delta, RefCountState state = RCS_NORMAL);

weight_t lvRefCntWtd(RefCountState state = RCS_NORMAL) const;
void incLvRefCntWtd(weight_t delta, RefCountState state = RCS_NORMAL);
Expand Down Expand Up @@ -2942,6 +2943,7 @@ class Compiler
static bool gtHasRef(GenTree* tree, unsigned lclNum);

bool gtHasLocalsWithAddrOp(GenTree* tree);
bool gtHasAddressExposedLocals(GenTree* tree);

unsigned gtSetCallArgsOrder(CallArgs* args, bool lateArgs, int* callCostEx, int* callCostSz);
unsigned gtSetMultiOpOrder(GenTreeMultiOp* multiOp);
Expand Down
22 changes: 20 additions & 2 deletions src/coreclr/jit/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4361,10 +4361,9 @@ inline unsigned short LclVarDsc::lvRefCnt(RefCountState state) const
// Notes:
// It is currently the caller's responsibility to ensure this increment
// will not cause overflow.

//
inline void LclVarDsc::incLvRefCnt(unsigned short delta, RefCountState state)
{

#if defined(DEBUG)
assert(state != RCS_INVALID);
Compiler* compiler = JitTls::GetCompiler();
Expand All @@ -4376,6 +4375,25 @@ inline void LclVarDsc::incLvRefCnt(unsigned short delta, RefCountState state)
assert(m_lvRefCnt >= oldRefCnt);
}

//------------------------------------------------------------------------------
// incLvRefCntSaturating: increment reference count for this local var (with saturating semantics)
//
// Arguments:
// delta: the amount of the increment
// state: the requestor's expected ref count state; defaults to RCS_NORMAL
//
inline void LclVarDsc::incLvRefCntSaturating(unsigned short delta, RefCountState state)
{
#if defined(DEBUG)
assert(state != RCS_INVALID);
Compiler* compiler = JitTls::GetCompiler();
assert(compiler->lvaRefCountState == state);
#endif

int newRefCnt = m_lvRefCnt + delta;
m_lvRefCnt = static_cast<unsigned short>(min(USHRT_MAX, newRefCnt));
}

//------------------------------------------------------------------------------
// setLvRefCnt: set the reference count for this local var
//
Expand Down
59 changes: 53 additions & 6 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2982,8 +2982,6 @@ bool Compiler::gtHasLocalsWithAddrOp(GenTree* tree)
DoLclVarsOnly = true,
};

bool HasAddrTakenLocal = false;

LocalsWithAddrOpVisitor(Compiler* comp) : GenTreeVisitor(comp)
{
}
Expand All @@ -2993,7 +2991,6 @@ bool Compiler::gtHasLocalsWithAddrOp(GenTree* tree)
LclVarDsc* varDsc = m_compiler->lvaGetDesc((*use)->AsLclVarCommon());
if (varDsc->lvHasLdAddrOp || varDsc->IsAddressExposed())
{
HasAddrTakenLocal = true;
return WALK_ABORT;
}

Expand All @@ -3002,8 +2999,48 @@ bool Compiler::gtHasLocalsWithAddrOp(GenTree* tree)
};

LocalsWithAddrOpVisitor visitor(this);
visitor.WalkTree(&tree, nullptr);
return visitor.HasAddrTakenLocal;
return visitor.WalkTree(&tree, nullptr) == WALK_ABORT;
}

//------------------------------------------------------------------------------
// gtHasAddressExposedLocal:
// Check if this tree contains locals with IsAddressExposed() flags set. Does
// a full tree walk.
//
// Paramters:
// tree - the tree
//
// Return Value:
// True if any sub tree is such a local.
//
bool Compiler::gtHasAddressExposedLocals(GenTree* tree)
{
struct Visitor : GenTreeVisitor<Visitor>
{
enum
{
DoPreOrder = true,
DoLclVarsOnly = true,
};

Visitor(Compiler* comp) : GenTreeVisitor(comp)
{
}

fgWalkResult PreOrderVisit(GenTree** use, GenTree* user)
{
LclVarDsc* varDsc = m_compiler->lvaGetDesc((*use)->AsLclVarCommon());
if (varDsc->IsAddressExposed())
{
return WALK_ABORT;
}

return WALK_CONTINUE;
}
};

Visitor visitor(this);
return visitor.WalkTree(&tree, nullptr) == WALK_ABORT;
}

#ifdef DEBUG
Expand Down Expand Up @@ -16353,7 +16390,17 @@ bool Compiler::gtSplitTree(

bool IsValue(const UseInfo& useInf)
{
GenTree* node = (*useInf.Use)->gtEffectiveVal();
GenTree* node = *useInf.Use;

// Some places create void-typed commas that wrap actual values
// (e.g. VN-based dead store removal), so we need the double check
// here.
if (!node->IsValue())
{
return false;
}

node = node->gtEffectiveVal();
if (!node->IsValue())
{
return false;
Expand Down
5 changes: 1 addition & 4 deletions src/coreclr/jit/lclmorph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1548,10 +1548,7 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>

// Note we don't need accurate counts when the values are large.
//
if (varDsc->lvRefCnt(RCS_EARLY) < USHRT_MAX)
{
varDsc->incLvRefCnt(1, RCS_EARLY);
}
varDsc->incLvRefCntSaturating(1, RCS_EARLY);

if (!m_compiler->lvaIsImplicitByRefLocal(lclNum))
{
Expand Down
Loading