[GVNHoist] Use MemorySSA, drop MemoryDependenceAnalysis (NFCI) - #212773
Merged
antoniofrighetto merged 1 commit intoAug 3, 2026
Conversation
Finalize MemorySSA usage in GVNHoist, while transitioning away from MemoryDependenceAnalysis.
|
@llvm/pr-subscribers-llvm-transforms Author: Antonio Frighetto (antoniofrighetto) ChangesFinalize MemorySSA usage in GVNHoist, while transitioning away from MemoryDependenceAnalysis. Full diff: https://github.com/llvm/llvm-project/pull/212773.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Scalar/GVNHoist.cpp b/llvm/lib/Transforms/Scalar/GVNHoist.cpp
index 3022f4a8481d0..37562a024a2b0 100644
--- a/llvm/lib/Transforms/Scalar/GVNHoist.cpp
+++ b/llvm/lib/Transforms/Scalar/GVNHoist.cpp
@@ -43,7 +43,6 @@
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/IteratedDominanceFrontier.h"
-#include "llvm/Analysis/MemoryDependenceAnalysis.h"
#include "llvm/Analysis/MemorySSA.h"
#include "llvm/Analysis/MemorySSAUpdater.h"
#include "llvm/Analysis/PostDominators.h"
@@ -243,8 +242,8 @@ class CallInfo {
class GVNHoist {
public:
GVNHoist(DominatorTree *DT, PostDominatorTree *PDT, AliasAnalysis *AA,
- MemoryDependenceResults *MD, MemorySSA *MSSA)
- : DT(DT), PDT(PDT), AA(AA), MD(MD), MSSA(MSSA),
+ MemorySSA *MSSA)
+ : DT(DT), PDT(PDT), AA(AA), MSSA(MSSA),
MSSAUpdater(std::make_unique<MemorySSAUpdater>(MSSA)) {
MSSA->ensureOptimizedUses();
}
@@ -264,7 +263,6 @@ class GVNHoist {
DominatorTree *DT;
PostDominatorTree *PDT;
AliasAnalysis *AA;
- MemoryDependenceResults *MD;
MemorySSA *MSSA;
std::unique_ptr<MemorySSAUpdater> MSSAUpdater;
DenseMap<const Value *, unsigned> DFSNumber;
@@ -507,7 +505,8 @@ bool GVNHoist::run(Function &F) {
NumFuncArgs = F.arg_size();
VN.setDomTree(DT);
VN.setAliasAnalysis(AA);
- VN.setMemDep(MD);
+ // TODO: Is this actually needed?
+ VN.setMemorySSA(MSSA, true);
bool Res = false;
// Perform DFS Numbering of instructions.
unsigned BBI = 0;
@@ -980,13 +979,13 @@ unsigned GVNHoist::rauw(const SmallVecInsn &Candidates, Instruction *Repl,
MemoryAccess *OldMA = MSSA->getMemoryAccess(I);
OldMA->replaceAllUsesWith(NewMemAcc);
MSSAUpdater->removeMemoryAccess(OldMA);
+ } else if (MemoryAccess *OldMA = MSSA->getMemoryAccess(I)) {
+ MSSAUpdater->removeMemoryAccess(OldMA);
}
combineMetadataForCSE(Repl, I, true);
Repl->andIRFlags(I);
I->replaceAllUsesWith(Repl);
- // Also invalidate the Alias Analysis cache.
- MD->removeInstruction(I);
I->eraseFromParent();
}
}
@@ -1106,7 +1105,8 @@ std::pair<unsigned, unsigned> GVNHoist::hoist(HoistingPointList &HPL) {
// Move the instruction at the end of HoistPt.
Instruction *Last = DestBB->getTerminator();
- MD->removeInstruction(Repl);
+ if (auto *MUD = MSSA->getMemoryAccess(Repl))
+ MSSAUpdater->moveToPlace(MUD, DestBB, MemorySSA::BeforeTerminator);
Repl->moveBefore(Last->getIterator());
DFSNumber[Repl] = DFSNumber[Last]++;
@@ -1202,9 +1202,8 @@ PreservedAnalyses GVNHoistPass::run(Function &F, FunctionAnalysisManager &AM) {
DominatorTree &DT = AM.getResult<DominatorTreeAnalysis>(F);
PostDominatorTree &PDT = AM.getResult<PostDominatorTreeAnalysis>(F);
AliasAnalysis &AA = AM.getResult<AAManager>(F);
- MemoryDependenceResults &MD = AM.getResult<MemoryDependenceAnalysis>(F);
MemorySSA &MSSA = AM.getResult<MemorySSAAnalysis>(F).getMSSA();
- GVNHoist G(&DT, &PDT, &AA, &MD, &MSSA);
+ GVNHoist G(&DT, &PDT, &AA, &MSSA);
if (!G.run(F))
return PreservedAnalyses::all();
|
alinas
approved these changes
Jul 30, 2026
frederik-h
pushed a commit
to frederik-h/llvm-project
that referenced
this pull request
Aug 3, 2026
…212773) Finalize MemorySSA usage in GVNHoist, while transitioning away from MemoryDependenceAnalysis.
jgreenbaum
pushed a commit
to jgreenbaum/llvm-project
that referenced
this pull request
Aug 3, 2026
…212773) Finalize MemorySSA usage in GVNHoist, while transitioning away from MemoryDependenceAnalysis.
tfzee
pushed a commit
to tfzee/llvm-project
that referenced
this pull request
Aug 6, 2026
…212773) Finalize MemorySSA usage in GVNHoist, while transitioning away from MemoryDependenceAnalysis.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Finalize MemorySSA usage in GVNHoist, while transitioning away from MemoryDependenceAnalysis.