@@ -13789,44 +13789,54 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac)
13789
13789
13790
13790
noway_assert(op1->TypeGet() == TYP_LONG && op1->OperGet() == GT_AND);
13791
13791
13792
- /* Is the result of the mask effectively an INT ? */
13793
-
13794
- GenTree* andMask;
13795
- andMask = op1->AsOp()->gtOp2;
13796
- if (andMask->gtOper != GT_CNS_NATIVELONG)
13797
- {
13798
- goto COMPARE;
13799
- }
13800
- if ((andMask->AsIntConCommon()->LngValue() >> 32) != 0)
13792
+ // The transform below cannot preserve VNs.
13793
+ if (fgGlobalMorph)
13801
13794
{
13802
- goto COMPARE;
13803
- }
13795
+ // Is the result of the mask effectively an INT ?
13804
13796
13805
- /* Now we know that we can cast AsOp()->gtOp1 of AND to int */
13797
+ GenTree* andMask = op1->AsOp()->gtOp2;
13798
+
13799
+ if (andMask->gtOper != GT_CNS_NATIVELONG)
13800
+ {
13801
+ goto COMPARE;
13802
+ }
13803
+ if ((andMask->AsIntConCommon()->LngValue() >> 32) != 0)
13804
+ {
13805
+ goto COMPARE;
13806
+ }
13806
13807
13807
- op1->AsOp()->gtOp1 = gtNewCastNode(TYP_INT, op1->AsOp()->gtOp1, false, TYP_INT);
13808
+ // Now we narrow AsOp()->gtOp1 of AND to int.
13809
+ if (optNarrowTree(op1->AsOp()->gtGetOp1(), TYP_LONG, TYP_INT, ValueNumPair(), false))
13810
+ {
13811
+ optNarrowTree(op1->AsOp()->gtGetOp1(), TYP_LONG, TYP_INT, ValueNumPair(), true);
13812
+ }
13813
+ else
13814
+ {
13815
+ op1->AsOp()->gtOp1 = gtNewCastNode(TYP_INT, op1->AsOp()->gtGetOp1(), false, TYP_INT);
13816
+ }
13808
13817
13809
- /* now replace the mask node (AsOp()->gtOp2 of AND node) */
13818
+ // now replace the mask node (AsOp()->gtOp2 of AND node).
13810
13819
13811
- noway_assert(andMask == op1->AsOp()->gtOp2);
13820
+ noway_assert(andMask == op1->AsOp()->gtOp2);
13812
13821
13813
- ival1 = (int)andMask->AsIntConCommon()->LngValue();
13814
- andMask->SetOper(GT_CNS_INT);
13815
- andMask->gtType = TYP_INT;
13816
- andMask->AsIntCon()->gtIconVal = ival1;
13822
+ ival1 = (int)andMask->AsIntConCommon()->LngValue();
13823
+ andMask->SetOper(GT_CNS_INT);
13824
+ andMask->gtType = TYP_INT;
13825
+ andMask->AsIntCon()->gtIconVal = ival1;
13817
13826
13818
- /* now change the type of the AND node */
13827
+ // now change the type of the AND node.
13819
13828
13820
- op1->gtType = TYP_INT;
13829
+ op1->gtType = TYP_INT;
13821
13830
13822
- /* finally we replace the comparand */
13831
+ // finally we replace the comparand.
13823
13832
13824
- ival2 = (int)cns2->AsIntConCommon()->LngValue();
13825
- cns2->SetOper(GT_CNS_INT);
13826
- cns2->gtType = TYP_INT;
13833
+ ival2 = (int)cns2->AsIntConCommon()->LngValue();
13834
+ cns2->SetOper(GT_CNS_INT);
13835
+ cns2->gtType = TYP_INT;
13827
13836
13828
- noway_assert(cns2 == op2);
13829
- cns2->AsIntCon()->gtIconVal = ival2;
13837
+ noway_assert(cns2 == op2);
13838
+ cns2->AsIntCon()->gtIconVal = ival2;
13839
+ }
13830
13840
13831
13841
goto COMPARE;
13832
13842
0 commit comments