aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
diff options
context:
space:
mode:
authorDanilo C. Grael <dancgr@gmail.com>2021-04-15 12:46:29 -0400
committerDanilo C. Grael <dancgr@gmail.com>2021-04-15 12:59:42 -0400
commit55487079a9bb039103615a78500d1cdd4de474ab (patch)
tree24e915e43fc0332b93994ff26d9b91c581a7a24b /llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
parentc8f0a7c215ab4c08ed2f5ac53f080adbb54714ab (diff)
downloadllvm-55487079a9bb039103615a78500d1cdd4de474ab.zip
llvm-55487079a9bb039103615a78500d1cdd4de474ab.tar.gz
llvm-55487079a9bb039103615a78500d1cdd4de474ab.tar.bz2
[LoopUnrollAndJam] Avoid repeated instructions for UAJ analysis
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
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp b/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
index 827c995..d85162f 100644
--- a/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
@@ -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))
@@ -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;