diff options
| author | Carl Ritson <carl.ritson@amd.com> | 2021-03-12 10:02:06 +0900 |
|---|---|---|
| committer | Carl Ritson <carl.ritson@amd.com> | 2021-03-12 11:52:08 +0900 |
| commit | f08dadd242fde200d1e252d5b06b16ab8bbecbf5 (patch) | |
| tree | a2ab612ef82e3a5daa295c34bc7d5e2bce8f5b79 /llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp | |
| parent | f65e1aee4004c25fbeacd5024de1d17f0a7ebc5c (diff) | |
[AMDGPU] Do not annotate an else branch if there is a kill
As llvm.amdgcn.kill is lowered to a terminator it can cause
else branch annotations to end up in the wrong block.
Do not annotate conditionals as else branches where there is
a kill to avoid this.
Reviewed By: arsenm
Differential Revision: https://reviews.llvm.org/D97427
Diffstat (limited to 'llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp')
| -rw-r--r-- | llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp b/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp index 625749deb3a8..3447ea33e92e 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); @@ -181,6 +183,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 +350,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; |
