[llvm] [CostModel][AArch64][ARM][AMDGPU] Add generic udiv/urem by power-2 costs (PR #126912)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 12 09:52:50 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());
----------------
davemgreen wrote:
It can come up from fshl costs and anything else that is checking the cost of a div/rem by a constant amount, that might or might not be power-2. i.e. hypothetical instructions, not real ones.
I could change the funnel shift cost directly and add this to aarch64/arm as needed. X86 already has this code, so gets better funnel shift costs. I get that it would cost a little bit of compile time for something that rarely comes up.
https://github.com/llvm/llvm-project/pull/126912
More information about the llvm-commits
mailing list