[llvm] [RISCV] Set the reciprocal throughtput cost for division to TTI::TCC_Expensive (PR #177516)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 23 20:52:27 PST 2026


================
@@ -2607,15 +2610,27 @@ InstructionCost RISCVTTIImpl::getArithmeticInstrCost(
 
   // Legalize the type.
   std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty);
+  unsigned ISDOpcode = TLI->InstructionOpcodeToISD(Opcode);
 
   // TODO: Handle scalar type.
-  if (!LT.second.isVector())
+  if (!LT.second.isVector()) {
+    bool LegalOp = TLI->isOperationLegalOrPromote(ISDOpcode, LT.second);
+
+    static const CostTblEntry DivTbl[]{
+        {ISD::UDIV, MVT::i32, TTI::TCC_Expensive},
+        {ISD::UDIV, MVT::i64, TTI::TCC_Expensive},
+        {ISD::SDIV, MVT::i32, TTI::TCC_Expensive},
+        {ISD::SDIV, MVT::i64, TTI::TCC_Expensive}};
+    if (LegalOp)
+      if (const auto *Entry = CostTableLookup(DivTbl, ISDOpcode, LT.second))
----------------
lukel97 wrote:

If we don't expect the cost to change with the type we can probably avoid the table lookup and just do `if (ISDOpcode == ISD::UDIV || ISDOpcode == ISD::SDIV)` 

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


More information about the llvm-commits mailing list