Skip to content

Commit

Permalink
[LoopUnrollAndJam] Avoid repeated instructions for UAJ analysis
Browse files Browse the repository at this point in the history
Avoid visiting repeated instructions for processHeaderPhiOperands as it can cause a scenario of endless loop. Test case is attached and can be ran with `opt -basic-aa -tbaa -loop-unroll-and-jam  -allow-unroll-and-jam -unroll-and-jam-count=4`.

Reviewed By: dmgreen

Differential Revision: https://reviews.llvm.org/D97407
  • Loading branch information
dancgr committed Apr 15, 2021
1 parent c8f0a7c commit 5548707
Show file tree
Hide file tree
Showing 2 changed files with 384 additions and 1 deletion.
5 changes: 4 additions & 1 deletion llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ template <typename T>
static bool processHeaderPhiOperands(BasicBlock *Header, BasicBlock *Latch,
BasicBlockSet &AftBlocks, T Visit) {
SmallVector<Instruction *, 8> Worklist;
SmallPtrSet<Instruction *, 8> VisitedInstr;
for (auto &Phi : Header->phis()) {
Value *V = Phi.getIncomingValueForBlock(Latch);
if (Instruction *I = dyn_cast<Instruction>(V))
Expand All @@ -151,11 +152,13 @@ static bool processHeaderPhiOperands(BasicBlock *Header, BasicBlock *Latch,
Instruction *I = Worklist.pop_back_val();
if (!Visit(I))
return false;
VisitedInstr.insert(I);

if (AftBlocks.count(I->getParent()))
for (auto &U : I->operands())
if (Instruction *II = dyn_cast<Instruction>(U))
Worklist.push_back(II);
if (!VisitedInstr.count(II))
Worklist.push_back(II);
}

return true;
Expand Down
Loading

0 comments on commit 5548707

Please sign in to comment.