Index: llvm/lib/Analysis/ScalarEvolution.cpp =================================================================== --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -8711,7 +8711,8 @@ // 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 + if (EL.ExactNotTaken != getCouldNotCompute() || + EL.SymbolicMaxNotTaken != getCouldNotCompute()) ExitCounts.emplace_back(ExitBB, EL); // 2. Derive the loop's MaxBECount from each exit's max number of @@ -8949,6 +8950,7 @@ const SCEV *BECount = getCouldNotCompute(); const SCEV *ConstantMaxBECount = getCouldNotCompute(); + const SCEV *SymbolicMaxBECount = getCouldNotCompute(); if (EitherMayExit) { // Both conditions must be same for the loop to continue executing. // Choose the less conservative count. @@ -8965,6 +8967,14 @@ else ConstantMaxBECount = getUMinFromMismatchedTypes(EL0.ConstantMaxNotTaken, EL1.ConstantMaxNotTaken); + if (EL0.SymbolicMaxNotTaken == getCouldNotCompute()) + SymbolicMaxBECount = EL1.SymbolicMaxNotTaken; + else if (EL1.SymbolicMaxNotTaken == getCouldNotCompute()) + SymbolicMaxBECount = EL0.SymbolicMaxNotTaken; + else + SymbolicMaxBECount = getUMinFromMismatchedTypes(EL0.SymbolicMaxNotTaken, + EL1.SymbolicMaxNotTaken, + /*Sequential*/ true); } else { // Both conditions must be same at the same time for the loop to exit. // For now, be conservative. @@ -8981,8 +8991,9 @@ if (isa(ConstantMaxBECount) && !isa(BECount)) ConstantMaxBECount = getConstant(getUnsignedRangeMax(BECount)); - const SCEV *SymbolicMaxBECount = - isa(BECount) ? ConstantMaxBECount : BECount; + if (isa(SymbolicMaxBECount)) + SymbolicMaxBECount = + isa(BECount) ? ConstantMaxBECount : BECount; return ExitLimit(BECount, ConstantMaxBECount, SymbolicMaxBECount, false, { &EL0.Predicates, &EL1.Predicates }); } 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 @@ -54,7 +54,6 @@ ret i32 -2 } -; TODO: Symbolic max can be %start define i32 @test_litter_conditions(i32 %start, i32 %len) { ; CHECK-LABEL: 'test_litter_conditions' ; CHECK-NEXT: Classifying expressions for: @test_litter_conditions @@ -80,8 +79,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 %start +; CHECK-NEXT: symbolic max exit count for loop: %start ; 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. @@ -118,7 +117,6 @@ ret i32 -2 } -; TODO: Symbolic max can be %start define i32 @test_litter_conditions_bad_context(i32 %start, i32 %len) { ; CHECK-LABEL: 'test_litter_conditions_bad_context' ; CHECK-NEXT: Classifying expressions for: @test_litter_conditions_bad_context @@ -144,8 +142,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 %start +; CHECK-NEXT: symbolic max exit count for loop: %start ; 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. @@ -182,7 +180,6 @@ ret i32 -2 } -; TODO: Symbolic max can be %start define i32 @test_and_conditions(i32 %start, i32 %len) { ; CHECK-LABEL: 'test_and_conditions' ; CHECK-NEXT: Classifying expressions for: @test_and_conditions @@ -201,8 +198,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 %start +; CHECK-NEXT: symbolic max exit count for loop: %start ; 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: