[PATCH] D150454: [NFC][SCEV] Add test on backedge-taken count

Aleksandr Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 12 09:20:24 PDT 2023


aleksandr.popov created this revision.
Herald added a project: All.
aleksandr.popov requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

https://reviews.llvm.org/D150454

Files:
  llvm/test/Analysis/ScalarEvolution/trip-count-from-loop-guard.ll


Index: llvm/test/Analysis/ScalarEvolution/trip-count-from-loop-guard.ll
===================================================================
--- /dev/null
+++ llvm/test/Analysis/ScalarEvolution/trip-count-from-loop-guard.ll
@@ -0,0 +1,41 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 2
+; RUN: opt -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s
+
+; if (const > 0)
+;   for (i8 i = 126; const - i > 0; i++) {}
+;
+; TODO: Use loop guard's info 'const > 0' to figure out that max backedge-taken count is 1
+define i32 @range_from_loop_guard(i8 %const) {
+; CHECK-LABEL: 'test'
+; CHECK-NEXT:  Classifying expressions for: @test
+; CHECK-NEXT:    %iv = phi i8 [ %iv.next, %loop ], [ 126, %entry ]
+; CHECK-NEXT:    --> {126,+,1}<nuw><%loop> U: [126,-2) S: [126,-2) Exits: ((-1 * (0 smin (-126 + %const))) + %const) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %iv.next = add nuw i8 %iv, 1
+; CHECK-NEXT:    --> {127,+,1}<nuw><%loop> U: [127,-1) S: [127,-1) Exits: (1 + (-1 * (0 smin (-126 + %const))) + %const) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    %sub = sub i8 %const, %iv
+; CHECK-NEXT:    --> {(-126 + %const),+,-1}<nw><%loop> U: full-set S: full-set Exits: (0 smin (-126 + %const)) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:  Determining loop execution counts for: @test
+; CHECK-NEXT:  Loop %loop: backedge-taken count is (-126 + (-1 * (0 smin (-126 + %const))) + %const)
+; CHECK-NEXT:  Loop %loop: constant max backedge-taken count is 127
+; CHECK-NEXT:  Loop %loop: symbolic max backedge-taken count is (-126 + (-1 * (0 smin (-126 + %const))) + %const)
+; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (-126 + (-1 * (0 smin (-126 + %const))) + %const)
+; CHECK-NEXT:   Predicates:
+; CHECK:       Loop %loop: Trip multiple is 1
+;
+entry:
+  %cmp0 = icmp sgt i8 %const, 0
+  br i1 %cmp0, label %loop, label %fail
+
+loop:
+  %iv = phi i8 [ %iv.next, %loop ], [ 126, %entry ]
+  %iv.next = add nuw i8 %iv, 1
+  %sub = sub i8 %const, %iv
+  %cmp1 = icmp sgt i8 %sub, 0
+  br i1 %cmp1, label %loop, label %exit
+
+fail:
+  ret i32 -1
+
+exit:
+  ret i32 0
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150454.521683.patch
Type: text/x-patch
Size: 2209 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230512/5d3be976/attachment.bin>


More information about the llvm-commits mailing list