[llvm] [CostModel][AArch64][ARM][AMDGPU] Add generic udiv/urem by power-2 costs (PR #126912)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 12 09:02:51 PST 2025


================
@@ -990,6 +990,17 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
       return LT.first * 2 * OpCost;
     }
 
+    // For a UDIV/UREM, if the operand is a power of 2 we can use the shift or
+    // and cost.
+    if (ISD == ISD::UDIV && Opd2Info.isPowerOf2())
+      return thisT()->getArithmeticInstrCost(Instruction::LShr, Ty, CostKind,
+                                             Opd1Info.getNoProps(),
+                                             Opd2Info.getNoProps());
+    if (ISD == ISD::UREM && Opd2Info.isPowerOf2())
+      return thisT()->getArithmeticInstrCost(Instruction::And, Ty, CostKind,
+                                             Opd1Info.getNoProps(),
+                                             Opd2Info.getNoProps());
----------------
arsenm wrote:

Why does this need to handle canonical IR? instcombine turns these into the shift already 

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


More information about the llvm-commits mailing list