[llvm] [LICM] Improve LICM when calls only change Inaccessible memory (PR #169379)

via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 13 10:05:30 PDT 2026


================
@@ -2333,14 +2342,28 @@ static bool noConflictingReadWrites(Instruction *I, MemorySSA *MSSA,
       if (const auto *MU = dyn_cast<MemoryUse>(&MA)) {
         auto *MD = getClobberingMemoryAccess(*MSSA, BAA, Flags,
                                              const_cast<MemoryUse *>(MU));
-        if (!MSSA->isLiveOnEntryDef(MD) && CurLoop->contains(MD->getBlock()))
-          return false;
+
+        if (!MSSA->isLiveOnEntryDef(MD) && CurLoop->contains(MD->getBlock())) {
+          auto *MDI = dyn_cast_or_null<MemoryDef>(MD);
+          // It checks only if I is clobbering.
+          // If MDI is not the same as I (that it wants to hoist), assumes they
+          // clobber
+          if (!MDI || MDI->getMemoryInst() != I)
+            return false;
----------------
CarolineConcatto wrote:

So I have a test for you A and B scenario. Assuming that invariant_write and read could read the same position as invariant_write. 
A) hoist_untill_I
loop {
  invariant_write;
  read;
}

B) neg_hoist_untill_I
loop {
  read;
  invariant_write;
}


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


More information about the llvm-commits mailing list