summaryrefslogtreecommitdiff
path: root/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp')
-rw-r--r--llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp b/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp
index 625749deb3a8..397b2f873515 100644
--- a/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp
+++ b/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp
@@ -71,6 +71,8 @@ class SIAnnotateControlFlow : public FunctionPass {
bool isElse(PHINode *Phi);
+ bool hasKill(const BasicBlock *BB);
+
void eraseIfUnused(PHINode *Phi);
void openIf(BranchInst *Term);
@@ -98,6 +100,7 @@ public:
AU.addRequired<LoopInfoWrapperPass>();
AU.addRequired<DominatorTreeWrapperPass>();
AU.addRequired<LegacyDivergenceAnalysis>();
+ AU.addPreserved<LoopInfoWrapperPass>();
AU.addPreserved<DominatorTreeWrapperPass>();
AU.addRequired<TargetPassConfig>();
FunctionPass::getAnalysisUsage(AU);
@@ -181,6 +184,15 @@ bool SIAnnotateControlFlow::isElse(PHINode *Phi) {
return true;
}
+bool SIAnnotateControlFlow::hasKill(const BasicBlock *BB) {
+ for (const Instruction &I : *BB) {
+ if (const CallInst *CI = dyn_cast<CallInst>(&I))
+ if (CI->getIntrinsicID() == Intrinsic::amdgcn_kill)
+ return true;
+ }
+ return false;
+}
+
// Erase "Phi" if it is not used any more
void SIAnnotateControlFlow::eraseIfUnused(PHINode *Phi) {
if (RecursivelyDeleteDeadPHINode(Phi)) {
@@ -339,7 +351,7 @@ bool SIAnnotateControlFlow::runOnFunction(Function &F) {
if (isTopOfStack(BB)) {
PHINode *Phi = dyn_cast<PHINode>(Term->getCondition());
- if (Phi && Phi->getParent() == BB && isElse(Phi)) {
+ if (Phi && Phi->getParent() == BB && isElse(Phi) && !hasKill(BB)) {
insertElse(Term);
eraseIfUnused(Phi);
continue;