[llvm] [X86][CostModel] Cost scalar integer divide/remainder by a constant (PR #211529)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 23 07:25:16 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() &&
----------------
RKSimon wrote:

Can move this down to be with the other div/rem special cases around line 361?

https://github.com/llvm/llvm-project/pull/211529


More information about the llvm-commits mailing list