[llvm] [AMDGPU] Implement LSR cost model for GFX9+ (PR #184138)

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 5 02:42:31 PST 2026


================
@@ -1703,3 +1704,50 @@ GCNTTIImpl::getInstructionUniformity(const Value *V) const {
 
   return InstructionUniformity::Default;
 }
+
+InstructionCost GCNTTIImpl::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
+                                                 StackOffset BaseOffset,
+                                                 bool HasBaseReg, int64_t Scale,
+                                                 unsigned AddrSpace) const {
+  if (HasBaseReg && Scale != 0) {
+    // gfx1250+ can fold base+scale*index into the instruction when scale
+    // equals the memory access size (scale_offset bit). Supported address
+    // spaces: flat, global, constant, private (scratch).
+    if (getST()->hasScaleOffset() && Ty && Ty->isSized() &&
----------------
michaelselehov wrote:

`isLegalAddressingMode` currently blocks Scale > 1 for SMEM and Scale > 0 for VMEM address spaces, and Scale=1 formulas are always beaten by pointer IVs in LSR. I don't see a way to write a meaningful test for this code path without changes to `isLegalAddressingMode`. I could add an expected-failure test if that would help.

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


More information about the llvm-commits mailing list