summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2015-08-13 09:56:20 +0000
committerChandler Carruth <chandlerc@gmail.com>2015-08-13 09:56:20 +0000
commit8ae7b81559125ba6e144dcc61c4c13ba0981e01f (patch)
treeee8c575d8eb297191d15990ce832bc37e85b31e1 /llvm/lib/Transforms
parent18c2669acaad6f6f87fff86fca97d33e197e7564 (diff)
downloadbcm5719-llvm-8ae7b81559125ba6e144dcc61c4c13ba0981e01f.tar.gz
bcm5719-llvm-8ae7b81559125ba6e144dcc61c4c13ba0981e01f.zip
[LIR] Start leveraging the fundamental guarantees of a loop in
simplified form to remove redundant checks and simplify the code for popcount recognition. We don't actually need to handle all of these cases. I've left a FIXME for one in particular until I finish inspecting to make sure we don't actually *rely* on the predicate in any way. llvm-svn: 244879
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
index e3fe2530c2b..f2f37eec53b 100644
--- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
@@ -830,29 +830,32 @@ bool LoopIdiomRecognize::recognizePopcount() {
// non-compact loop. Therefore, recognizing popcount idiom only makes sense
// in a compact loop.
- // Give up if the loop has multiple blocks or multiple backedges.
- if (CurLoop->getNumBackEdges() != 1 || CurLoop->getNumBlocks() != 1)
+ assert(CurLoop->isLoopSimplifyForm() &&
+ "Loop passes require simplified form!");
+
+ // Give up if the loop has multiple blocks.
+ if (CurLoop->getNumBlocks() != 1)
return false;
- BasicBlock *LoopBody = *(CurLoop->block_begin());
- if (LoopBody->size() >= 20) {
- // The loop is too big, bail out.
+ // If the loop is too big, bail out.
+ BasicBlock &LoopBB = *CurLoop->getHeader();
+ if (LoopBB.size() >= 20)
return false;
- }
// It should have a preheader containing nothing but an unconditional branch.
- BasicBlock *PH = CurLoop->getLoopPreheader();
- if (!PH)
- return false;
- if (&PH->front() != PH->getTerminator())
+ BasicBlock &PH = *CurLoop->getLoopPreheader();
+ if (&PH.front() != PH.getTerminator())
return false;
- auto *EntryBI = dyn_cast<BranchInst>(PH->getTerminator());
+ // FIXME: Technically, it shouldn't matter what instruction we use as
+ // a terminator, the only property needed is the definition of a preheader:
+ // a single loop predecessor whose only successor is the loop header.
+ auto *EntryBI = dyn_cast<BranchInst>(PH.getTerminator());
if (!EntryBI || EntryBI->isConditional())
return false;
// It should have a precondition block where the generated popcount instrinsic
// function can be inserted.
- auto *PreCondBB = PH->getSinglePredecessor();
+ auto *PreCondBB = PH.getSinglePredecessor();
if (!PreCondBB)
return false;
auto *PreCondBI = dyn_cast<BranchInst>(PreCondBB->getTerminator());
OpenPOWER on IntegriCloud