Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some unneeded code from division morphing #53464

Merged
merged 3 commits into from
Jun 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 10 additions & 33 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12531,11 +12531,6 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac)
}
#endif
#endif // !TARGET_64BIT

if (op2->gtOper == GT_CAST && op2->AsOp()->gtOp1->IsCnsIntOrI())
SingleAccretion marked this conversation as resolved.
Show resolved Hide resolved
{
op2 = gtFoldExprConst(op2);
}
break;

case GT_UDIV:
Expand Down Expand Up @@ -12603,43 +12598,30 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac)
// 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);
}
SingleAccretion marked this conversation as resolved.
Show resolved Hide resolved

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);
Expand Down Expand Up @@ -12693,11 +12675,6 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac)
#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
Expand Down