summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2021-11-18 09:35:18 +0000
committerFlorian Hahn <flo@fhahn.com>2021-11-18 09:35:19 +0000
commitdd6281c4c172d7a9571ae8012cdf44d23d818b25 (patch)
tree051ed442e575a8af2ce9ff114f0fce1ad6c6f87d
parent7aa2ce0fab3c21cf87c5884f6bf8bdece1b6fe1c (diff)
downloadllvm-dd6281c4c172d7a9571ae8012cdf44d23d818b25.tar.gz
[SCEV] Add additional guard tests with swapped condition ops.
-rw-r--r--llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll36
-rw-r--r--llvm/test/Analysis/ScalarEvolution/trip-multiple-guard-info.ll26
2 files changed, 62 insertions, 0 deletions
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
index a3dcc174acbb..3026f94da8fc 100644
--- a/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
+++ b/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
@@ -1288,6 +1288,42 @@ exit:
ret void
}
+; Same as @optimized_range_check_unsigned, but with the icmp operands swapped.
+define void @optimized_range_check_unsigned_icmp_ops_swapped(i16* %pred, i32 %N) {
+; CHECK-LABEL: 'optimized_range_check_unsigned_icmp_ops_swapped'
+; CHECK-NEXT: Classifying expressions for: @optimized_range_check_unsigned_icmp_ops_swapped
+; CHECK-NEXT: %N.off = add i32 %N, -1
+; CHECK-NEXT: --> (-1 + %N) U: full-set S: full-set
+; CHECK-NEXT: %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
+; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%loop> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %N) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: %gep = getelementptr inbounds i16, i16* %pred, i32 %iv
+; CHECK-NEXT: --> {%pred,+,2}<nuw><%loop> U: full-set S: full-set Exits: ((2 * (zext i32 (-1 + %N) to i64))<nuw><nsw> + %pred) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: %iv.next = add nuw nsw i32 %iv, 1
+; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%loop> U: [1,-2147483648) S: [1,-2147483648) Exits: %N LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: Determining loop execution counts for: @optimized_range_check_unsigned_icmp_ops_swapped
+; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + %N)
+; CHECK-NEXT: Loop %loop: max backedge-taken count is -1
+; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + %N)
+; CHECK-NEXT: Predicates:
+; CHECK: Loop %loop: Trip multiple is 1
+;
+entry:
+ %N.off = add i32 %N, -1
+ %cmp = icmp ugt i32 7, %N.off
+ br i1 %cmp, label %loop, label %exit
+
+loop:
+ %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
+ %gep = getelementptr inbounds i16, i16* %pred, i32 %iv
+ store i16 0, i16* %gep, align 2
+ %iv.next = add nuw nsw i32 %iv, 1
+ %ec = icmp eq i32 %iv.next, %N
+ br i1 %ec, label %exit, label %loop
+
+exit:
+ ret void
+}
+
; The function below uses a single condition to ensure %N > 2 && %N < 22.
; InstCombine transforms such checks with 2 conditions to a single check as in
; the test function.
diff --git a/llvm/test/Analysis/ScalarEvolution/trip-multiple-guard-info.ll b/llvm/test/Analysis/ScalarEvolution/trip-multiple-guard-info.ll
index 6663909fdd7a..1c99ccf3fa73 100644
--- a/llvm/test/Analysis/ScalarEvolution/trip-multiple-guard-info.ll
+++ b/llvm/test/Analysis/ScalarEvolution/trip-multiple-guard-info.ll
@@ -28,6 +28,32 @@ exit:
ret void
}
+; Same as @test_trip_multiple_4 but with the icmp operands swapped.
+define void @test_trip_multiple_4_icmp_ops_swapped(i32 %num) {
+; CHECK-LABEL: @test_trip_multiple_4_icmp_ops_swapped
+; CHECK: Loop %for.body: backedge-taken count is (-1 + %num)
+; CHECK-NEXT: Loop %for.body: max backedge-taken count is -2
+; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is (-1 + %num)
+; CHECK: Loop %for.body: Trip multiple is 1
+;
+entry:
+ %u = urem i32 %num, 4
+ %cmp = icmp eq i32 0, %u
+ tail call void @llvm.assume(i1 %cmp)
+ %cmp.1 = icmp uge i32 %num, 4
+ tail call void @llvm.assume(i1 %cmp.1)
+ br label %for.body
+
+for.body:
+ %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+ %inc = add nuw nsw i32 %i.010, 1
+ %cmp2 = icmp ult i32 %inc, %num
+ br i1 %cmp2, label %for.body, label %exit
+
+exit:
+ ret void
+}
+
define void @test_trip_multiple_5(i32 %num) {
; CHECK-LABEL: @test_trip_multiple_5
; CHECK: Loop %for.body: backedge-taken count is (-1 + %num)