From af06645d6e8766991428c123a15c555f8c06d6fe Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Mon, 16 Jul 2018 18:48:24 -0700 Subject: [PATCH] JIT: fix value numbering to handle GT_NULLCHECK more generally (dotnet/coreclr#18942) With the advent of dotnet/coreclr#18819 we may now see GT_NULLCHECK nodes with operands that also can cause exceptions. Handle this in value numbering. Closes dotnet/coreclr#18937. Commit migrated from https://github.com/dotnet/coreclr/commit/2a4db3b265eccb9d56e3706d260237b3687da9ca --- src/coreclr/src/jit/valuenum.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/coreclr/src/jit/valuenum.cpp b/src/coreclr/src/jit/valuenum.cpp index 8b70757..a65a878 100644 --- a/src/coreclr/src/jit/valuenum.cpp +++ b/src/coreclr/src/jit/valuenum.cpp @@ -7033,13 +7033,18 @@ void Compiler::fgValueNumberTree(GenTree* tree, bool evalAsgLhsInd) break; case GT_NULLCHECK: + { // Explicit null check. - tree->gtVNPair = - vnStore->VNPWithExc(ValueNumPair(ValueNumStore::VNForVoid(), ValueNumStore::VNForVoid()), - vnStore->VNPExcSetSingleton( - vnStore->VNPairForFunc(TYP_REF, VNF_NullPtrExc, - tree->gtOp.gtOp1->gtVNPair))); - break; + // Handle case where operand tree also may cause exceptions. + ValueNumPair excSet = vnStore->VNPExcSetSingleton( + vnStore->VNPairForFunc(TYP_REF, VNF_NullPtrExc, + vnStore->VNPNormVal(tree->gtOp.gtOp1->gtVNPair))); + ValueNumPair excSetBoth = + vnStore->VNPExcSetUnion(excSet, vnStore->VNPExcVal(tree->gtOp.gtOp1->gtVNPair)); + + tree->gtVNPair = vnStore->VNPWithExc(vnStore->VNPForVoid(), excSetBoth); + } + break; case GT_LOCKADD: // Binop case GT_XADD: // Binop -- 2.7.4