Add missing opcodes for morph cast narrowing.
authorEugene Rozenfeld <erozen@microsoft.com>
Tue, 25 Apr 2017 20:38:39 +0000 (13:38 -0700)
committerEugene Rozenfeld <erozen@microsoft.com>
Tue, 25 Apr 2017 22:38:35 +0000 (15:38 -0700)
The narrowing can be applied to GT_SUB, GT_NOT, GT_NEG, and GT_LSH in addition to
GT_ADD, GT_MUL, GT_AND, GT_OR, and GT_XOR that were already supported.

src/jit/morph.cpp

index aad413d..07c09b5 100644 (file)
@@ -450,14 +450,16 @@ GenTreePtr Compiler::fgMorphCast(GenTreePtr tree)
             // For these operations the lower 32 bits of the result only depends
             // upon the lower 32 bits of the operands
             //
-            if ((oper->OperGet() == GT_ADD) || (oper->OperGet() == GT_MUL) || (oper->OperGet() == GT_AND) ||
-                (oper->OperGet() == GT_OR) || (oper->OperGet() == GT_XOR))
+            if (oper->OperIs(GT_ADD, GT_SUB, GT_MUL, GT_AND, GT_OR, GT_XOR, GT_NOT, GT_NEG, GT_LSH))
             {
                 DEBUG_DESTROY_NODE(tree);
 
                 // Insert narrowing casts for op1 and op2
                 oper->gtOp.gtOp1 = gtNewCastNode(TYP_INT, oper->gtOp.gtOp1, dstType);
-                oper->gtOp.gtOp2 = gtNewCastNode(TYP_INT, oper->gtOp.gtOp2, dstType);
+                if (oper->gtOp.gtOp2 != nullptr)
+                {
+                    oper->gtOp.gtOp2 = gtNewCastNode(TYP_INT, oper->gtOp.gtOp2, dstType);
+                }
 
                 // Clear the GT_MUL_64RSLT if it is set
                 if (oper->gtOper == GT_MUL && (oper->gtFlags & GTF_MUL_64RSLT))