JIT: fix value numbering to handle GT_NULLCHECK more generally (#18942)
authorAndy Ayers <andya@microsoft.com>
Tue, 17 Jul 2018 01:48:24 +0000 (18:48 -0700)
committerGitHub <noreply@github.com>
Tue, 17 Jul 2018 01:48:24 +0000 (18:48 -0700)
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

index 8b70757..a65a878 100644 (file)
@@ -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