[llvm] [AArch64][LV] Adjust costs for low-VF interleaved access (PR #209441)

Jacob Crawley via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 15 06:10:38 PDT 2026


================
@@ -5460,13 +5460,19 @@ InstructionCost AArch64TTIImpl::getInterleavedMemoryOpCost(
       }
 
       // llvm.vector.deinterleaveN is lowered as a binary tree of deinterleave2
-      // operations. A binary tree producing Factor leaf vectors has
-      // (Factor -1) inner deinterleave2 nodes. Each deinterleave2 on a pair of
-      // SVE registers emits one uzp1 + one uzp2.
-      // Total shuffle cost: (Factor - 1) deinterleave2 operations, each
-      // processing LT.first legal vector parts,with one uzp shuffle per part.
-      auto LT = getTypeLegalizationCost(VecTy);
-      return MemCost + (Factor - 1) * LT.first;
+      // operations. The tree has Log2(Factor) levels, with Factor UZP/ZIP
+      // operations at each level, giving a total shuffle cost of
+      // Factor * Log2(Factor).
+
+      // For stores, account for an additional legalization cost when
+      // repacking the legalized subvectors into the narrow interleaved
+      // vector.
+      auto LegalizationCost = getTypeLegalizationCost(SubVecTy).first;
+
+      if (Opcode == Instruction::Store)
+        LegalizationCost *= 2;
+
+      return MemCost + (Factor * LegalizationCost) + (Factor * Log2_64(Factor));
----------------
jacob-crawley wrote:

It's still the same value as `LT.first`. I've just defined the variable as the `.first` value directly rather than the pair, as that's the only value from `getTypeLegalizationCost` being used (and I thought `LegalizationCost` was a more descriptive name than `LT` for this purpose).

I've changed the variable type to explicitly define it as `llvm::InstructionCost` which should make its purpose clearer as this is in line with `MemCost`.

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


More information about the llvm-commits mailing list