From 51cbf928ab5d77ad4368a01d4e7470dbaa05ae21 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Wed, 9 Jul 2008 00:12:01 +0000 Subject: If loop induction variable's start value is less then its exit value then do not split the loop. llvm-svn: 53265 --- llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp') diff --git a/llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp b/llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp index 45d4900ca86..135ce33ee6f 100644 --- a/llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp +++ b/llvm/lib/Transforms/Scalar/LoopIndexSplit.cpp @@ -384,6 +384,19 @@ void LoopIndexSplit::findLoopConditionals() { BasicBlock *Preheader = L->getLoopPreheader(); StartValue = IndVar->getIncomingValueForBlock(Preheader); } + + // If start value is more then exit value where induction variable + // increments by 1 then we are potentially dealing with an infinite loop. + // Do not index split this loop. + if (ExitCondition) { + ConstantInt *SV = dyn_cast(StartValue); + ConstantInt *EV = + dyn_cast(ExitCondition->getOperand(ExitValueNum)); + if (SV && EV && SV->getSExtValue() > EV->getSExtValue()) + ExitCondition = NULL; + else if (EV && EV->isZero()) + ExitCondition = NULL; + } } /// Find condition inside a loop that is suitable candidate for index split. -- cgit v1.2.3