}
#endif
#endif // !TARGET_64BIT
-
- if (op2->gtOper == GT_CAST && op2->AsOp()->gtOp1->IsCnsIntOrI())
- {
- op2 = gtFoldExprConst(op2);
- }
break;
case GT_UDIV:
// Note for TARGET_ARMARCH we don't have a remainder instruction, so we don't do this optimization
//
#else // TARGET_XARCH
- /* If this is an unsigned long mod with op2 which is a cast to long from a
- constant int, then don't morph to a call to the helper. This can be done
- faster inline using idiv.
- */
+ // If this is an unsigned long mod with a constant divisor,
+ // then don't morph to a helper call - it can be done faster inline using idiv.
noway_assert(op2);
- if ((typ == TYP_LONG) && opts.OptEnabled(CLFLG_CONSTANTFOLD) &&
- ((tree->gtFlags & GTF_UNSIGNED) == (op1->gtFlags & GTF_UNSIGNED)) &&
- ((tree->gtFlags & GTF_UNSIGNED) == (op2->gtFlags & GTF_UNSIGNED)))
+ if ((typ == TYP_LONG) && opts.OptEnabled(CLFLG_CONSTANTFOLD))
{
- if (op2->gtOper == GT_CAST && op2->AsCast()->CastOp()->gtOper == GT_CNS_INT &&
- op2->AsCast()->CastOp()->AsIntCon()->gtIconVal >= 2 &&
- op2->AsCast()->CastOp()->AsIntCon()->gtIconVal <= 0x3fffffff &&
- (tree->gtFlags & GTF_UNSIGNED) == (op2->AsCast()->CastOp()->gtFlags & GTF_UNSIGNED))
- {
- tree->AsOp()->gtOp2 = op2 = fgMorphCast(op2);
- noway_assert(op2->gtOper == GT_CNS_NATIVELONG);
- }
-
- if (op2->gtOper == GT_CNS_NATIVELONG && op2->AsIntConCommon()->LngValue() >= 2 &&
+ if (op2->OperIs(GT_CNS_NATIVELONG) && op2->AsIntConCommon()->LngValue() >= 2 &&
op2->AsIntConCommon()->LngValue() <= 0x3fffffff)
{
tree->AsOp()->gtOp1 = op1 = fgMorphTree(op1);
- noway_assert(op1->TypeGet() == TYP_LONG);
+ noway_assert(op1->TypeIs(TYP_LONG));
- // Update flags for op1 morph
+ // Update flags for op1 morph.
tree->gtFlags &= ~GTF_ALL_EFFECT;
- tree->gtFlags |= (op1->gtFlags & GTF_ALL_EFFECT); // Only update with op1 as op2 is a constant
+ // Only update with op1 as op2 is a constant.
+ tree->gtFlags |= (op1->gtFlags & GTF_ALL_EFFECT);
- // If op1 is a constant, then do constant folding of the division operator
- if (op1->gtOper == GT_CNS_NATIVELONG)
+ // If op1 is a constant, then do constant folding of the division operator.
+ if (op1->OperIs(GT_CNS_NATIVELONG))
{
tree = gtFoldExpr(tree);
}
- // We may fail to fold
if (!tree->OperIsConst())
{
tree->AsOp()->CheckDivideByConstOptimized(this);
#endif
#endif // !TARGET_64BIT
- if (op2->gtOper == GT_CAST && op2->AsOp()->gtOp1->IsCnsIntOrI())
- {
- op2 = gtFoldExprConst(op2);
- }
-
#ifdef TARGET_ARM64
// For ARM64 we don't have a remainder instruction,
// The architecture manual suggests the following transformation to