Index: llvm/trunk/lib/Transforms/Scalar/LoopRerollPass.cpp =================================================================== --- llvm/trunk/lib/Transforms/Scalar/LoopRerollPass.cpp +++ llvm/trunk/lib/Transforms/Scalar/LoopRerollPass.cpp @@ -1551,14 +1551,12 @@ "] Loop %" << Header->getName() << " (" << L->getNumBlocks() << " block(s))\n"); - bool Changed = false; - // For now, we'll handle only single BB loops. if (L->getNumBlocks() > 1) - return Changed; + return false; if (!SE->hasLoopInvariantBackedgeTakenCount(L)) - return Changed; + return false; const SCEV *LIBETC = SE->getBackedgeTakenCount(L); const SCEV *IterCount = SE->getAddExpr(LIBETC, SE->getOne(LIBETC->getType())); @@ -1572,11 +1570,12 @@ if (PossibleIVs.empty()) { DEBUG(dbgs() << "LRR: No possible IVs found\n"); - return Changed; + return false; } ReductionTracker Reductions; collectPossibleReductions(L, Reductions); + bool Changed = false; // For each possible IV, collect the associated possible set of 'root' nodes // (i+1, i+2, etc.). @@ -1587,5 +1586,9 @@ break; } + // Trip count of L has changed so SE must be re-evaluated. + if (Changed) + SE->forgetLoop(L); + return Changed; } Index: llvm/trunk/test/Transforms/LoopReroll/basic32iters.ll =================================================================== --- llvm/trunk/test/Transforms/LoopReroll/basic32iters.ll +++ llvm/trunk/test/Transforms/LoopReroll/basic32iters.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -loop-reroll -S | FileCheck %s +; RUN: opt < %s -loop-reroll -verify-scev -S | FileCheck %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu"