diff options
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp | 13 | 
1 files changed, 11 insertions, 2 deletions
| diff --git a/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp b/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp index 45642288948..a26c12bb934 100644 --- a/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp +++ b/llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp @@ -264,8 +264,17 @@ void SIAnnotateControlFlow::handleLoop(BranchInst *Term) {    Term->setCondition(BoolTrue);    Value *Arg = handleLoopCondition(Cond, Broken, L, Term); -  for (BasicBlock *Pred : predecessors(Target)) -    Broken->addIncoming(Pred == BB ? Arg : Int64Zero, Pred); +  for (BasicBlock *Pred : predecessors(Target)) { +    Value *PHIValue = Int64Zero; +    if (Pred == BB) // Remember the value of the previous iteration. +      PHIValue = Arg; +    // If the backedge from Pred to Target could be executed before the exit +    // of the loop at BB, it should not reset or change "Broken", which keeps +    // track of the number of threads exited the loop at BB. +    else if (L->contains(Pred) && DT->dominates(Pred, BB)) +      PHIValue = Broken; +    Broken->addIncoming(PHIValue, Pred); +  }    Term->setCondition(CallInst::Create(Loop, Arg, "", Term)); | 

