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

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 4 08:03:20 PST 2025


================
@@ -311,6 +311,14 @@ instructionClobbersQuery(const MemoryDef *MD, const MemoryLocation &UseLoc,
   }
 
   if (auto *CB = dyn_cast_or_null<CallBase>(UseInst)) {
+    if (auto *CU = dyn_cast_or_null<CallBase>(DefInst)) {
+      MemoryEffects CBME = CB->getMemoryEffects();
+      MemoryEffects CUME = CU->getMemoryEffects();
+      if (CBME.onlyAccessesInaccessibleMem() ||
+          CUME.onlyAccessesInaccessibleMem())
+        if ((CBME & CUME & MemoryEffects::writeOnly()).onlyReadsMemory())
+          return false;
----------------
paulwalker-arm wrote:

This logic looks invalid. I believe `instructionClobbersQuery` is asking the question "does MD clobber the location that UseInst reads". As InaccessibleMem is only a single bit, then by definition all calls that write it clobber later calls that read it.

What you're trying to do in https://github.com/llvm/llvm-project/pull/155590 is different because there we have multiple target memory regions where we can reason that writes to one are not visible to reads of another.

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


More information about the llvm-commits mailing list