[llvm] 5ab96fa - [SCEV] Add tests with single-cond range check generated by InstComb.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 23 02:17:56 PDT 2021
Author: Florian Hahn
Date: 2021-06-23T10:16:57+01:00
New Revision: 5ab96fa16b31c0f019da63ae2bce3820e672d897
URL: https://github.com/llvm/llvm-project/commit/5ab96fa16b31c0f019da63ae2bce3820e672d897
DIFF: https://github.com/llvm/llvm-project/commit/5ab96fa16b31c0f019da63ae2bce3820e672d897.diff
LOG: [SCEV] Add tests with single-cond range check generated by InstComb.
Added:
Modified:
llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
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
index fa2f6bcbc9ab..bc72ad358d66 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
@@ -1250,3 +1250,115 @@ loop:
exit:
ret void
}
+
+; The function below uses a single condition to ensure %N > 0 && %N < 8.
+; InstCombine transforms such checks with 2 conditions to a single check as in
+; the test function.
+define void @optimized_range_check_unsigned(i16* %pred, i32 %N) {
+; CHECK-LABEL: 'optimized_range_check_unsigned'
+; CHECK-NEXT: Classifying expressions for: @optimized_range_check_unsigned
+; 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
+; 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 ult i32 %N.off, 7
+ 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
+}
+
+; Similar to @optimized_range_check_unsigned, but the initial compare checks
+; against unsigned max (-1), which breaks the range check idiom.
+define void @not_optimized_range_check_unsigned1(i16* %pred, i32 %N) {
+; CHECK-LABEL: 'not_optimized_range_check_unsigned1'
+; CHECK-NEXT: Classifying expressions for: @not_optimized_range_check_unsigned1
+; 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: @not_optimized_range_check_unsigned1
+; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + %N)
+; CHECK-NEXT: Loop %loop: max backedge-taken count is -2
+; 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 ult i32 %N.off, -1
+ 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
+}
+
+; Similar to @optimized_range_check_unsigned, but the initial compare checks
+; against 0, which breaks the range check idiom.
+define void @not_optimized_range_check_unsigned2(i16* %pred, i32 %N) {
+; CHECK-LABEL: 'not_optimized_range_check_unsigned2'
+; CHECK-NEXT: Classifying expressions for: @not_optimized_range_check_unsigned2
+; 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: @not_optimized_range_check_unsigned2
+; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + %N)
+; CHECK-NEXT: Loop %loop: max backedge-taken count is -2
+; 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 ult i32 %N.off, 0
+ 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
+}
More information about the llvm-commits
mailing list