[llvm] [GVN] MemorySSA for GVN: eliminate redundant loads via MemorySSA (PR #152859)
Antonio Frighetto via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 20 12:33:57 PDT 2025
================
@@ -1545,12 +1559,24 @@ LoadInst *GVNPass::findLoadToHoistIntoPred(BasicBlock *Pred, BasicBlock *LoadBB,
if (!Inst.isIdenticalTo(Load))
continue;
- MemDepResult Dep = MD->getDependency(&Inst);
+ bool HasLocalDep = true;
+ if (MD && !MSSAU) {
+ MemDepResult Dep = MD->getDependency(&Inst);
+ HasLocalDep = !Dep.isNonLocal();
+ } else {
+ auto *MSSA = MSSAU->getMemorySSA();
+ // Do not hoist if the identical load has ordering constraint.
+ if (auto *MA = MSSA->getMemoryAccess(&Inst); MA && isa<MemoryUse>(MA)) {
+ auto *Clobber = MSSA->getWalker()->getClobberingMemoryAccess(MA);
+ HasLocalDep = isa<MemoryDef>(Clobber) && Clobber->getBlock() == SuccBB;
----------------
antoniofrighetto wrote:
This is a recent addition. If not missing anything, it should suffice to check whether the identical load has a local dominating clobber, in order not to be hoisted.
https://github.com/llvm/llvm-project/pull/152859
More information about the llvm-commits
mailing list