Proposed fix for 15671
authorBrian Sullivan <briansul@microsoft.com>
Sat, 6 Jan 2018 01:34:21 +0000 (17:34 -0800)
committerBrian Sullivan <briansul@microsoft.com>
Sat, 6 Jan 2018 01:37:29 +0000 (17:37 -0800)
If we are fetching an Array Length for an array ref that came from global memory
then for CSE safety we must use the conservative value number for both

src/jit/valuenum.cpp

index 4679a3c..1d50271 100644 (file)
@@ -6935,6 +6935,15 @@ void Compiler::fgValueNumberTree(GenTreePtr tree, bool evalAsgLhsInd)
                         ValueNumPair op1VNPx = ValueNumStore::VNPForEmptyExcSet();
                         vnStore->VNPUnpackExc(tree->gtOp.gtOp1->gtVNPair, &op1VNP, &op1VNPx);
 
+                        // If we are fetching the array length for an array ref that came from global memory
+                        // then for CSE safety we must use the conservative value number for both
+                        //
+                        if ((tree->OperGet() == GT_ARR_LENGTH) && ((tree->gtOp.gtOp1->gtFlags & GTF_GLOB_REF) != 0))
+                        {
+                            // use the conservative value number for both when computing the VN for the ARR_LENGTH
+                            op1VNP.SetBoth(op1VNP.GetConservative());
+                        }
+
                         tree->gtVNPair =
                             vnStore->VNPWithExc(vnStore->VNPairForFunc(tree->TypeGet(),
                                                                        GetVNFuncForOper(oper, (tree->gtFlags &