aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2007-08-08 01:51:27 +0000
committerDevang Patel <dpatel@apple.com>2007-08-08 01:51:27 +0000
commit6a2bfdaab62db8737bf54a8429da3cb8fbdfff62 (patch)
treeea69ec31ea37d88a9b85a2c569b65c926166b4a8 /lib
parent51cbf3c980e921a2950766282dfd6d9b2288eadd (diff)
downloadexternal_llvm-6a2bfdaab62db8737bf54a8429da3cb8fbdfff62.zip
external_llvm-6a2bfdaab62db8737bf54a8429da3cb8fbdfff62.tar.gz
external_llvm-6a2bfdaab62db8737bf54a8429da3cb8fbdfff62.tar.bz2
Embrace patch review feedback.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40915 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/LoopIndexSplit.cpp46
1 files changed, 23 insertions, 23 deletions
diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp
index 4d4de9d..eb1a5b1 100644
--- a/lib/Transforms/Scalar/LoopIndexSplit.cpp
+++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp
@@ -217,13 +217,26 @@ bool LoopIndexSplit::processOneIterationLoop(LPPassManager &LPM) {
if (!safeExitBlock(ExitBlock))
return false;
+ // Update CFG.
+
+ // As a first step to break this loop, remove Latch to Header edge.
BasicBlock *Latch = L->getLoopLatch();
+ BasicBlock *LatchSucc = NULL;
+ BranchInst *BR = dyn_cast<BranchInst>(Latch->getTerminator());
+ if (!BR)
+ return false;
+ Header->removePredecessor(Latch);
+ for (succ_iterator SI = succ_begin(Latch), E = succ_end(Latch);
+ SI != E; ++SI) {
+ if (Header != *SI)
+ LatchSucc = *SI;
+ }
+ BR->setUnconditionalDest(LatchSucc);
+
BasicBlock *Preheader = L->getLoopPreheader();
Instruction *Terminator = Header->getTerminator();
Value *StartValue = IndVar->getIncomingValueForBlock(Preheader);
- // Update CFG.
-
// Replace split condition in header.
// Transform
// SplitCondition : icmp eq i32 IndVar, SplitValue
@@ -238,22 +251,10 @@ bool LoopIndexSplit::processOneIterationLoop(LPPassManager &LPM) {
Instruction *C2 = new ICmpInst(SignedPredicate ?
ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
SplitValue, ExitValue, "lisplit", Terminator);
- Instruction *NSplitCond = BinaryOperator::create(Instruction::And,
- C1, C2, "lisplit", Terminator);
+ Instruction *NSplitCond = BinaryOperator::createAnd(C1, C2, "lisplit", Terminator);
SplitCondition->replaceAllUsesWith(NSplitCond);
SplitCondition->eraseFromParent();
- // As a first step to break this loop, remove Latch to Header edge.
- BasicBlock *LatchSucc = NULL;
- Header->removePredecessor(Latch);
- for (succ_iterator SI = succ_begin(Latch), E = succ_end(Latch);
- SI != E; ++SI) {
- if (Header != *SI)
- LatchSucc = *SI;
- }
- BranchInst *BR = dyn_cast<BranchInst>(Latch->getTerminator());
- BR->setUnconditionalDest(LatchSucc);
-
// Now, clear latch block. Remove instructions that are responsible
// to increment induction variable.
Instruction *LTerminator = Latch->getTerminator();
@@ -281,15 +282,13 @@ bool LoopIndexSplit::safeHeader(BasicBlock *Header) {
BI != BE; ++BI) {
Instruction *I = BI;
- // PHI Nodes are OK.
+ // PHI Nodes are OK. FIXME : Handle last value assignments.
if (isa<PHINode>(I))
continue;
// SplitCondition itself is OK.
- if (ICmpInst *CI = dyn_cast<ICmpInst>(I)) {
- if (CI == SplitCondition)
- continue;
- }
+ if (I == SplitCondition)
+ continue;
// Terminator is also harmless.
if (I == Terminator)
@@ -307,12 +306,12 @@ bool LoopIndexSplit::safeHeader(BasicBlock *Header) {
bool LoopIndexSplit::safeExitBlock(BasicBlock *ExitBlock) {
Instruction *IndVarIncrement = NULL;
-
+
for (BasicBlock::iterator BI = ExitBlock->begin(), BE = ExitBlock->end();
BI != BE; ++BI) {
Instruction *I = BI;
- // PHI Nodes are OK.
+ // PHI Nodes are OK. FIXME : Handle last value assignments.
if (isa<PHINode>(I))
continue;
@@ -338,6 +337,7 @@ bool LoopIndexSplit::safeExitBlock(BasicBlock *ExitBlock) {
if (IndVarIncrement && PN == IndVar && CI->isOne())
continue;
}
+
// I is an Exit condition if next instruction is block terminator.
// Exit condition is OK if it compares loop invariant exit value,
// which is checked below.
@@ -346,7 +346,7 @@ bool LoopIndexSplit::safeExitBlock(BasicBlock *ExitBlock) {
Instruction *N = BI;
if (N == ExitBlock->getTerminator()) {
ExitCondition = EC;
- break;
+ continue;
}
}