[llvm] 293b483 - [SCEV] Add test where loop guards can be used to improve BTC.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed May 3 14:06:04 PDT 2023


Author: Florian Hahn
Date: 2023-05-03T22:05:30+01:00
New Revision: 293b4834b5756e1c284e8b23d0bfd16680bb2ce8

URL: https://github.com/llvm/llvm-project/commit/293b4834b5756e1c284e8b23d0bfd16680bb2ce8
DIFF: https://github.com/llvm/llvm-project/commit/293b4834b5756e1c284e8b23d0bfd16680bb2ce8.diff

LOG: [SCEV] Add test where loop guards can be used to improve BTC.

Added: 
    llvm/test/Analysis/ScalarEvolution/backedge-taken-count-guard-info.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Analysis/ScalarEvolution/backedge-taken-count-guard-info.ll b/llvm/test/Analysis/ScalarEvolution/backedge-taken-count-guard-info.ll
new file mode 100644
index 0000000000000..c0704d7423ae6
--- /dev/null
+++ b/llvm/test/Analysis/ScalarEvolution/backedge-taken-count-guard-info.ll
@@ -0,0 +1,76 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 2
+; RUN: opt -passes='print<scalar-evolution>' -disable-output %s 2>&1 | FileCheck %s
+
+define void @loop_guard_improves_exact_backedge_taken_count_1(i32 %conv) {
+; CHECK-LABEL: 'loop_guard_improves_exact_backedge_taken_count_1'
+; CHECK-NEXT:  Classifying expressions for: @loop_guard_improves_exact_backedge_taken_count_1
+; CHECK-NEXT:    %and = and i32 %conv, 1
+; CHECK-NEXT:    --> (zext i1 (trunc i32 %conv to i1) to i32) U: [0,2) S: [0,2)
+; CHECK-NEXT:    %conv8 = zext i32 %and to i64
+; CHECK-NEXT:    --> (zext i1 (trunc i32 %conv to i1) to i64) U: [0,2) S: [0,2)
+; CHECK-NEXT:    %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%loop> U: [0,2) S: [0,2) Exits: (zext i1 (trunc i32 %conv to i1) to i64) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %iv.next = add i64 %iv, 1
+; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%loop> U: [1,3) S: [1,3) Exits: (1 + (zext i1 (trunc i32 %conv to i1) to i64))<nuw><nsw> LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:  Determining loop execution counts for: @loop_guard_improves_exact_backedge_taken_count_1
+; CHECK-NEXT:  Loop %loop: backedge-taken count is (zext i1 (trunc i32 %conv to i1) to i64)
+; CHECK-NEXT:  Loop %loop: constant max backedge-taken count is 1
+; CHECK-NEXT:  Loop %loop: symbolic max backedge-taken count is (zext i1 (trunc i32 %conv to i1) to i64)
+; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (zext i1 (trunc i32 %conv to i1) to i64)
+; CHECK-NEXT:   Predicates:
+; CHECK:       Loop %loop: Trip multiple is 1
+;
+entry:
+  %and = and i32 %conv, 1
+  %conv8 = zext i32 %and to i64
+  %c = icmp ugt i32 %and, 0
+  br i1 %c, label %exit, label %loop
+
+loop:
+  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+  call void @clobber()
+  %iv.next = add i64 %iv, 1
+  %exitcond = icmp eq i64 %iv, %conv8
+  br i1 %exitcond, label %exit, label %loop
+
+exit:
+  ret void
+}
+
+define void @loop_guard_improves_exact_backedge_taken_count_2(i32 %conv) {
+; CHECK-LABEL: 'loop_guard_improves_exact_backedge_taken_count_2'
+; CHECK-NEXT:  Classifying expressions for: @loop_guard_improves_exact_backedge_taken_count_2
+; CHECK-NEXT:    %and = and i32 %conv, 1
+; CHECK-NEXT:    --> (zext i1 (trunc i32 %conv to i1) to i32) U: [0,2) S: [0,2)
+; CHECK-NEXT:    %conv8 = zext i32 %and to i64
+; CHECK-NEXT:    --> (zext i1 (trunc i32 %conv to i1) to i64) U: [0,2) S: [0,2)
+; CHECK-NEXT:    %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%loop> U: [0,2) S: [0,2) Exits: (zext i1 (trunc i32 %conv to i1) to i64) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %iv.next = add i64 %iv, 1
+; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%loop> U: [1,3) S: [1,3) Exits: (1 + (zext i1 (trunc i32 %conv to i1) to i64))<nuw><nsw> LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:  Determining loop execution counts for: @loop_guard_improves_exact_backedge_taken_count_2
+; CHECK-NEXT:  Loop %loop: backedge-taken count is (zext i1 (trunc i32 %conv to i1) to i64)
+; CHECK-NEXT:  Loop %loop: constant max backedge-taken count is 1
+; CHECK-NEXT:  Loop %loop: symbolic max backedge-taken count is (zext i1 (trunc i32 %conv to i1) to i64)
+; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (zext i1 (trunc i32 %conv to i1) to i64)
+; CHECK-NEXT:   Predicates:
+; CHECK:       Loop %loop: Trip multiple is 1
+;
+entry:
+  %and = and i32 %conv, 1
+  %conv8 = zext i32 %and to i64
+  %c = icmp eq i32 %and, 1
+  br i1 %c, label %loop, label %exit
+
+loop:
+  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+  call void @clobber()
+  %iv.next = add i64 %iv, 1
+  %exitcond = icmp eq i64 %iv, %conv8
+  br i1 %exitcond, label %exit, label %loop
+
+exit:
+  ret void
+}
+
+declare void @clobber()


        


More information about the llvm-commits mailing list