[llvm] 5cd45e4 - [SCEV] Precommit test for widened signed induction variables

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 6 14:09:48 PST 2024


Author: Philip Reames
Date: 2024-03-06T14:09:40-08:00
New Revision: 5cd45e442e99f8e01127f37548b124fa0e70f96a

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

LOG: [SCEV] Precommit test for widened signed induction variables

These tests highlight that we have missed oppurtunities proving
trip count bounds when our start/end values are sign extended
from smaller types and we have either a loop guard to relate our
start vs end, or a nsw/nuw fact to bound end.

Added: 
    

Modified: 
    llvm/test/Analysis/ScalarEvolution/trip-count.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Analysis/ScalarEvolution/trip-count.ll b/llvm/test/Analysis/ScalarEvolution/trip-count.ll
index 9dd9e3a5ee995d..cbe07effdeb265 100644
--- a/llvm/test/Analysis/ScalarEvolution/trip-count.ll
+++ b/llvm/test/Analysis/ScalarEvolution/trip-count.ll
@@ -140,3 +140,74 @@ loop:
 exit:
   ret void
 }
+
+define void @dual_sext_ne_with_slt_guard(i8 %s, i8 %n) {
+; CHECK-LABEL: 'dual_sext_ne_with_slt_guard'
+; CHECK-NEXT:  Determining loop execution counts for: @dual_sext_ne_with_slt_guard
+; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + (sext i8 %n to i64) + (-1 * (sext i8 %s to i64))<nsw>)
+; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i64 -1
+; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + (sext i8 %n to i64) + (-1 * (sext i8 %s to i64))<nsw>)
+; CHECK-NEXT:  Loop %for.body: Trip multiple is 1
+;
+entry:
+  %cmp4 = icmp slt i8 %s, %n
+  br i1 %cmp4, label %for.body.preheader, label %exit
+
+for.body.preheader:
+  %0 = sext i8 %s to i64
+  %wide.trip.count = sext i8 %n to i64
+  br label %for.body
+
+for.body:
+  %iv = phi i64 [ %0, %for.body.preheader ], [ %iv.next, %for.body ]
+  %iv.next = add nsw i64 %iv, 1
+  %exitcond.not = icmp eq i64 %iv.next, %wide.trip.count
+  br i1 %exitcond.not, label %exit, label %for.body
+
+exit:
+  ret void
+}
+
+define void @dual_sext_ne_with_nsw_inc(i8 %s, i64 %n) {
+; CHECK-LABEL: 'dual_sext_ne_with_nsw_inc'
+; CHECK-NEXT:  Determining loop execution counts for: @dual_sext_ne_with_nsw_inc
+; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + (-1 * (sext i8 %s to i64))<nsw> + %n)
+; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i64 -1
+; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + (-1 * (sext i8 %s to i64))<nsw> + %n)
+; CHECK-NEXT:  Loop %for.body: Trip multiple is 1
+;
+entry:
+  %0 = sext i8 %s to i64
+  br label %for.body
+
+for.body:
+  %iv = phi i64 [ %0, %entry ], [ %iv.next, %for.body ]
+  %iv.next = add nsw i64 %iv, 1
+  %exitcond.not = icmp eq i64 %iv.next, %n
+  br i1 %exitcond.not, label %exit, label %for.body
+
+exit:
+  ret void
+}
+
+define void @dual_sext_ne_with_nuw_inc(i8 %s, i64 %n) {
+; CHECK-LABEL: 'dual_sext_ne_with_nuw_inc'
+; CHECK-NEXT:  Determining loop execution counts for: @dual_sext_ne_with_nuw_inc
+; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + (-1 * (sext i8 %s to i64))<nsw> + %n)
+; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is i64 -1
+; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + (-1 * (sext i8 %s to i64))<nsw> + %n)
+; CHECK-NEXT:  Loop %for.body: Trip multiple is 1
+;
+entry:
+  %0 = sext i8 %s to i64
+  br label %for.body
+
+for.body:
+  %iv = phi i64 [ %0, %entry ], [ %iv.next, %for.body ]
+  %iv.next = add nuw i64 %iv, 1
+  %exitcond.not = icmp eq i64 %iv.next, %n
+  br i1 %exitcond.not, label %exit, label %for.body
+
+exit:
+  ret void
+}


        


More information about the llvm-commits mailing list