summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/LoopIndexSplit.cpp
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2008-10-10 22:02:57 +0000
committerDevang Patel <dpatel@apple.com>2008-10-10 22:02:57 +0000
commitfc19fbd2ca2759eafaea4d174a814f9236f2d0e8 (patch)
treed4782f4f8f812f39abc4439fe06ee945b2a179a0 /lib/Transforms/Scalar/LoopIndexSplit.cpp
parent875314bb529c9208e9e8dedec90f1e4a966442e9 (diff)
downloadllvm-fc19fbd2ca2759eafaea4d174a814f9236f2d0e8.tar.gz
llvm-fc19fbd2ca2759eafaea4d174a814f9236f2d0e8.tar.bz2
llvm-fc19fbd2ca2759eafaea4d174a814f9236f2d0e8.tar.xz
Check loop exit predicate properly while eliminating one iteration loop.
This patch fixes PR 2869 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57369 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/LoopIndexSplit.cpp')
-rw-r--r--lib/Transforms/Scalar/LoopIndexSplit.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp
index 047e656377..6a2c7587f6 100644
--- a/lib/Transforms/Scalar/LoopIndexSplit.cpp
+++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp
@@ -585,16 +585,7 @@ bool LoopIndexSplit::processOneIterationLoop(SplitInfo &SD) {
// only when index variable is equal to split value.
IndVar->replaceAllUsesWith(SD.SplitValue);
- // 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;
- }
- BR->setUnconditionalDest(LatchSucc);
-
+ Instruction *LTerminator = Latch->getTerminator();
Instruction *Terminator = Header->getTerminator();
Value *ExitValue = ExitCondition->getOperand(ExitValueNum);
@@ -606,12 +597,14 @@ bool LoopIndexSplit::processOneIterationLoop(SplitInfo &SD) {
// c2 = icmp ult i32 SplitValue, ExitValue
// and i32 c1, c2
bool SignedPredicate = ExitCondition->isSignedPredicate();
+ CmpInst::Predicate C2Predicate = ExitCondition->getPredicate();
+ if (LTerminator->getOperand(0) != Header)
+ C2Predicate = CmpInst::getInversePredicate(C2Predicate);
Instruction *C1 = new ICmpInst(SignedPredicate ?
ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE,
SD.SplitValue, StartValue, "lisplit",
Terminator);
- Instruction *C2 = new ICmpInst(SignedPredicate ?
- ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
+ Instruction *C2 = new ICmpInst(C2Predicate,
SD.SplitValue, ExitValue, "lisplit",
Terminator);
Instruction *NSplitCond = BinaryOperator::CreateAnd(C1, C2, "lisplit",
@@ -619,9 +612,18 @@ bool LoopIndexSplit::processOneIterationLoop(SplitInfo &SD) {
SD.SplitCondition->replaceAllUsesWith(NSplitCond);
SD.SplitCondition->eraseFromParent();
+ // 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;
+ }
+ BR->setUnconditionalDest(LatchSucc);
+
// Now, clear latch block. Remove instructions that are responsible
// to increment induction variable.
- Instruction *LTerminator = Latch->getTerminator();
for (BasicBlock::iterator LB = Latch->begin(), LE = Latch->end();
LB != LE; ) {
Instruction *I = LB;