[llvm] f8bd0be - [AssumeBundleBuilder] Fix PreservedAnalyses reporting
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 14 09:28:15 PDT 2023
Author: Arthur Eubanks
Date: 2023-03-14T09:28:00-07:00
New Revision: f8bd0be602947c7b03dca744a27585cb5a08e548
URL: https://github.com/llvm/llvm-project/commit/f8bd0be602947c7b03dca744a27585cb5a08e548
DIFF: https://github.com/llvm/llvm-project/commit/f8bd0be602947c7b03dca744a27585cb5a08e548.diff
LOG: [AssumeBundleBuilder] Fix PreservedAnalyses reporting
These weren't properly reporting changes.
Added:
Modified:
llvm/include/llvm/Transforms/Utils/AssumeBundleBuilder.h
llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/Utils/AssumeBundleBuilder.h b/llvm/include/llvm/Transforms/Utils/AssumeBundleBuilder.h
index 991ecb8efbd07..30752e9cd79fc 100644
--- a/llvm/include/llvm/Transforms/Utils/AssumeBundleBuilder.h
+++ b/llvm/include/llvm/Transforms/Utils/AssumeBundleBuilder.h
@@ -40,7 +40,8 @@ AssumeInst *buildAssumeFromInst(Instruction *I);
/// become silently be invalid.
/// The DominatorTree can optionally be provided to enable cross-block
/// reasoning.
-void salvageKnowledge(Instruction *I, AssumptionCache *AC = nullptr,
+/// This returns if a change was made.
+bool salvageKnowledge(Instruction *I, AssumptionCache *AC = nullptr,
DominatorTree *DT = nullptr);
/// Build and return a new assume created from the provided knowledge
diff --git a/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp b/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
index d17c399ba7989..7eb615e90b177 100644
--- a/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
+++ b/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
@@ -290,17 +290,20 @@ AssumeInst *llvm::buildAssumeFromInst(Instruction *I) {
return Builder.build();
}
-void llvm::salvageKnowledge(Instruction *I, AssumptionCache *AC,
+bool llvm::salvageKnowledge(Instruction *I, AssumptionCache *AC,
DominatorTree *DT) {
if (!EnableKnowledgeRetention || I->isTerminator())
- return;
+ return false;
+ bool Changed = false;
AssumeBuilderState Builder(I->getModule(), I, AC, DT);
Builder.addInstruction(I);
if (auto *Intr = Builder.build()) {
Intr->insertBefore(I);
+ Changed = true;
if (AC)
AC->registerAssumption(Intr);
}
+ return Changed;
}
AssumeInst *
@@ -563,9 +566,12 @@ PreservedAnalyses AssumeSimplifyPass::run(Function &F,
FunctionAnalysisManager &AM) {
if (!EnableKnowledgeRetention)
return PreservedAnalyses::all();
- simplifyAssumes(F, &AM.getResult<AssumptionAnalysis>(F),
- AM.getCachedResult<DominatorTreeAnalysis>(F));
- return PreservedAnalyses::all();
+ if (!simplifyAssumes(F, &AM.getResult<AssumptionAnalysis>(F),
+ AM.getCachedResult<DominatorTreeAnalysis>(F)))
+ return PreservedAnalyses::all();
+ PreservedAnalyses PA;
+ PA.preserveSet<CFGAnalyses>();
+ return PA;
}
namespace {
@@ -611,9 +617,14 @@ PreservedAnalyses AssumeBuilderPass::run(Function &F,
FunctionAnalysisManager &AM) {
AssumptionCache *AC = &AM.getResult<AssumptionAnalysis>(F);
DominatorTree* DT = AM.getCachedResult<DominatorTreeAnalysis>(F);
+ bool Changed = false;
for (Instruction &I : instructions(F))
- salvageKnowledge(&I, AC, DT);
- return PreservedAnalyses::all();
+ Changed |= salvageKnowledge(&I, AC, DT);
+ if (!Changed)
+ PreservedAnalyses::all();
+ PreservedAnalyses PA;
+ PA.preserveSet<CFGAnalyses>();
+ return PA;
}
namespace {
More information about the llvm-commits
mailing list