[llvm] [LICM] Improve LICM when calls only change Inaccessible memory (PR #169379)
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 8 08:17:39 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;
+ }
// Disable hoisting past potentially interfering loads. Optimized
// Uses may point to an access outside the loop, as getClobbering
// checks the previous iteration when walking the backedge.
- // FIXME: More precise: no Uses that alias I.
- if (!Flags.getIsSink() && !MSSA->dominates(IMD, MU))
- return false;
+ if (!Flags.getIsSink() && !MSSA->dominates(IMD, MU)) {
----------------
paulwalker-arm wrote:
If [#187529](https://github.com/llvm/llvm-project/pull/187529) lands, doesn't that make this extension easier? We care about hoisting the only write to inaccessible memory within a loop, assuming there are no earlier reads of inaccessible memory within the same loop. I think that means only the new code in the `if (!MSSA->isLiveOnEntryDef(MD)...` block is relevant?
The `dyn_cast_or_null<MemoryDef>(MD)` check ensures there are no in-loop conflicting writes, because otherwise `MD` will be a `MemoryPhi`. The `MDI->getMemoryInst() != I)` check ensures we don't bail if the clobbering access is the instruction we're trying to hoist. At that point I think all that remains is checking whether `I` is loop invariant and thus safe to hoist, which given the context, I assume is already handled elsewhere.
https://github.com/llvm/llvm-project/pull/169379
More information about the llvm-commits
mailing list