[llvm] SLP] Add store-to-load forwarding conflict cost for widened store chains (PR #199606)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 2 09:53:24 PDT 2026


================
@@ -18049,6 +18060,16 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
               BaseSI->getPointerAddressSpace(), CostKind, OpInfo);
         }
       }
+      // Widening this store chain can break store-to-load forwarding for a
+      // nearby loop-carried load. Rather than reject the tree outright, add
+      // the target's modeled STLF penalty so a chain that is still profitable
+      // after paying it can vectorize. The penalty is a throughput/latency
+      // hazard, so only account for it under those cost kinds.
+      if (EnableSLPStoreLoadForwardCheck && E->State == TreeEntry::Vectorize &&
+          (CostKind == TTI::TCK_RecipThroughput ||
+           CostKind == TTI::TCK_Latency) &&
+          findStoreLoadForwardingConflict(BaseSI, E->getVectorFactor()))
+        VecStCost += TTI->getStoreLoadForwardingConflictCost(VecTy, CostKind);
----------------
alexey-bataev wrote:

I think need to something similar to load cost case:
```
      // A widened load also breaks forwarding when it straddles recent
      // same-base stores that remain scalar (or are narrower than the load).
      if (EnableSLPStoreLoadForwardCheck &&
          E->State == TreeEntry::Vectorize &&
          (CostKind == TTI::TCK_RecipThroughput ||
           CostKind == TTI::TCK_Latency) &&
          findStoreLoadForwardingHazardForLoad(LI0, E->getVectorFactor()))
        VecLdCost += TTI->getStoreLoadForwardingConflictCost(VecTy, CostKind);
```

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


More information about the llvm-commits mailing list