[llvm] a78d8fe - [LowerConstantIntrinsics] Preserve Dominator Tree, if avaliable
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 29 14:16:34 PST 2021
Author: Roman Lebedev
Date: 2021-01-30T01:14:50+03:00
New Revision: a78d8feb48a536f50736f97a9ae28d5bae94e8ed
URL: https://github.com/llvm/llvm-project/commit/a78d8feb48a536f50736f97a9ae28d5bae94e8ed
DIFF: https://github.com/llvm/llvm-project/commit/a78d8feb48a536f50736f97a9ae28d5bae94e8ed.diff
LOG: [LowerConstantIntrinsics] Preserve Dominator Tree, if avaliable
Added:
Modified:
llvm/lib/Transforms/Scalar/LowerConstantIntrinsics.cpp
llvm/test/CodeGen/AMDGPU/opt-pipeline.ll
llvm/test/Other/opt-O2-pipeline.ll
llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
llvm/test/Other/opt-O3-pipeline.ll
llvm/test/Other/opt-Os-pipeline.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/LowerConstantIntrinsics.cpp b/llvm/lib/Transforms/Scalar/LowerConstantIntrinsics.cpp
index bfe8db83b027..0890437fd90c 100644
--- a/llvm/lib/Transforms/Scalar/LowerConstantIntrinsics.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerConstantIntrinsics.cpp
@@ -15,12 +15,14 @@
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/Analysis/DomTreeUpdater.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
+#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
@@ -50,7 +52,8 @@ static Value *lowerIsConstantIntrinsic(IntrinsicInst *II) {
}
static bool replaceConditionalBranchesOnConstant(Instruction *II,
- Value *NewValue) {
+ Value *NewValue,
+ DomTreeUpdater *DTU) {
bool HasDeadBlocks = false;
SmallSetVector<Instruction *, 8> Worklist;
replaceAndRecursivelySimplify(II, NewValue, nullptr, nullptr, nullptr,
@@ -78,6 +81,8 @@ static bool replaceConditionalBranchesOnConstant(Instruction *II,
Other->removePredecessor(Source);
BI->eraseFromParent();
BranchInst::Create(Target, Source);
+ if (DTU)
+ DTU->applyUpdates({{DominatorTree::Delete, Source, Other}});
if (pred_empty(Other))
HasDeadBlocks = true;
}
@@ -85,7 +90,12 @@ static bool replaceConditionalBranchesOnConstant(Instruction *II,
return HasDeadBlocks;
}
-static bool lowerConstantIntrinsics(Function &F, const TargetLibraryInfo *TLI) {
+static bool lowerConstantIntrinsics(Function &F, const TargetLibraryInfo *TLI,
+ DominatorTree *DT) {
+ Optional<DomTreeUpdater> DTU;
+ if (DT)
+ DTU.emplace(DT, DomTreeUpdater::UpdateStrategy::Lazy);
+
bool HasDeadBlocks = false;
const auto &DL = F.getParent()->getDataLayout();
SmallVector<WeakTrackingVH, 8> Worklist;
@@ -128,19 +138,21 @@ static bool lowerConstantIntrinsics(Function &F, const TargetLibraryInfo *TLI) {
ObjectSizeIntrinsicsHandled++;
break;
}
- HasDeadBlocks |= replaceConditionalBranchesOnConstant(II, NewValue);
+ HasDeadBlocks |= replaceConditionalBranchesOnConstant(
+ II, NewValue, DTU.hasValue() ? DTU.getPointer() : nullptr);
}
if (HasDeadBlocks)
- removeUnreachableBlocks(F);
+ removeUnreachableBlocks(F, DTU.hasValue() ? DTU.getPointer() : nullptr);
return !Worklist.empty();
}
PreservedAnalyses
LowerConstantIntrinsicsPass::run(Function &F, FunctionAnalysisManager &AM) {
- if (lowerConstantIntrinsics(F,
- AM.getCachedResult<TargetLibraryAnalysis>(F))) {
+ if (lowerConstantIntrinsics(F, AM.getCachedResult<TargetLibraryAnalysis>(F),
+ AM.getCachedResult<DominatorTreeAnalysis>(F))) {
PreservedAnalyses PA;
PA.preserve<GlobalsAA>();
+ PA.preserve<DominatorTreeAnalysis>();
return PA;
}
@@ -163,18 +175,25 @@ class LowerConstantIntrinsics : public FunctionPass {
bool runOnFunction(Function &F) override {
auto *TLIP = getAnalysisIfAvailable<TargetLibraryInfoWrapperPass>();
const TargetLibraryInfo *TLI = TLIP ? &TLIP->getTLI(F) : nullptr;
- return lowerConstantIntrinsics(F, TLI);
+ DominatorTree *DT = nullptr;
+ if (auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>())
+ DT = &DTWP->getDomTree();
+ return lowerConstantIntrinsics(F, TLI, DT);
}
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addPreserved<GlobalsAAWrapperPass>();
+ AU.addPreserved<DominatorTreeWrapperPass>();
}
};
} // namespace
char LowerConstantIntrinsics::ID = 0;
-INITIALIZE_PASS(LowerConstantIntrinsics, "lower-constant-intrinsics",
- "Lower constant intrinsics", false, false)
+INITIALIZE_PASS_BEGIN(LowerConstantIntrinsics, "lower-constant-intrinsics",
+ "Lower constant intrinsics", false, false)
+INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
+INITIALIZE_PASS_END(LowerConstantIntrinsics, "lower-constant-intrinsics",
+ "Lower constant intrinsics", false, false)
FunctionPass *llvm::createLowerConstantIntrinsicsPass() {
return new LowerConstantIntrinsics();
diff --git a/llvm/test/CodeGen/AMDGPU/opt-pipeline.ll b/llvm/test/CodeGen/AMDGPU/opt-pipeline.ll
index 54f6ac172936..b9df53020bd4 100644
--- a/llvm/test/CodeGen/AMDGPU/opt-pipeline.ll
+++ b/llvm/test/CodeGen/AMDGPU/opt-pipeline.ll
@@ -208,7 +208,6 @@
; GCN-O1-NEXT: Dominator Tree Construction
; GCN-O1-NEXT: Float to int
; GCN-O1-NEXT: Lower constant intrinsics
-; GCN-O1-NEXT: Dominator Tree Construction
; GCN-O1-NEXT: Natural Loop Information
; GCN-O1-NEXT: Canonicalize natural loops
; GCN-O1-NEXT: LCSSA Verifier
@@ -560,7 +559,6 @@
; GCN-O2-NEXT: Dominator Tree Construction
; GCN-O2-NEXT: Float to int
; GCN-O2-NEXT: Lower constant intrinsics
-; GCN-O2-NEXT: Dominator Tree Construction
; GCN-O2-NEXT: Natural Loop Information
; GCN-O2-NEXT: Canonicalize natural loops
; GCN-O2-NEXT: LCSSA Verifier
@@ -924,7 +922,6 @@
; GCN-O3-NEXT: Dominator Tree Construction
; GCN-O3-NEXT: Float to int
; GCN-O3-NEXT: Lower constant intrinsics
-; GCN-O3-NEXT: Dominator Tree Construction
; GCN-O3-NEXT: Natural Loop Information
; GCN-O3-NEXT: Canonicalize natural loops
; GCN-O3-NEXT: LCSSA Verifier
diff --git a/llvm/test/Other/opt-O2-pipeline.ll b/llvm/test/Other/opt-O2-pipeline.ll
index 7d7934e6e4ab..8899030ecb47 100644
--- a/llvm/test/Other/opt-O2-pipeline.ll
+++ b/llvm/test/Other/opt-O2-pipeline.ll
@@ -204,7 +204,6 @@
; CHECK-NEXT: Dominator Tree Construction
; CHECK-NEXT: Float to int
; CHECK-NEXT: Lower constant intrinsics
-; CHECK-NEXT: Dominator Tree Construction
; CHECK-NEXT: Natural Loop Information
; CHECK-NEXT: Canonicalize natural loops
; CHECK-NEXT: LCSSA Verifier
diff --git a/llvm/test/Other/opt-O3-pipeline-enable-matrix.ll b/llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
index bd77a8bac87c..85a251d726b9 100644
--- a/llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
+++ b/llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
@@ -209,7 +209,6 @@
; CHECK-NEXT: Dominator Tree Construction
; CHECK-NEXT: Float to int
; CHECK-NEXT: Lower constant intrinsics
-; CHECK-NEXT: Dominator Tree Construction
; CHECK-NEXT: Natural Loop Information
; CHECK-NEXT: Lazy Branch Probability Analysis
; CHECK-NEXT: Lazy Block Frequency Analysis
diff --git a/llvm/test/Other/opt-O3-pipeline.ll b/llvm/test/Other/opt-O3-pipeline.ll
index 85f25363d232..d907aa5a69a6 100644
--- a/llvm/test/Other/opt-O3-pipeline.ll
+++ b/llvm/test/Other/opt-O3-pipeline.ll
@@ -209,7 +209,6 @@
; CHECK-NEXT: Dominator Tree Construction
; CHECK-NEXT: Float to int
; CHECK-NEXT: Lower constant intrinsics
-; CHECK-NEXT: Dominator Tree Construction
; CHECK-NEXT: Natural Loop Information
; CHECK-NEXT: Canonicalize natural loops
; CHECK-NEXT: LCSSA Verifier
diff --git a/llvm/test/Other/opt-Os-pipeline.ll b/llvm/test/Other/opt-Os-pipeline.ll
index 6d42b39fb8a5..2cfb093c49cc 100644
--- a/llvm/test/Other/opt-Os-pipeline.ll
+++ b/llvm/test/Other/opt-Os-pipeline.ll
@@ -190,7 +190,6 @@
; CHECK-NEXT: Dominator Tree Construction
; CHECK-NEXT: Float to int
; CHECK-NEXT: Lower constant intrinsics
-; CHECK-NEXT: Dominator Tree Construction
; CHECK-NEXT: Natural Loop Information
; CHECK-NEXT: Canonicalize natural loops
; CHECK-NEXT: LCSSA Verifier
More information about the llvm-commits
mailing list