[llvm] [SLP] Invariant loads cannot have a memory dependency on stores. (PR #167929)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 13 13:28:11 PST 2025


================
@@ -21623,6 +21623,17 @@ void BoUpSLP::BlockScheduling::calculateDependencies(
       }
     }
 
+    // Helper to detect loads marked with !invariant.load metadata. Such loads
+    // are defined to read from memory that never changes for the lifetime of
+    // the program; any store to the same location would be UB. Therefore we
+    // can conservatively treat an invariant load and any store as non-aliasing
+    // for scheduling/dep purposes and skip creating a dependency edge.
+    auto IsInvariantLoad = [](const Instruction *I) {
+      if (const auto *LI = dyn_cast<LoadInst>(I))
+        return LI->getMetadata(LLVMContext::MD_invariant_load) != nullptr;
+      return false;
----------------
alexey-bataev wrote:

```
const auto *LI = dyn_cast<LoadInst>(I);
return LI && LI->getMetadata(LLVMContext::MD_invariant_load);
```

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


More information about the llvm-commits mailing list