[llvm] [MergedLoadStore] Preserve common metadata when sinking stores. (PR #116382)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 15 05:39:54 PST 2024


================
@@ -255,7 +255,15 @@ void MergedLoadStoreMotion::sinkStoresAndGEPs(BasicBlock *BB, StoreInst *S0,
   BasicBlock::iterator InsertPt = BB->getFirstInsertionPt();
   // Intersect optional metadata.
   S0->andIRFlags(S1);
-  S0->dropUnknownNonDebugMetadata();
+
+  // Keep metadata present on both instructions.
+  SmallVector<std::pair<unsigned, MDNode *>> MDs;
+  S0->getAllMetadataOtherThanDebugLoc(MDs);
+  SmallVector<unsigned> CommonMDs;
+  for (const auto &[Kind, MD] : MDs)
+    if (S1->getMetadata(Kind) == MD)
+      CommonMDs.push_back(Kind);
+  S0->dropUnknownNonDebugMetadata(CommonMDs);
----------------
fhahn wrote:

Yeah updated. Originally thought this might not be completely right, but should be fine after a second thought, thanks!

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


More information about the llvm-commits mailing list