Index: llvm/trunk/lib/Analysis/ScalarEvolution.cpp =================================================================== --- llvm/trunk/lib/Analysis/ScalarEvolution.cpp +++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp @@ -7074,6 +7074,7 @@ Cond = ExitCond->getPredicate(); else Cond = ExitCond->getInversePredicate(); + const ICmpInst::Predicate OriginalCond = Cond; // Handle common loops like: for (X = "string"; *X; ++X) if (LoadInst *LI = dyn_cast(ExitCond->getOperand(0))) @@ -7157,7 +7158,7 @@ return ExhaustiveCount; return computeShiftCompareExitLimit(ExitCond->getOperand(0), - ExitCond->getOperand(1), L, Cond); + ExitCond->getOperand(1), L, OriginalCond); } ScalarEvolution::ExitLimit Index: llvm/trunk/test/Analysis/ScalarEvolution/shift-op.ll =================================================================== --- llvm/trunk/test/Analysis/ScalarEvolution/shift-op.ll +++ llvm/trunk/test/Analysis/ScalarEvolution/shift-op.ll @@ -160,5 +160,24 @@ ret void } +define void @test9() { +; CHECK-LABEL: Determining loop execution counts for: @test9 +; CHECK: Loop %loop: Unpredictable max backedge-taken count. + +; This is an infinite loop, make sure that it recognized as such. + +entry: + br label %loop + +leave: + ret void + +loop: + %iv = phi i32 [ -20, %entry ], [ %iv.shift, %loop ] + %iv.shift = ashr i32 %iv, 1 + %exit.cond = icmp sgt i32 %iv, -1 + br i1 %exit.cond, label %leave, label %loop +} + !0 = !{i32 0, i32 50000} !1 = !{i32 -5000, i32 -1}