Skip to content

Commit 675be65

Browse files
committed
Require chained analyses in BasicAA and AAResults to be transitive
This patch fixes a bug that could result in miscompiles (at least in an OOT target). The problem could be seen by adding checks that the DominatorTree used in BasicAliasAnalysis and ValueTracking was valid (e.g. by adding DT->verify() call before every DT dereference and then running all tests in test/CodeGen). Problem was that the LegacyPassManager calculated "last user" incorrectly for passes such as the DominatorTree when not telling the pass manager that there was a transitive dependency between the different analyses. And then it could happen that an incorrect dominator tree was used when doing alias analysis (which was a pretty serious bug as the alias analysis result could be invalid). Fixes: https://bugs.llvm.org/show_bug.cgi?id=48709 Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D94138
1 parent c5be0e0 commit 675be65

File tree

4 files changed

+5
-7
lines changed

4 files changed

+5
-7
lines changed

llvm/lib/Analysis/AliasAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,8 @@ bool AAResultsWrapperPass::runOnFunction(Function &F) {
883883

884884
void AAResultsWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
885885
AU.setPreservesAll();
886-
AU.addRequired<BasicAAWrapperPass>();
887-
AU.addRequired<TargetLibraryInfoWrapperPass>();
886+
AU.addRequiredTransitive<BasicAAWrapperPass>();
887+
AU.addRequiredTransitive<TargetLibraryInfoWrapperPass>();
888888

889889
// We also need to mark all the alias analysis passes we will potentially
890890
// probe in runOnFunction as used here to ensure the legacy pass manager

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,9 +1899,9 @@ bool BasicAAWrapperPass::runOnFunction(Function &F) {
18991899

19001900
void BasicAAWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
19011901
AU.setPreservesAll();
1902-
AU.addRequired<AssumptionCacheTracker>();
1903-
AU.addRequired<DominatorTreeWrapperPass>();
1904-
AU.addRequired<TargetLibraryInfoWrapperPass>();
1902+
AU.addRequiredTransitive<AssumptionCacheTracker>();
1903+
AU.addRequiredTransitive<DominatorTreeWrapperPass>();
1904+
AU.addRequiredTransitive<TargetLibraryInfoWrapperPass>();
19051905
AU.addUsedIfAvailable<PhiValuesWrapperPass>();
19061906
}
19071907

llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ class HexagonLoopIdiomRecognizeLegacyPass : public LoopPass {
165165
AU.addRequiredID(LoopSimplifyID);
166166
AU.addRequiredID(LCSSAID);
167167
AU.addRequired<AAResultsWrapperPass>();
168-
AU.addPreserved<AAResultsWrapperPass>();
169168
AU.addRequired<ScalarEvolutionWrapperPass>();
170169
AU.addRequired<DominatorTreeWrapperPass>();
171170
AU.addRequired<TargetLibraryInfoWrapperPass>();

llvm/lib/Transforms/Scalar/GVNHoist.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,6 @@ class GVNHoistLegacyPass : public FunctionPass {
547547
AU.addPreserved<DominatorTreeWrapperPass>();
548548
AU.addPreserved<MemorySSAWrapperPass>();
549549
AU.addPreserved<GlobalsAAWrapperPass>();
550-
AU.addPreserved<AAResultsWrapperPass>();
551550
}
552551
};
553552

0 commit comments

Comments
 (0)