Compiler::fgWalkResult PostOrderVisit(GenTree** use, GenTree* user)
{
m_treeSize++;
- GenTree* const node = *use;
+
+ GenTree* const node = *use;
+ bool const isDef = (user != nullptr) && user->OperIs(GT_ASG) && (user->gtGetOp1() == node);
if (node->OperIs(GT_LCL_VAR))
{
// Screen out contextual "uses"
//
GenTree* const parent = user;
- bool const isDef = parent->OperIs(GT_ASG) && (parent->gtGetOp1() == node);
bool const isAddr = parent->OperIs(GT_ADDR);
bool isCallTarget = false;
}
}
- if (node->OperIsLocal())
+ // Stores to and uses of address-exposed locals are modelled as global refs.
+ //
+ GenTree* lclNode = nullptr;
+ if (node->OperIsLocal() && !isDef)
{
- unsigned const lclNum = node->AsLclVarCommon()->GetLclNum();
-
- // Uses of address-exposed locals are modelled as global refs.
- //
- LclVarDsc* const varDsc = m_compiler->lvaGetDesc(lclNum);
+ lclNode = node;
+ }
+ else if (node->OperIs(GT_ASG) && node->gtGetOp1()->OperIsLocal())
+ {
+ lclNode = node->gtGetOp1();
+ }
- if (varDsc->IsAddressExposed())
- {
- m_accumulatedFlags |= GTF_GLOB_REF;
- }
+ if ((lclNode != nullptr) && m_compiler->lvaGetDesc(lclNode->AsLclVarCommon())->IsAddressExposed())
+ {
+ m_accumulatedFlags |= GTF_GLOB_REF;
}
m_accumulatedFlags |= (node->gtFlags & GTF_GLOB_EFFECT);