diff options
| author | alex-t <alexander.timofeev@amd.com> | 2020-11-13 19:07:29 +0300 |
|---|---|---|
| committer | alex-t <alexander.timofeev@amd.com> | 2020-12-28 17:14:02 +0300 |
| commit | 644da789e364b338227a13b5cc11dd03c8ae5ba8 (patch) | |
| tree | 4bfb02a2eae43c595f3ad70d1faa7006b2705274 /llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp | |
| parent | e673d40199477f48b78ed9ad790ce7356474f907 (diff) | |
[AMDGPU] Split edge to make si_if dominate end_cf
Basic block containing "if" not necessarily dominates block that is the "false" target for the if.
That "false" target block may have another predecessor besides the "if" block. IR value corresponding to the Exec mask is generated by the
si_if intrinsic and then used by the end_cf intrinsic. In this case IR verifier complains that 'Def does not dominate all uses'.
This change split the edge between the "if" block and "false" target block to make it dominated by the "if" block.
Reviewed By: arsenm
Differential Revision: https://reviews.llvm.org/D91435
Diffstat (limited to 'llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp')
| -rw-r--r-- | llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp b/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp index 3c41bf1fef5e..016c3b2019fd 100644 --- a/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp +++ b/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp @@ -313,8 +313,15 @@ void SIAnnotateControlFlow::closeControlFlow(BasicBlock *BB) { Value *Exec = popSaved(); Instruction *FirstInsertionPt = &*BB->getFirstInsertionPt(); - if (!isa<UndefValue>(Exec) && !isa<UnreachableInst>(FirstInsertionPt)) + if (!isa<UndefValue>(Exec) && !isa<UnreachableInst>(FirstInsertionPt)) { + Instruction *ExecDef = cast<Instruction>(Exec); + BasicBlock *DefBB = ExecDef->getParent(); + if (!DT->dominates(DefBB, BB)) { + // Split edge to make Def dominate Use + FirstInsertionPt = &*SplitEdge(DefBB, BB, DT, LI)->getFirstInsertionPt(); + } CallInst::Create(EndCf, Exec, "", FirstInsertionPt); + } } /// Annotate the control flow with intrinsics so the backend can @@ -327,7 +334,6 @@ bool SIAnnotateControlFlow::runOnFunction(Function &F) { const TargetMachine &TM = TPC.getTM<TargetMachine>(); initialize(*F.getParent(), TM.getSubtarget<GCNSubtarget>(F)); - for (df_iterator<BasicBlock *> I = df_begin(&F.getEntryBlock()), E = df_end(&F.getEntryBlock()); I != E; ++I) { BasicBlock *BB = *I; @@ -344,7 +350,8 @@ bool SIAnnotateControlFlow::runOnFunction(Function &F) { if (isTopOfStack(BB)) closeControlFlow(BB); - handleLoop(Term); + if (DT->dominates(Term->getSuccessor(1), BB)) + handleLoop(Term); continue; } |
