[llvm] [SimplifyCFG] Preserve AA metadata when speculating stores (PR #227034)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 29 01:30:19 PDT 2026


================
@@ -3418,8 +3429,21 @@ bool SimplifyCFGOpt::speculativelyExecuteBB(CondBrInst *BI,
   for (auto &I : make_early_inc_range(*ThenBB)) {
     if (!SpeculatedStoreValue || &I != SpeculatedStore) {
       I.dropLocation();
+      I.dropUBImplyingAttrsAndMetadata();
+    } else {
+      // combineAAMetadata() made these safe on both paths above. Keep the
+      // resulting intersection while dropping all other UB-implying metadata.
+      static constexpr unsigned AAMetadata[] = {
----------------
david-arm wrote:

This seems a bit magic. How can we be sure that this will always be correct and maintained in future? It might be good to have a helper function (perhaps in the same place as `combineAAMetadata`) that returns a list of AA metadata that can be validly combined so that it accurately mirrors `combineAAMetadata`.

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


More information about the llvm-commits mailing list