From b3cab8d377833201000a88e4b00511eacee4524e Mon Sep 17 00:00:00 2001 From: SingleAccretion Date: Tue, 1 Feb 2022 12:50:53 +0300 Subject: [PATCH] Do not add NRE sets for non-null addresses --- src/coreclr/jit/valuenum.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 947f774fbdac0..704cefdd27537 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);