[llvm] [SelectionDAG][RISCV] Avoid store merging across function calls (PR #130430)

Mikhail R. Gadelha via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 17 08:25:18 PDT 2025


================
@@ -21553,6 +21553,56 @@ bool DAGCombiner::tryStoreMergeOfLoads(SmallVectorImpl<MemOpLink> &StoreNodes,
       JointMemOpVT = EVT::getIntegerVT(Context, SizeInBits);
     }
 
+    auto HasCallInLdStChain = [](SmallVectorImpl<MemOpLink> &StoreNodes,
+                                 SmallVectorImpl<MemOpLink> &LoadNodes,
+                                 unsigned NumStores) {
+      for (unsigned i = 0; i < NumStores; ++i) {
+        StoreSDNode *St = cast<StoreSDNode>(StoreNodes[i].MemNode);
+        SDValue Val = peekThroughBitcasts(St->getValue());
+        LoadSDNode *Ld = cast<LoadSDNode>(Val);
+        assert(Ld == LoadNodes[i].MemNode && "Load and store mismatch");
----------------
mikhailramalho wrote:

how about the following?
```
-        SDValue Val = peekThroughBitcasts(St->getValue());
-        LoadSDNode *Ld = cast<LoadSDNode>(Val);
-        assert(Ld == LoadNodes[i].MemNode && "Load and store mismatch");
+        LoadSDNode *Ld = cast<LoadSDNode>(LoadNodes[i].MemNode);
+        assert(Ld == cast<LoadSDNode>(peekThroughBitcasts(St->getValue())) &&
+               "Load and store mismatch");
```

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


More information about the llvm-commits mailing list