diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index e82d187d5e889..a5639e536a7e4 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -8846,20 +8846,31 @@ void Compiler::fgValueNumberTree(GenTree* tree) // If this is a (full or partial) def we skip; it will be handled as part of the assignment. if ((lclFld->gtFlags & GTF_VAR_DEF) == 0) { - unsigned lclNum = lclFld->GetLclNum(); + unsigned lclNum = lclFld->GetLclNum(); + LclVarDsc* varDsc = lvaGetDesc(lclNum); - if (!lclFld->HasSsaName()) + if (lclFld->HasSsaName()) { - lclFld->gtVNPair.SetBoth(vnStore->VNForExpr(compCurBB, lclFld->TypeGet())); - } - else - { - LclVarDsc* varDsc = lvaGetDesc(lclNum); ValueNumPair lclVarValue = varDsc->GetPerSsaData(lclFld->GetSsaNum())->m_vnPair; lclFld->gtVNPair = vnStore->VNPairForLoad(lclVarValue, lvaLclExactSize(lclNum), lclFld->TypeGet(), lclFld->GetLclOffs(), lclFld->GetSize()); } + else if (varDsc->IsAddressExposed()) + { + // Address-exposed locals are part of ByrefExposed. + ValueNum addrVN = vnStore->VNForFunc(TYP_BYREF, VNF_PtrToLoc, vnStore->VNForIntCon(lclNum), + vnStore->VNForIntPtrCon(lclFld->GetLclOffs())); + ValueNum loadVN = fgValueNumberByrefExposedLoad(lclFld->TypeGet(), addrVN); + + lclFld->gtVNPair.SetLiberal(loadVN); + lclFld->gtVNPair.SetConservative(vnStore->VNForExpr(compCurBB, lclFld->TypeGet())); + } + else + { + // An untracked local, and other odd cases. + lclFld->gtVNPair.SetBoth(vnStore->VNForExpr(compCurBB, lclFld->TypeGet())); + } } else {