[llvm] [SLP] Bail out on store-to-load forwarding hazards (PR #199606)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 12 13:07:43 PDT 2026
================
@@ -28257,6 +28285,110 @@ bool SLPVectorizerPass::runImpl(Function &F, ScalarEvolution *SE_,
return Changed;
}
+bool BoUpSLP::findStoreLoadForwardingConflict(StoreInst *BaseStore,
+ unsigned VF) {
+ if (!BaseStore)
+ return false;
+
+ StoreInst *FirstStore = BaseStore;
+
+ // Memoize per (store, VF); the entry is re-costed repeatedly.
+ auto Key = std::make_pair(FirstStore, VF);
+ auto CacheIt = StlfConflictCache.find(Key);
+ if (CacheIt != StlfConflictCache.end())
+ return CacheIt->second;
+
+ auto CacheAndReturn = [&](bool Result) -> bool {
+ StlfConflictCache[Key] = Result;
+ // No conflict at VF implies none at any smaller VF that divides VF, so seed
+ // those entries too. The recency window is VF-independent (so it stays
+ // satisfied for any smaller width), and the distance remains a multiple of
+ // V * ElementSize only for divisors of VF. This covers the power-of-2
+ // ladder (each smaller power of 2 divides the larger) and any
+ // non-power-of-2 VF the caller may probe. Conflicts do not propagate
+ // downward.
+ if (!Result)
+ for (unsigned V = 2; V < VF; ++V)
+ if (VF % V == 0)
+ StlfConflictCache.try_emplace(std::make_pair(FirstStore, V), false);
+ return Result;
+ };
+
+ Type *ValueTy = FirstStore->getValueOperand()->getType();
+ TypeSize StoreSize = DL->getTypeStoreSize(ValueTy);
+ if (StoreSize.isScalable())
+ return CacheAndReturn(false);
+ uint64_t ElementSize = StoreSize.getFixedValue();
+ if (ElementSize == 0)
+ return CacheAndReturn(false);
+
+ // Store-to-load forwarding hazards are a loop-carried concern.
+ if (!LI->getLoopFor(FirstStore->getParent()))
----------------
alexey-bataev wrote:
```suggestion
const Loop *StoreL = LI->getLoopFor(FirstStore->getParent());
if (!StoreL)
```
https://github.com/llvm/llvm-project/pull/199606
More information about the llvm-commits
mailing list