Skip to content

Commit 1b52c7b

Browse files
committed
[AMDGPUUnifyDivergentExitNodes] Use Uniformity Analysis
Reviewed By: foad Differential Revision: https://reviews.llvm.org/D145018
1 parent 969ab71 commit 1b52c7b

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
#include "llvm/ADT/SmallVector.h"
2727
#include "llvm/ADT/StringRef.h"
2828
#include "llvm/Analysis/DomTreeUpdater.h"
29-
#include "llvm/Analysis/LegacyDivergenceAnalysis.h"
3029
#include "llvm/Analysis/PostDominators.h"
3130
#include "llvm/Analysis/TargetTransformInfo.h"
31+
#include "llvm/Analysis/UniformityAnalysis.h"
3232
#include "llvm/IR/BasicBlock.h"
3333
#include "llvm/IR/CFG.h"
3434
#include "llvm/IR/Constants.h"
@@ -82,7 +82,7 @@ INITIALIZE_PASS_BEGIN(AMDGPUUnifyDivergentExitNodes, DEBUG_TYPE,
8282
"Unify divergent function exit nodes", false, false)
8383
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
8484
INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass)
85-
INITIALIZE_PASS_DEPENDENCY(LegacyDivergenceAnalysis)
85+
INITIALIZE_PASS_DEPENDENCY(UniformityInfoWrapperPass)
8686
INITIALIZE_PASS_END(AMDGPUUnifyDivergentExitNodes, DEBUG_TYPE,
8787
"Unify divergent function exit nodes", false, false)
8888

@@ -92,15 +92,15 @@ void AMDGPUUnifyDivergentExitNodes::getAnalysisUsage(AnalysisUsage &AU) const{
9292

9393
AU.addRequired<PostDominatorTreeWrapperPass>();
9494

95-
AU.addRequired<LegacyDivergenceAnalysis>();
95+
AU.addRequired<UniformityInfoWrapperPass>();
9696

9797
if (RequireAndPreserveDomTree) {
9898
AU.addPreserved<DominatorTreeWrapperPass>();
9999
// FIXME: preserve PostDominatorTreeWrapperPass
100100
}
101101

102102
// No divergent values are changed, only blocks and branch edges.
103-
AU.addPreserved<LegacyDivergenceAnalysis>();
103+
AU.addPreserved<UniformityInfoWrapperPass>();
104104

105105
// We preserve the non-critical-edgeness property
106106
AU.addPreservedID(BreakCriticalEdgesID);
@@ -114,14 +114,13 @@ void AMDGPUUnifyDivergentExitNodes::getAnalysisUsage(AnalysisUsage &AU) const{
114114

115115
/// \returns true if \p BB is reachable through only uniform branches.
116116
/// XXX - Is there a more efficient way to find this?
117-
static bool isUniformlyReached(const LegacyDivergenceAnalysis &DA,
118-
BasicBlock &BB) {
117+
static bool isUniformlyReached(const UniformityInfo &UA, BasicBlock &BB) {
119118
SmallVector<BasicBlock *, 8> Stack(predecessors(&BB));
120119
SmallPtrSet<BasicBlock *, 8> Visited;
121120

122121
while (!Stack.empty()) {
123122
BasicBlock *Top = Stack.pop_back_val();
124-
if (!DA.isUniform(Top->getTerminator()))
123+
if (!UA.isUniform(Top->getTerminator()))
125124
return false;
126125

127126
for (BasicBlock *Pred : predecessors(Top)) {
@@ -192,7 +191,8 @@ bool AMDGPUUnifyDivergentExitNodes::runOnFunction(Function &F) {
192191
!isa<BranchInst>(PDT.getRoot()->getTerminator())))
193192
return false;
194193

195-
LegacyDivergenceAnalysis &DA = getAnalysis<LegacyDivergenceAnalysis>();
194+
UniformityInfo &UA =
195+
getAnalysis<UniformityInfoWrapperPass>().getUniformityInfo();
196196
TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
197197

198198
// Loop over all of the blocks in a function, tracking all of the blocks that
@@ -213,7 +213,7 @@ bool AMDGPUUnifyDivergentExitNodes::runOnFunction(Function &F) {
213213
// exits, we should only unify UnreachableBlocks that are not uniformly
214214
// reachable.
215215
bool HasDivergentExitBlock = llvm::any_of(
216-
PDT.roots(), [&](auto BB) { return !isUniformlyReached(DA, *BB); });
216+
PDT.roots(), [&](auto BB) { return !isUniformlyReached(UA, *BB); });
217217

218218
for (BasicBlock *BB : PDT.roots()) {
219219
if (isa<ReturnInst>(BB->getTerminator())) {

llvm/test/CodeGen/AMDGPU/llc-pipeline.ll

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565
; GCN-O0-NEXT: Remove unreachable blocks from the CFG
6666
; GCN-O0-NEXT: Post-Dominator Tree Construction
6767
; GCN-O0-NEXT: Dominator Tree Construction
68-
; GCN-O0-NEXT: Natural Loop Information
69-
; GCN-O0-NEXT: Legacy Divergence Analysis
68+
; GCN-O0-NEXT: Cycle Info Analysis
69+
; GCN-O0-NEXT: Uniformity Analysis
7070
; GCN-O0-NEXT: Unify divergent function exit nodes
7171
; GCN-O0-NEXT: Lazy Value Information Analysis
7272
; GCN-O0-NEXT: Lower SwitchInst's to branches
@@ -262,7 +262,8 @@
262262
; GCN-O1-NEXT: Basic Alias Analysis (stateless AA impl)
263263
; GCN-O1-NEXT: Function Alias Analysis Results
264264
; GCN-O1-NEXT: Code sinking
265-
; GCN-O1-NEXT: Legacy Divergence Analysis
265+
; GCN-O1-NEXT: Cycle Info Analysis
266+
; GCN-O1-NEXT: Uniformity Analysis
266267
; GCN-O1-NEXT: Unify divergent function exit nodes
267268
; GCN-O1-NEXT: Lazy Value Information Analysis
268269
; GCN-O1-NEXT: Lower SwitchInst's to branches
@@ -562,7 +563,8 @@
562563
; GCN-O1-OPTS-NEXT: Basic Alias Analysis (stateless AA impl)
563564
; GCN-O1-OPTS-NEXT: Function Alias Analysis Results
564565
; GCN-O1-OPTS-NEXT: Code sinking
565-
; GCN-O1-OPTS-NEXT: Legacy Divergence Analysis
566+
; GCN-O1-OPTS-NEXT: Cycle Info Analysis
567+
; GCN-O1-OPTS-NEXT: Uniformity Analysis
566568
; GCN-O1-OPTS-NEXT: Unify divergent function exit nodes
567569
; GCN-O1-OPTS-NEXT: Lazy Value Information Analysis
568570
; GCN-O1-OPTS-NEXT: Lower SwitchInst's to branches
@@ -870,7 +872,8 @@
870872
; GCN-O2-NEXT: Basic Alias Analysis (stateless AA impl)
871873
; GCN-O2-NEXT: Function Alias Analysis Results
872874
; GCN-O2-NEXT: Code sinking
873-
; GCN-O2-NEXT: Legacy Divergence Analysis
875+
; GCN-O2-NEXT: Cycle Info Analysis
876+
; GCN-O2-NEXT: Uniformity Analysis
874877
; GCN-O2-NEXT: Unify divergent function exit nodes
875878
; GCN-O2-NEXT: Lazy Value Information Analysis
876879
; GCN-O2-NEXT: Lower SwitchInst's to branches
@@ -1191,7 +1194,8 @@
11911194
; GCN-O3-NEXT: Basic Alias Analysis (stateless AA impl)
11921195
; GCN-O3-NEXT: Function Alias Analysis Results
11931196
; GCN-O3-NEXT: Code sinking
1194-
; GCN-O3-NEXT: Legacy Divergence Analysis
1197+
; GCN-O3-NEXT: Cycle Info Analysis
1198+
; GCN-O3-NEXT: Uniformity Analysis
11951199
; GCN-O3-NEXT: Unify divergent function exit nodes
11961200
; GCN-O3-NEXT: Lazy Value Information Analysis
11971201
; GCN-O3-NEXT: Lower SwitchInst's to branches

0 commit comments

Comments
 (0)