[llvm] [SLP]Charge extract latency for extracts feeding memory addresses (PR #224634)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 20 09:11:57 PDT 2026


================
@@ -20052,6 +20080,17 @@ InstructionCost BoUpSLP::getTreeCost(InstructionCost TreeCost,
     // existing ScaleCost path (user-block based) remains correct, since the
     // scalar instruction executes at its definition site's frequency.
     if (!ExternalUsesAsOriginalScalar.contains(EU.Scalar)) {
+      // An extract feeding a memory address is on the critical path to that
+      // access, so its latency is exposed rather than hidden by parallelism;
+      // charge the extraction latency, not the throughput. Not applied for
+      // code size: the number of emitted extracts does not change.
+      if (CostKind != TTI::TCK_CodeSize && IsExtractOnAddressPath(EU.Scalar)) {
+        InstructionCost LatencyCost = GetExtractCost(TTI::TCK_Latency);
+        if (LatencyCost.isValid())
+          ExtraCost = std::max(ExtraCost, LatencyCost);
+        LLVM_DEBUG(dbgs() << "  Extract on address path cost: " << ExtraCost
----------------
RKSimon wrote:

I'm never very comfortable adding InstructionCost from different CostKind together - is this really necessary?

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


More information about the llvm-commits mailing list