Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10464,7 +10464,12 @@ bool GenTreeOp::UsesDivideByConstOptimized(Compiler* comp)
// x / -1 can't be optimized because INT_MIN / -1 is required to throw an exception.
return false;
}
else if (isPow2(divisorValue))
// Match the lowering acceptance for absolute value: lowering's TryLowerConstIntDivOrMod
// turns negative pow2 divisors into shift+neg and negative non-pow2 divisors into
// signed magic-divide sequences, both of which require the divisor be a literal.
size_t absDivisorValue = (divisorValue == SSIZE_T_MIN) ? static_cast<size_t>(divisorValue)
: static_cast<size_t>(std::abs(divisorValue));
if (isPow2(absDivisorValue))
{
return true;
}
Expand Down Expand Up @@ -10514,7 +10519,9 @@ bool GenTreeOp::UsesDivideByConstOptimized(Compiler* comp)

// TODO-ARM-CQ: Currently there's no GT_MULHI for ARM32
#if defined(TARGET_XARCH) || defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)
if (!comp->opts.MinOpts() && ((divisorValue >= 3) || !isSignedDivide))
// For signed divides also accept negative magic divisors (e.g. -3, -5); lowering generates
// a reciprocal-multiply sequence for those, see TryLowerConstIntDivOrMod.
if (!comp->opts.MinOpts() && (!isSignedDivide || (divisorValue >= 3) || (divisorValue <= -3)))
{
// All checks pass we can perform the division operation using a reciprocal multiply.
return true;
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11396,6 +11396,7 @@ GenTree* Compiler::fgMorphSmpOpOptional(GenTreeOp* tree, bool* optAssertionPropD
DEBUG_DESTROY_NODE(tree);
return op1;
}
tree->AsOp()->CheckDivideByConstOptimized(this);
Comment thread
AndyAyersMS marked this conversation as resolved.
break;

case GT_UDIV:
Expand Down
Loading