diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 947f774fbdac05..704cefdd27537b 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -10615,7 +10615,19 @@ void Compiler::fgValueNumberAddExceptionSetForIndirection(GenTree* tree, GenTree // The normal VN for base address is used to create the NullPtrExc ValueNumPair vnpBaseNorm = vnStore->VNPNormalPair(baseVNP); - ValueNumPair excChkSet = vnStore->VNPExcSetSingleton(vnStore->VNPairForFunc(TYP_REF, VNF_NullPtrExc, vnpBaseNorm)); + ValueNumPair excChkSet = vnStore->VNPForEmptyExcSet(); + + if (!vnStore->IsKnownNonNull(vnpBaseNorm.GetLiberal())) + { + excChkSet.SetLiberal( + vnStore->VNExcSetSingleton(vnStore->VNForFunc(TYP_REF, VNF_NullPtrExc, vnpBaseNorm.GetLiberal()))); + } + + if (!vnStore->IsKnownNonNull(vnpBaseNorm.GetConservative())) + { + excChkSet.SetConservative( + vnStore->VNExcSetSingleton(vnStore->VNForFunc(TYP_REF, VNF_NullPtrExc, vnpBaseNorm.GetConservative()))); + } // Add the NullPtrExc to "tree"'s value numbers. tree->gtVNPair = vnStore->VNPWithExc(tree->gtVNPair, excChkSet);