[llvm] [X86][CostModel] Cost scalar integer divide/remainder by a constant (PR #211529)
Rito Takeuchi via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 23 07:42:32 PDT 2026
================
@@ -278,6 +278,21 @@ InstructionCost X86TTIImpl::getArithmeticInstrCost(
int ISD = TLI->InstructionOpcodeToISD(Opcode);
assert(ISD && "Invalid opcode");
+ // A scalar integer divide/remainder by a constant is not a hardware divide;
+ // it lowers to a magic-number multiply-high plus a few fixup ops. Cost it as
+ // that sequence rather than the generic single-instruction divide, so the
+ // vectorizers do not compare against an artificially cheap scalar lane.
+ // Power-of-two divisors lower to a shift and are left to the generic handling.
+ if (!Ty->isVectorTy() && Op2Info.isConstant() && !Op2Info.isPowerOf2() &&
----------------
Licht-T wrote:
Done. Moved it down next to the pow2 div/rem special cases (dropped the now-redundant `isPowerOf2` check, and kept `!isNegatedPowerOf2`). It's behavior-preserving: the `div`/`rem` cost tables regenerate with no diff.
https://github.com/llvm/llvm-project/pull/211529
More information about the llvm-commits
mailing list