[llvm] 7e3373c - [Test] Add couple more tests where we can compute symbolic max exit count
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 24 22:36:39 PST 2022
Author: Max Kazantsev
Date: 2022-11-25T13:35:16+07:00
New Revision: 7e3373c9e174eff6edb1214efb3e67d7b7ad447d
URL: https://github.com/llvm/llvm-project/commit/7e3373c9e174eff6edb1214efb3e67d7b7ad447d
DIFF: https://github.com/llvm/llvm-project/commit/7e3373c9e174eff6edb1214efb3e67d7b7ad447d.diff
LOG: [Test] Add couple more tests where we can compute symbolic max exit count
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/symbolic_max_exit_count.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 6b20f08ad44e..64b951a9c390 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -13373,8 +13373,14 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
OS << "Unpredictable constant max backedge-taken count. ";
}
- OS << "\n"
- "Loop ";
+ OS << "\n";
+ if (ExitingBlocks.size() > 1)
+ for (BasicBlock *ExitingBlock : ExitingBlocks) {
+ OS << " constant max exit count for " << ExitingBlock->getName() << ": "
+ << *SE->getExitCount(L, ExitingBlock, ScalarEvolution::ConstantMaximum) << "\n";
+ }
+
+ OS << "Loop ";
L->getHeader()->printAsOperand(OS, /*PrintType=*/false);
OS << ": ";
diff --git a/llvm/test/Analysis/ScalarEvolution/symbolic_max_exit_count.ll b/llvm/test/Analysis/ScalarEvolution/symbolic_max_exit_count.ll
index 8b0ab04e7859..4eb243a668e0 100644
--- a/llvm/test/Analysis/ScalarEvolution/symbolic_max_exit_count.ll
+++ b/llvm/test/Analysis/ScalarEvolution/symbolic_max_exit_count.ll
@@ -20,6 +20,9 @@ define i32 @test_simple_case(i32 %start, i32 %len) {
; 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: constant max exit count for loop: -1
+; CHECK-NEXT: constant max exit count for range_check_block: ***COULDNOTCOMPUTE***
+; CHECK-NEXT: constant max exit count for backedge: ***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***
@@ -80,6 +83,9 @@ define i32 @test_litter_conditions(i32 %start, i32 %len) {
; 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: constant max exit count for loop: ***COULDNOTCOMPUTE***
+; CHECK-NEXT: constant max exit count for range_check_block: ***COULDNOTCOMPUTE***
+; CHECK-NEXT: constant max exit count for backedge: ***COULDNOTCOMPUTE***
; CHECK-NEXT: Loop %loop: Unpredictable symbolic max backedge-taken count.
; CHECK-NEXT: symbolic max exit count for loop: ***COULDNOTCOMPUTE***
; CHECK-NEXT: symbolic max exit count for range_check_block: ***COULDNOTCOMPUTE***
@@ -144,6 +150,9 @@ define i32 @test_litter_conditions_bad_context(i32 %start, i32 %len) {
; 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: constant max exit count for loop: ***COULDNOTCOMPUTE***
+; CHECK-NEXT: constant max exit count for range_check_block: ***COULDNOTCOMPUTE***
+; CHECK-NEXT: constant max exit count for backedge: ***COULDNOTCOMPUTE***
; CHECK-NEXT: Loop %loop: Unpredictable symbolic max backedge-taken count.
; CHECK-NEXT: symbolic max exit count for loop: ***COULDNOTCOMPUTE***
; CHECK-NEXT: symbolic max exit count for range_check_block: ***COULDNOTCOMPUTE***
@@ -201,6 +210,8 @@ define i32 @test_and_conditions(i32 %start, i32 %len) {
; 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: constant max exit count for loop: ***COULDNOTCOMPUTE***
+; CHECK-NEXT: constant max exit count for backedge: ***COULDNOTCOMPUTE***
; CHECK-NEXT: Loop %loop: Unpredictable symbolic max backedge-taken count.
; CHECK-NEXT: symbolic max exit count for loop: ***COULDNOTCOMPUTE***
; CHECK-NEXT: symbolic max exit count for backedge: ***COULDNOTCOMPUTE***
@@ -228,3 +239,99 @@ done:
failed:
ret i32 -3
}
+
+define i32 @test_mixup_constant_symbolic(i32 %end, i32 %len) {
+; CHECK-LABEL: 'test_mixup_constant_symbolic'
+; CHECK-NEXT: Classifying expressions for: @test_mixup_constant_symbolic
+; CHECK-NEXT: %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]
+; CHECK-NEXT: --> {0,+,1}<%loop> U: [0,1001) S: [0,1001) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: %iv.next = add i32 %iv, 1
+; CHECK-NEXT: --> {1,+,1}<%loop> U: [1,1002) S: [1,1002) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: %loop_cond = call i1 @cond()
+; CHECK-NEXT: --> %loop_cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
+; CHECK-NEXT: Determining loop execution counts for: @test_mixup_constant_symbolic
+; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
+; CHECK-NEXT: exit count for loop: %end
+; CHECK-NEXT: exit count for range_check_block: 1000
+; CHECK-NEXT: exit count for backedge: ***COULDNOTCOMPUTE***
+; CHECK-NEXT: Loop %loop: constant max backedge-taken count is 1000
+; CHECK-NEXT: constant max exit count for loop: -1
+; CHECK-NEXT: constant max exit count for range_check_block: 1000
+; CHECK-NEXT: constant max exit count for backedge: ***COULDNOTCOMPUTE***
+; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is (1000 umin %end)
+; CHECK-NEXT: symbolic max exit count for loop: %end
+; CHECK-NEXT: symbolic max exit count for range_check_block: 1000
+; CHECK-NEXT: symbolic max exit count for backedge: ***COULDNOTCOMPUTE***
+; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count.
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i32 [0, %entry], [%iv.next, %backedge]
+ %zero_check = icmp ne i32 %iv, %end
+ br i1 %zero_check, label %range_check_block, label %failed_1
+
+range_check_block:
+ %range_check = icmp ult i32 %iv, 1000
+ br i1 %range_check, label %backedge, label %failed_2
+
+backedge:
+ %iv.next = add i32 %iv, 1
+ %loop_cond = call i1 @cond()
+ br i1 %loop_cond, label %done, label %loop
+
+done:
+ ret i32 %iv
+
+failed_1:
+ ret i32 -1
+
+failed_2:
+ ret i32 -2
+}
+
+define i32 @test_mixup_constant_symbolic_merged(i32 %end, i32 %len) {
+; CHECK-LABEL: 'test_mixup_constant_symbolic_merged'
+; CHECK-NEXT: Classifying expressions for: @test_mixup_constant_symbolic_merged
+; CHECK-NEXT: %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]
+; CHECK-NEXT: --> {0,+,1}<%loop> U: [0,1001) S: [0,1001) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: %and = and i1 %zero_check, %range_check
+; CHECK-NEXT: --> (%range_check umin %zero_check) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
+; CHECK-NEXT: %iv.next = add i32 %iv, 1
+; CHECK-NEXT: --> {1,+,1}<%loop> U: [1,1002) S: [1,1002) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: %loop_cond = call i1 @cond()
+; CHECK-NEXT: --> %loop_cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
+; CHECK-NEXT: Determining loop execution counts for: @test_mixup_constant_symbolic_merged
+; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
+; CHECK-NEXT: exit count for loop: (1000 umin %end)
+; CHECK-NEXT: exit count for backedge: ***COULDNOTCOMPUTE***
+; CHECK-NEXT: Loop %loop: constant max backedge-taken count is 1000
+; CHECK-NEXT: constant max exit count for loop: 1000
+; CHECK-NEXT: constant max exit count for backedge: ***COULDNOTCOMPUTE***
+; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is (1000 umin %end)
+; CHECK-NEXT: symbolic max exit count for loop: (1000 umin %end)
+; CHECK-NEXT: symbolic max exit count for backedge: ***COULDNOTCOMPUTE***
+; CHECK-NEXT: Loop %loop: Unpredictable predicated backedge-taken count.
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i32 [0, %entry], [%iv.next, %backedge]
+ %zero_check = icmp ne i32 %iv, %end
+ %range_check = icmp ult i32 %iv, 1000
+ %and = and i1 %zero_check, %range_check
+ br i1 %and, label %backedge, label %failed_1
+
+backedge:
+ %iv.next = add i32 %iv, 1
+ %loop_cond = call i1 @cond()
+ br i1 %loop_cond, label %done, label %loop
+
+done:
+ ret i32 %iv
+
+failed_1:
+ ret i32 -1
+}
More information about the llvm-commits
mailing list