From 2a4db3b265eccb9d56e3706d260237b3687da9ca 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 (#18942) With the advent of #18819 we may now see GT_NULLCHECK nodes with operands that also can cause exceptions. Handle this in value numbering. Closes #18937. --- src/jit/valuenum.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/jit/valuenum.cpp b/src/jit/valuenum.cpp index 8b70757..a65a878 100644 --- a/src/jit/valuenum.cpp +++ b/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