From d651f657f249c5de7f4feff826f9079a138b2840 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Mon, 20 Aug 2007 20:24:15 +0000 Subject: [PATCH] Do not split loops rejected by processOneIterationLoop(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41194 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LoopIndexSplit.cpp | 16 +++++++++++----- .../LoopIndexSplit/Crash-2007-08-17.ll | 3 +-- .../LoopIndexSplit/Crash2-2007-08-17.ll | 3 +-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp index 9b4319d40cd..4a5c1c8cc0b 100644 --- a/lib/Transforms/Scalar/LoopIndexSplit.cpp +++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp @@ -178,7 +178,7 @@ bool LoopIndexSplit::runOnLoop(Loop *IncomingLoop, LPPassManager &LPM_Ref) { // First see if it is possible to eliminate loop itself or not. for (SmallVector::iterator SI = SplitData.begin(), - E = SplitData.end(); SI != E; ++SI) { + E = SplitData.end(); SI != E;) { SplitInfo &SD = *SI; if (SD.SplitCondition->getPredicate() == ICmpInst::ICMP_EQ) { Changed = processOneIterationLoop(SD); @@ -186,8 +186,13 @@ bool LoopIndexSplit::runOnLoop(Loop *IncomingLoop, LPPassManager &LPM_Ref) { ++NumIndexSplit; // If is loop is eliminated then nothing else to do here. return Changed; + } else { + SmallVector::iterator Delete_SI = SI; + ++SI; + SplitData.erase(Delete_SI); } - } + } else + ++SI; } unsigned MaxCost = 99; @@ -198,8 +203,8 @@ bool LoopIndexSplit::runOnLoop(Loop *IncomingLoop, LPPassManager &LPM_Ref) { SplitInfo SD = *SI; // ICM_EQs are already handled above. - if (SD.SplitCondition->getPredicate() == ICmpInst::ICMP_EQ) - continue; + assert (SD.SplitCondition->getPredicate() != ICmpInst::ICMP_EQ && + "Unexpected split condition predicate"); unsigned Cost = findSplitCost(L, SD); if (Cost < MaxCost) @@ -207,7 +212,8 @@ bool LoopIndexSplit::runOnLoop(Loop *IncomingLoop, LPPassManager &LPM_Ref) { } // Split most profitiable condition. - Changed = splitLoop(SplitData[MostProfitableSDIndex]); + if (!SplitData.empty()) + Changed = splitLoop(SplitData[MostProfitableSDIndex]); if (Changed) ++NumIndexSplit; diff --git a/test/Transforms/LoopIndexSplit/Crash-2007-08-17.ll b/test/Transforms/LoopIndexSplit/Crash-2007-08-17.ll index 71fccce7471..d77f55a60ae 100644 --- a/test/Transforms/LoopIndexSplit/Crash-2007-08-17.ll +++ b/test/Transforms/LoopIndexSplit/Crash-2007-08-17.ll @@ -1,5 +1,4 @@ -; RUN: llvm-as < %s | opt -loop-index-split -disable-output -stats |& \ -; RUN: grep "loop-index-split" | count 1 +; RUN: llvm-as < %s | opt -loop-index-split -disable-output %struct._edit_script = type { %struct._edit_script*, i32, i8 } diff --git a/test/Transforms/LoopIndexSplit/Crash2-2007-08-17.ll b/test/Transforms/LoopIndexSplit/Crash2-2007-08-17.ll index 76c30b3cf16..241b7dc188d 100644 --- a/test/Transforms/LoopIndexSplit/Crash2-2007-08-17.ll +++ b/test/Transforms/LoopIndexSplit/Crash2-2007-08-17.ll @@ -1,5 +1,4 @@ -; RUN: llvm-as < %s | opt -loop-index-split -disable-output -stats |& \ -; RUN: grep "loop-index-split" | count 1 +; RUN: llvm-as < %s | opt -loop-index-split -disable-output %struct._edit_script = type { %struct._edit_script*, i32, i8 }