[llvm] [GVN] MemorySSA for GVN: eliminate redundant loads via MemorySSA (PR #152859)
Alina Sbirlea via llvm-commits
llvm-commits at lists.llvm.org
Thu May 7 09:33:24 PDT 2026
================
@@ -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;
----------------
alinas wrote:
Agreed, I think we're saying the same thing here :-). I think the second condition (`Clobber->getBlock() == SuccBB`) is sufficient here, there's no need to also check that Clobber is a MemoryDef.
https://github.com/llvm/llvm-project/pull/152859
More information about the llvm-commits
mailing list