aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/LoopSimplify.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-08-16 10:39:57 +0200
committerNikita Popov <npopov@redhat.com>2023-08-17 09:09:14 +0200
commit51dfe3cb3bdf543186fb3fba5085f2376047bb33 (patch)
tree60bbf7e26db4f3b6ae42817467cc83ac532f5a78 /llvm/lib/Transforms/Utils/LoopSimplify.cpp
parent317a0fe5bd7113c0ac9d30b2de58ca409e5ff754 (diff)
downloadllvm-51dfe3cb3bdf543186fb3fba5085f2376047bb33.zip
llvm-51dfe3cb3bdf543186fb3fba5085f2376047bb33.tar.gz
llvm-51dfe3cb3bdf543186fb3fba5085f2376047bb33.tar.bz2
[IR] Add PHINode::removeIncomingValueIf() (NFC)
Add an API that allows removing multiple incoming phi values based on a predicate callback, as suggested on D157621. This makes sure that the removal is linear time rather than quadratic, and avoids subtleties around iterator invalidation. I have replaced some of the more straightforward users with the new API, though there's a couple more places that should be able to use it. Differential Revision: https://reviews.llvm.org/D158064
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopSimplify.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/LoopSimplify.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopSimplify.cpp b/llvm/lib/Transforms/Utils/LoopSimplify.cpp
index 3e604fd..07e622b 100644
--- a/llvm/lib/Transforms/Utils/LoopSimplify.cpp
+++ b/llvm/lib/Transforms/Utils/LoopSimplify.cpp
@@ -429,8 +429,8 @@ static BasicBlock *insertUniqueBackedgeBlock(Loop *L, BasicBlock *Preheader,
PN->setIncomingBlock(0, PN->getIncomingBlock(PreheaderIdx));
}
// Nuke all entries except the zero'th.
- for (unsigned i = 0, e = PN->getNumIncomingValues()-1; i != e; ++i)
- PN->removeIncomingValue(e-i, false);
+ PN->removeIncomingValueIf([](unsigned Idx) { return Idx != 0; },
+ /* DeletePHIIfEmpty */ false);
// Finally, add the newly constructed PHI node as the entry for the BEBlock.
PN->addIncoming(NewPN, BEBlock);