Merge pull request #10958 from pgavlin/VSO397793
authorPat Gavlin <pgavlin@gmail.com>
Sat, 15 Apr 2017 05:16:44 +0000 (22:16 -0700)
committerGitHub <noreply@github.com>
Sat, 15 Apr 2017 05:16:44 +0000 (22:16 -0700)
Preserve VNs in fgMorphIntoHelperCall.

1  2 
src/jit/morph.cpp

diff --combined src/jit/morph.cpp
@@@ -60,7 -60,8 +60,8 @@@ GenTreePtr Compiler::fgMorphCastIntoHel
  
  GenTreePtr Compiler::fgMorphIntoHelperCall(GenTreePtr tree, int helper, GenTreeArgList* args)
  {
-     tree->ChangeOper(GT_CALL);
+     // The helper call ought to be semantically equivalent to the original node, so preserve its VN.
+     tree->ChangeOper(GT_CALL, GenTree::PRESERVE_VN);
  
      tree->gtFlags |= GTF_CALL;
      if (args)
@@@ -11416,20 -11417,6 +11417,20 @@@ GenTreePtr Compiler::fgMorphSmpOp(GenTr
                  }
              }
  
 +            // If gtOp1 is a GT_FIELD, we need to pass down the mac if
 +            // its parent is GT_ADDR, since the address of the field
 +            // is part of an ongoing address computation. Otherwise
 +            // op1 represents the value of the field and so any address
 +            // calculations it does are in a new context.
 +            if ((op1->gtOper == GT_FIELD) && (tree->gtOper != GT_ADDR))
 +            {
 +                subMac1 = nullptr;
 +
 +                // The impact of this field's value to any ongoing
 +                // address computation is handled below when looking
 +                // at op2.
 +            }
 +
              tree->gtOp.gtOp1 = op1 = fgMorphTree(op1, subMac1);
  
  #if LOCAL_ASSERTION_PROP
              // (These are used to convey parent context about how addresses being calculated
              // will be used; see the specification comment for MorphAddrContext for full details.)
              // Assume it's an Ind context to start.
 -            MorphAddrContext subIndMac2(MACK_Ind);
              switch (tree->gtOper)
              {
                  case GT_ADD:
                  default:
                      break;
              }
 +
 +            // If gtOp2 is a GT_FIELD, we must be taking its value,
 +            // so it should evaluate its address in a new context.
 +            if (op2->gtOper == GT_FIELD)
 +            {
 +                // The impact of this field's value to any ongoing
 +                // address computation is handled above when looking
 +                // at op1.
 +                mac = nullptr;
 +            }
 +
              tree->gtOp.gtOp2 = op2 = fgMorphTree(op2, mac);
  
              /* Propagate the side effect flags from op2 */