[llvm] eea5689 - [SCEV] Add test where result depends on order loop guards are applied.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 15 11:12:23 PST 2021


Author: Florian Hahn
Date: 2021-12-15T19:10:28Z
New Revision: eea568927b6fb44c6b4650a4a6f54ad9c4772bd8

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

LOG: [SCEV] Add test where result depends on order loop guards are applied.

This patch adds 2 test cases where we fail to determine a tight bound on
the backedge taken count because the ULT condition is applied before the
signed conditions. The order the conditions are applied impacts which
min/max folds are applied.

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 38ea8b5dfbab..9289d38cb6f8 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
@@ -1475,3 +1475,76 @@ loop:
 exit:
   ret void
 }
+
+define i32 @sle_sgt_ult_umax_to_smax(i32 %num) {
+; CHECK-LABEL: 'sle_sgt_ult_umax_to_smax'
+; CHECK-NEXT:  Classifying expressions for: @sle_sgt_ult_umax_to_smax
+; CHECK-NEXT:    %iv = phi i32 [ 0, %guard.3 ], [ %iv.next, %loop ]
+; CHECK-NEXT:    --> {0,+,4}<nuw><%loop> U: [0,-3) S: [-2147483648,2147483645) Exits: (4 * ((-4 + %num) /u 4))<nuw> LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %iv.next = add nuw i32 %iv, 4
+; CHECK-NEXT:    --> {4,+,4}<nuw><%loop> U: [4,-3) S: [-2147483648,2147483645) Exits: (4 + (4 * ((-4 + %num) /u 4))<nuw>) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:  Determining loop execution counts for: @sle_sgt_ult_umax_to_smax
+; CHECK-NEXT:  Loop %loop: backedge-taken count is ((-4 + %num) /u 4)
+; CHECK-NEXT:  Loop %loop: max backedge-taken count is 1073741823
+; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is ((-4 + %num) /u 4)
+; CHECK-NEXT:   Predicates:
+; CHECK:       Loop %loop: Trip multiple is 1
+;
+guard.1:
+  %cmp.1 = icmp sle i32 %num, 0
+  br i1 %cmp.1, label %exit, label %guard.2
+
+guard.2:
+  %cmp.2 = icmp sgt i32 %num, 28
+  br i1 %cmp.2, label %exit, label %guard.3
+
+guard.3:
+  %cmp.3 = icmp ult i32 %num, 4
+  br i1 %cmp.3, label %exit, label %loop
+
+loop:
+  %iv = phi i32 [ 0, %guard.3 ], [ %iv.next, %loop ]
+  %iv.next = add nuw i32 %iv, 4
+  %ec = icmp eq i32 %iv.next, %num
+  br i1 %ec, label %exit, label %loop
+
+exit:
+  ret i32 0
+}
+
+; Similar to @sle_sgt_ult_umax_to_smax but with 
diff erent predicate order.
+define i32 @ult_sle_sgt_umax_to_smax(i32 %num) {
+; CHECK-LABEL: 'ult_sle_sgt_umax_to_smax'
+; CHECK-NEXT:  Classifying expressions for: @ult_sle_sgt_umax_to_smax
+; CHECK-NEXT:    %iv = phi i32 [ 0, %guard.3 ], [ %iv.next, %loop ]
+; CHECK-NEXT:    --> {0,+,4}<nuw><%loop> U: [0,25) S: [0,25) Exits: (4 * ((-4 + %num) /u 4))<nuw> LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %iv.next = add nuw i32 %iv, 4
+; CHECK-NEXT:    --> {4,+,4}<nuw><%loop> U: [4,29) S: [4,29) Exits: (4 + (4 * ((-4 + %num) /u 4))<nuw>) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:  Determining loop execution counts for: @ult_sle_sgt_umax_to_smax
+; CHECK-NEXT:  Loop %loop: backedge-taken count is ((-4 + %num) /u 4)
+; CHECK-NEXT:  Loop %loop: max backedge-taken count is 6
+; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is ((-4 + %num) /u 4)
+; CHECK-NEXT:   Predicates:
+; CHECK:       Loop %loop: Trip multiple is 1
+;
+guard.1:
+  %cmp.1 = icmp ult i32 %num, 4
+  br i1 %cmp.1, label %exit, label %guard.2
+
+guard.2:
+  %cmp.2 = icmp sgt i32 %num, 28
+  br i1 %cmp.2, label %exit, label %guard.3
+
+guard.3:
+  %cmp.3 = icmp sle i32 %num, 0
+  br i1 %cmp.3, label %exit, label %loop
+
+loop:
+  %iv = phi i32 [ 0, %guard.3 ], [ %iv.next, %loop ]
+  %iv.next = add nuw i32 %iv, 4
+  %ec = icmp eq i32 %iv.next, %num
+  br i1 %ec, label %exit, label %loop
+
+exit:
+  ret i32 0
+}


        


More information about the llvm-commits mailing list