Index: llvm/lib/Analysis/ScalarEvolution.cpp =================================================================== --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -8714,8 +8714,13 @@ // We couldn't compute an exact value for this exit, so // we won't be able to compute an exact value for the loop. CouldComputeBECount = false; - else + // Remember exit count if either exact or symbolic is known. Because + // Exact always implies symbolic, only check symbolic. + if (EL.SymbolicMaxNotTaken != getCouldNotCompute()) ExitCounts.emplace_back(ExitBB, EL); + else + assert(EL.ExactNotTaken == getCouldNotCompute() && + "Exact is known but symbolic isn't?"); // 2. Derive the loop's MaxBECount from each exit's max number of // non-exiting iterations. Partition the loop exits into two kinds: Index: llvm/test/Analysis/ScalarEvolution/addrec-computed-during-addrec-calculation.ll =================================================================== --- llvm/test/Analysis/ScalarEvolution/addrec-computed-during-addrec-calculation.ll +++ llvm/test/Analysis/ScalarEvolution/addrec-computed-during-addrec-calculation.ll @@ -28,7 +28,7 @@ ; CHECK-NEXT: Determining loop execution counts for: @test ; CHECK-NEXT: Loop %loop2: Unpredictable backedge-taken count. ; CHECK-NEXT: Loop %loop2: constant max backedge-taken count is -1 -; CHECK-NEXT: Loop %loop2: Unpredictable symbolic max backedge-taken count. +; CHECK-NEXT: Loop %loop2: symbolic max backedge-taken count is -1 ; CHECK-NEXT: Loop %loop2: Unpredictable predicated backedge-taken count. ; CHECK-NEXT: Loop %loop3: backedge-taken count is false ; CHECK-NEXT: Loop %loop3: constant max backedge-taken count is false Index: llvm/test/Analysis/ScalarEvolution/symbolic_max_exit_count.ll =================================================================== --- llvm/test/Analysis/ScalarEvolution/symbolic_max_exit_count.ll +++ llvm/test/Analysis/ScalarEvolution/symbolic_max_exit_count.ll @@ -80,8 +80,8 @@ ; CHECK-NEXT: exit count for range_check_block: ***COULDNOTCOMPUTE*** ; CHECK-NEXT: exit count for backedge: ***COULDNOTCOMPUTE*** ; CHECK-NEXT: Loop %loop: constant max backedge-taken count is -1 -; CHECK-NEXT: Loop %loop: Unpredictable symbolic max backedge-taken count. -; CHECK-NEXT: symbolic max exit count for loop: ***COULDNOTCOMPUTE*** +; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is -1 +; CHECK-NEXT: symbolic max exit count for loop: -1 ; CHECK-NEXT: symbolic max exit count for range_check_block: ***COULDNOTCOMPUTE*** ; CHECK-NEXT: symbolic max exit count for backedge: ***COULDNOTCOMPUTE*** ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count. @@ -144,8 +144,8 @@ ; CHECK-NEXT: exit count for range_check_block: ***COULDNOTCOMPUTE*** ; CHECK-NEXT: exit count for backedge: ***COULDNOTCOMPUTE*** ; CHECK-NEXT: Loop %loop: constant max backedge-taken count is -1 -; CHECK-NEXT: Loop %loop: Unpredictable symbolic max backedge-taken count. -; CHECK-NEXT: symbolic max exit count for loop: ***COULDNOTCOMPUTE*** +; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is -1 +; CHECK-NEXT: symbolic max exit count for loop: -1 ; CHECK-NEXT: symbolic max exit count for range_check_block: ***COULDNOTCOMPUTE*** ; CHECK-NEXT: symbolic max exit count for backedge: ***COULDNOTCOMPUTE*** ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count. @@ -201,8 +201,8 @@ ; CHECK-NEXT: exit count for loop: ***COULDNOTCOMPUTE*** ; CHECK-NEXT: exit count for backedge: ***COULDNOTCOMPUTE*** ; CHECK-NEXT: Loop %loop: constant max backedge-taken count is -1 -; CHECK-NEXT: Loop %loop: Unpredictable symbolic max backedge-taken count. -; CHECK-NEXT: symbolic max exit count for loop: ***COULDNOTCOMPUTE*** +; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is -1 +; CHECK-NEXT: symbolic max exit count for loop: -1 ; CHECK-NEXT: symbolic max exit count for backedge: ***COULDNOTCOMPUTE*** ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count. ; Index: llvm/test/Analysis/ScalarEvolution/trip-count10.ll =================================================================== --- llvm/test/Analysis/ScalarEvolution/trip-count10.ll +++ llvm/test/Analysis/ScalarEvolution/trip-count10.ll @@ -159,7 +159,7 @@ ; CHECK-NEXT: Determining loop execution counts for: @exit_orcond_nsw ; CHECK-NEXT: Loop %for.body.i: Unpredictable backedge-taken count. ; CHECK-NEXT: Loop %for.body.i: constant max backedge-taken count is 1 -; CHECK-NEXT: Loop %for.body.i: Unpredictable symbolic max backedge-taken count. +; CHECK-NEXT: Loop %for.body.i: symbolic max backedge-taken count is 1 ; CHECK-NEXT: Loop %for.body.i: Unpredictable predicated backedge-taken count. ; entry: Index: llvm/test/Analysis/ScalarEvolution/trip-count7.ll =================================================================== --- llvm/test/Analysis/ScalarEvolution/trip-count7.ll +++ llvm/test/Analysis/ScalarEvolution/trip-count7.ll @@ -65,7 +65,7 @@ ; CHECK-NEXT: Determining loop execution counts for: @Doit_bb7_2E_i ; CHECK-NEXT: Loop %bb7.i: Unpredictable backedge-taken count. ; CHECK-NEXT: Loop %bb7.i: constant max backedge-taken count is 8 -; CHECK-NEXT: Loop %bb7.i: Unpredictable symbolic max backedge-taken count. +; CHECK-NEXT: Loop %bb7.i: symbolic max backedge-taken count is 8 ; CHECK-NEXT: Loop %bb7.i: Unpredictable predicated backedge-taken count. ; newFuncRoot: Index: llvm/test/Analysis/ScalarEvolution/widenable-condition.ll =================================================================== --- llvm/test/Analysis/ScalarEvolution/widenable-condition.ll +++ llvm/test/Analysis/ScalarEvolution/widenable-condition.ll @@ -24,7 +24,7 @@ ; CHECK-NEXT: Determining loop execution counts for: @wc_max ; CHECK-NEXT: Loop %loop: Unpredictable backedge-taken count. ; CHECK-NEXT: Loop %loop: constant max backedge-taken count is 1999 -; CHECK-NEXT: Loop %loop: Unpredictable symbolic max backedge-taken count. +; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is 1999 ; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count. ; entry: