[llvm] 98f08e7 - [tests] Exercise cases where SCEV can use trip counts to refine ashr/lshr recurrences
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 31 12:50:45 PDT 2021
Author: Philip Reames
Date: 2021-03-31T12:48:50-07:00
New Revision: 98f08e7d8132daba7f9723e7977f0f073b0302ad
URL: https://github.com/llvm/llvm-project/commit/98f08e7d8132daba7f9723e7977f0f073b0302ad
DIFF: https://github.com/llvm/llvm-project/commit/98f08e7d8132daba7f9723e7977f0f073b0302ad.diff
LOG: [tests] Exercise cases where SCEV can use trip counts to refine ashr/lshr recurrences
Added:
Modified:
llvm/test/Analysis/ScalarEvolution/shift-recurrences.ll
Removed:
################################################################################
diff --git a/llvm/test/Analysis/ScalarEvolution/shift-recurrences.ll b/llvm/test/Analysis/ScalarEvolution/shift-recurrences.ll
index 4d24e02afdad..0b9525ddf4ed 100644
--- a/llvm/test/Analysis/ScalarEvolution/shift-recurrences.ll
+++ b/llvm/test/Analysis/ScalarEvolution/shift-recurrences.ll
@@ -440,3 +440,198 @@ unreachable:
br label %for.cond2295
}
+; Next batch of tests show where we can get tighter ranges on ashr/lshr
+; by using the trip count information on the loop.
+
+define void @test_ashr_tc_positive() {
+; CHECK-LABEL: 'test_ashr_tc_positive'
+; CHECK-NEXT: Classifying expressions for: @test_ashr_tc_positive
+; CHECK-NEXT: %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+; CHECK-NEXT: --> {0,+,1}<%loop> U: [0,5) S: [0,5) Exits: 4 LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: %iv.ashr = phi i64 [ 1023, %entry ], [ %iv.ashr.next, %loop ]
+; CHECK-NEXT: --> %iv.ashr U: [0,1024) S: [0,1024) Exits: 63 LoopDispositions: { %loop: Variant }
+; CHECK-NEXT: %iv.next = add i64 %iv, 1
+; CHECK-NEXT: --> {1,+,1}<%loop> U: [1,6) S: [1,6) Exits: 5 LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: %iv.ashr.next = ashr i64 %iv.ashr, 1
+; CHECK-NEXT: --> %iv.ashr.next U: [0,512) S: [0,512) Exits: 31 LoopDispositions: { %loop: Variant }
+; CHECK-NEXT: Determining loop execution counts for: @test_ashr_tc_positive
+; CHECK-NEXT: Loop %loop: backedge-taken count is 4
+; CHECK-NEXT: Loop %loop: max backedge-taken count is 4
+; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is 4
+; CHECK-NEXT: Predicates:
+; CHECK: Loop %loop: Trip multiple is 5
+;
+entry:
+ br label %loop
+loop:
+ %iv = phi i64 [0, %entry], [%iv.next, %loop]
+ %iv.ashr = phi i64 [1023, %entry], [%iv.ashr.next, %loop]
+ %iv.next = add i64 %iv, 1
+ %iv.ashr.next = ashr i64 %iv.ashr, 1
+ %cmp = icmp eq i64 %iv, 4
+ br i1 %cmp, label %exit, label %loop
+exit:
+ ret void
+}
+
+define void @test_ashr_tc_negative() {
+; CHECK-LABEL: 'test_ashr_tc_negative'
+; CHECK-NEXT: Classifying expressions for: @test_ashr_tc_negative
+; CHECK-NEXT: %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+; CHECK-NEXT: --> {0,+,1}<%loop> U: [0,5) S: [0,5) Exits: 4 LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: %iv.ashr = phi i8 [ -128, %entry ], [ %iv.ashr.next, %loop ]
+; CHECK-NEXT: --> %iv.ashr U: [-128,0) S: [-128,0) Exits: -8 LoopDispositions: { %loop: Variant }
+; CHECK-NEXT: %iv.next = add i64 %iv, 1
+; CHECK-NEXT: --> {1,+,1}<%loop> U: [1,6) S: [1,6) Exits: 5 LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: %iv.ashr.next = ashr i8 %iv.ashr, 1
+; CHECK-NEXT: --> %iv.ashr.next U: [-64,0) S: [-64,0) Exits: -4 LoopDispositions: { %loop: Variant }
+; CHECK-NEXT: Determining loop execution counts for: @test_ashr_tc_negative
+; CHECK-NEXT: Loop %loop: backedge-taken count is 4
+; CHECK-NEXT: Loop %loop: max backedge-taken count is 4
+; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is 4
+; CHECK-NEXT: Predicates:
+; CHECK: Loop %loop: Trip multiple is 5
+;
+entry:
+ br label %loop
+loop:
+ %iv = phi i64 [0, %entry], [%iv.next, %loop]
+ %iv.ashr = phi i8 [128, %entry], [%iv.ashr.next, %loop]
+ %iv.next = add i64 %iv, 1
+ %iv.ashr.next = ashr i8 %iv.ashr, 1
+ %cmp = icmp eq i64 %iv, 4
+ br i1 %cmp, label %exit, label %loop
+exit:
+ ret void
+}
+
+define void @test_ashr_tc_either(i1 %a) {
+; CHECK-LABEL: 'test_ashr_tc_either'
+; CHECK-NEXT: Classifying expressions for: @test_ashr_tc_either
+; CHECK-NEXT: %start = sext i1 %a to i8
+; CHECK-NEXT: --> (sext i1 %a to i8) U: [-1,1) S: [-1,1)
+; CHECK-NEXT: %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+; CHECK-NEXT: --> {0,+,1}<%loop> U: [0,61) S: [0,61) Exits: 60 LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: %iv.ashr = phi i8 [ %start, %entry ], [ %iv.ashr.next, %loop ]
+; CHECK-NEXT: --> %iv.ashr U: [-16,16) S: [-16,16) Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
+; CHECK-NEXT: %iv.next = add i64 %iv, 1
+; CHECK-NEXT: --> {1,+,1}<%loop> U: [1,62) S: [1,62) Exits: 61 LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: %iv.ashr.next = ashr i8 %iv.ashr, 1
+; CHECK-NEXT: --> %iv.ashr.next U: [-16,16) S: [-16,16) Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
+; CHECK-NEXT: Determining loop execution counts for: @test_ashr_tc_either
+; CHECK-NEXT: Loop %loop: backedge-taken count is 60
+; CHECK-NEXT: Loop %loop: max backedge-taken count is 60
+; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is 60
+; CHECK-NEXT: Predicates:
+; CHECK: Loop %loop: Trip multiple is 61
+;
+entry:
+ %start = sext i1 %a to i8
+ br label %loop
+loop:
+ %iv = phi i64 [0, %entry], [%iv.next, %loop]
+ %iv.ashr = phi i8 [%start, %entry], [%iv.ashr.next, %loop]
+ %iv.next = add i64 %iv, 1
+ %iv.ashr.next = ashr i8 %iv.ashr, 1
+ %cmp = icmp eq i64 %iv, 60
+ br i1 %cmp, label %exit, label %loop
+exit:
+ ret void
+}
+
+
+define void @test_lshr_tc_positive() {
+; CHECK-LABEL: 'test_lshr_tc_positive'
+; CHECK-NEXT: Classifying expressions for: @test_lshr_tc_positive
+; CHECK-NEXT: %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+; CHECK-NEXT: --> {0,+,1}<%loop> U: [0,5) S: [0,5) Exits: 4 LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: %iv.lshr = phi i64 [ 1023, %entry ], [ %iv.lshr.next, %loop ]
+; CHECK-NEXT: --> %iv.lshr U: [0,1024) S: [0,1024) Exits: 63 LoopDispositions: { %loop: Variant }
+; CHECK-NEXT: %iv.next = add i64 %iv, 1
+; CHECK-NEXT: --> {1,+,1}<%loop> U: [1,6) S: [1,6) Exits: 5 LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: %iv.lshr.next = lshr i64 %iv.lshr, 1
+; CHECK-NEXT: --> (%iv.lshr /u 2) U: [0,512) S: [0,512) Exits: 31 LoopDispositions: { %loop: Variant }
+; CHECK-NEXT: Determining loop execution counts for: @test_lshr_tc_positive
+; CHECK-NEXT: Loop %loop: backedge-taken count is 4
+; CHECK-NEXT: Loop %loop: max backedge-taken count is 4
+; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is 4
+; CHECK-NEXT: Predicates:
+; CHECK: Loop %loop: Trip multiple is 5
+;
+entry:
+ br label %loop
+loop:
+ %iv = phi i64 [0, %entry], [%iv.next, %loop]
+ %iv.lshr = phi i64 [1023, %entry], [%iv.lshr.next, %loop]
+ %iv.next = add i64 %iv, 1
+ %iv.lshr.next = lshr i64 %iv.lshr, 1
+ %cmp = icmp eq i64 %iv, 4
+ br i1 %cmp, label %exit, label %loop
+exit:
+ ret void
+}
+
+define void @test_lshr_tc_negative() {
+; CHECK-LABEL: 'test_lshr_tc_negative'
+; CHECK-NEXT: Classifying expressions for: @test_lshr_tc_negative
+; CHECK-NEXT: %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+; CHECK-NEXT: --> {0,+,1}<%loop> U: [0,5) S: [0,5) Exits: 4 LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: %iv.lshr = phi i8 [ -1, %entry ], [ %iv.lshr.next, %loop ]
+; CHECK-NEXT: --> %iv.lshr U: [-1,-128) S: [-1,-128) Exits: 15 LoopDispositions: { %loop: Variant }
+; CHECK-NEXT: %iv.next = add i64 %iv, 1
+; CHECK-NEXT: --> {1,+,1}<%loop> U: [1,6) S: [1,6) Exits: 5 LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: %iv.lshr.next = lshr i8 %iv.lshr, 1
+; CHECK-NEXT: --> (%iv.lshr /u 2) U: [0,-128) S: [0,-128) Exits: 7 LoopDispositions: { %loop: Variant }
+; CHECK-NEXT: Determining loop execution counts for: @test_lshr_tc_negative
+; CHECK-NEXT: Loop %loop: backedge-taken count is 4
+; CHECK-NEXT: Loop %loop: max backedge-taken count is 4
+; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is 4
+; CHECK-NEXT: Predicates:
+; CHECK: Loop %loop: Trip multiple is 5
+;
+entry:
+ br label %loop
+loop:
+ %iv = phi i64 [0, %entry], [%iv.next, %loop]
+ %iv.lshr = phi i8 [-1, %entry], [%iv.lshr.next, %loop]
+ %iv.next = add i64 %iv, 1
+ %iv.lshr.next = lshr i8 %iv.lshr, 1
+ %cmp = icmp eq i64 %iv, 4
+ br i1 %cmp, label %exit, label %loop
+exit:
+ ret void
+}
+
+define void @test_lshr_tc_either(i1 %a) {
+; CHECK-LABEL: 'test_lshr_tc_either'
+; CHECK-NEXT: Classifying expressions for: @test_lshr_tc_either
+; CHECK-NEXT: %start = sext i1 %a to i8
+; CHECK-NEXT: --> (sext i1 %a to i8) U: [-1,1) S: [-1,1)
+; CHECK-NEXT: %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+; CHECK-NEXT: --> {0,+,1}<%loop> U: [0,5) S: [0,5) Exits: 4 LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: %iv.lshr = phi i8 [ %start, %entry ], [ %iv.lshr.next, %loop ]
+; CHECK-NEXT: --> %iv.lshr U: [-1,-128) S: [-1,-128) Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
+; CHECK-NEXT: %iv.next = add i64 %iv, 1
+; CHECK-NEXT: --> {1,+,1}<%loop> U: [1,6) S: [1,6) Exits: 5 LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: %iv.lshr.next = lshr i8 %iv.lshr, 1
+; CHECK-NEXT: --> (%iv.lshr /u 2) U: [0,-128) S: [0,-128) Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
+; CHECK-NEXT: Determining loop execution counts for: @test_lshr_tc_either
+; CHECK-NEXT: Loop %loop: backedge-taken count is 4
+; CHECK-NEXT: Loop %loop: max backedge-taken count is 4
+; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is 4
+; CHECK-NEXT: Predicates:
+; CHECK: Loop %loop: Trip multiple is 5
+;
+entry:
+ %start = sext i1 %a to i8
+ br label %loop
+loop:
+ %iv = phi i64 [0, %entry], [%iv.next, %loop]
+ %iv.lshr = phi i8 [%start, %entry], [%iv.lshr.next, %loop]
+ %iv.next = add i64 %iv, 1
+ %iv.lshr.next = lshr i8 %iv.lshr, 1
+ %cmp = icmp eq i64 %iv, 4
+ br i1 %cmp, label %exit, label %loop
+exit:
+ ret void
+}
More information about the llvm-commits
mailing list