[llvm] 51973a6 - [SCEV] Add test cases for max BTC with loop guard info.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 17 12:33:02 PDT 2020
Author: Florian Hahn
Date: 2020-09-17T20:27:48+01:00
New Revision: 51973a607dfa4681037aff43e295f3ea1fb0f3f4
URL: https://github.com/llvm/llvm-project/commit/51973a607dfa4681037aff43e295f3ea1fb0f3f4
DIFF: https://github.com/llvm/llvm-project/commit/51973a607dfa4681037aff43e295f3ea1fb0f3f4.diff
LOG: [SCEV] Add test cases for max BTC with loop guard info.
This adds test cases for PR40961 and PR47247. They illustrate cases in
which the max backedge-taken count can be improved by information from
the loop guards.
Added:
llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll b/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
new file mode 100644
index 000000000000..0bbb8aace805
--- /dev/null
+++ b/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
@@ -0,0 +1,55 @@
+; RUN: opt -analyze -scalar-evolution %s | FileCheck %s
+
+; Test case for PR40961. The loop guard limit the max backedge-taken count.
+
+define void @test_guard_less_than_16(i32* nocapture %a, i64 %i) {
+; CHECK-LABEL: Determining loop execution counts for: @test_guard_less_than_16
+; CHECK-NEXT: Loop %loop: backedge-taken count is (15 + (-1 * %i))
+; CHECK-NEXT: Loop %loop: max backedge-taken count is -1
+; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (15 + (-1 * %i))
+;
+entry:
+ %cmp3 = icmp ult i64 %i, 16
+ br i1 %cmp3, label %loop, label %exit
+
+loop:
+ %iv = phi i64 [ %iv.next, %loop ], [ %i, %entry ]
+ %idx = getelementptr inbounds i32, i32* %a, i64 %iv
+ store i32 1, i32* %idx, align 4
+ %iv.next = add nuw nsw i64 %iv, 1
+ %exitcond = icmp eq i64 %iv.next, 16
+ br i1 %exitcond, label %exit, label %loop
+
+exit:
+ ret void
+}
+
+; Test case for PR47247. Both the guard condition and the assume limit the
+; max backedge-taken count.
+
+define void @test_guard_and_assume(i32* nocapture readonly %data, i64 %count) {
+; CHECK-LABEL: Determining loop execution counts for: @test_guard_and_assume
+; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + %count)
+; CHECK-NEXT: Loop %loop: max backedge-taken count is -2
+; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + %count)
+;
+entry:
+ %cmp = icmp ult i64 %count, 5
+ tail call void @llvm.assume(i1 %cmp)
+ %cmp18.not = icmp eq i64 %count, 0
+ br i1 %cmp18.not, label %exit, label %loop
+
+loop:
+ %iv = phi i64 [ %iv.next, %loop ], [ 0, %entry ]
+ %idx = getelementptr inbounds i32, i32* %data, i64 %iv
+ store i32 1, i32* %idx, align 4
+ %iv.next = add nuw i64 %iv, 1
+ %exitcond.not = icmp eq i64 %iv.next, %count
+ br i1 %exitcond.not, label %exit, label %loop
+
+exit:
+ ret void
+}
+
+; Function Attrs: nounwind willreturn
+declare void @llvm.assume(i1 noundef)
More information about the llvm-commits
mailing list