[PATCH] D143644: [SCEV] Add a test where the trip count can't be calculated

Alon Kom via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 9 06:25:30 PST 2023


alonkom created this revision.
alonkom added reviewers: mkazantsev, fhahn.
Herald added a subscriber: StephenFan.
Herald added a project: All.
alonkom requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead.
Herald added a project: LLVM.

Add a test in which the trip count could have been calculated correctly thanks to an assume since it is known to divide by the step of the IV.


https://reviews.llvm.org/D143644

Files:
  llvm/test/Analysis/ScalarEvolution/trip-multiple-guard-info.ll


Index: llvm/test/Analysis/ScalarEvolution/trip-multiple-guard-info.ll
===================================================================
--- llvm/test/Analysis/ScalarEvolution/trip-multiple-guard-info.ll
+++ llvm/test/Analysis/ScalarEvolution/trip-multiple-guard-info.ll
@@ -40,14 +40,14 @@
 
 define void @test_trip_multiple_4_guard(i32 %num) {
 ; CHECK-LABEL: 'test_trip_multiple_4_guard'
-; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_4
+; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_4_guard
 ; CHECK-NEXT:    %u = urem i32 %num, 4
 ; CHECK-NEXT:    --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4)
 ; CHECK-NEXT:    %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
 ; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable }
 ; CHECK-NEXT:    %inc = add nuw nsw i32 %i.010, 1
 ; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable }
-; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_4
+; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_4_guard
 ; CHECK-NEXT:  Loop %for.body: backedge-taken count is (-1 + %num)
 ; CHECK-NEXT:  Loop %for.body: constant max backedge-taken count is -2
 ; CHECK-NEXT:  Loop %for.body: symbolic max backedge-taken count is (-1 + %num)
@@ -464,5 +464,37 @@
   ret void
 }
 
+; TODO: Even though %num is known to divide by 4, and the loop's IV advances by 4, SCEV can't compute the trip count.
+define void @test_trip_multiple_4_vectorized_iv(i32 %num) {
+; CHECK-LABEL: 'test_trip_multiple_4_vectorized_iv'
+; CHECK-NEXT:  Classifying expressions for: @test_trip_multiple_4_vectorized_iv
+; CHECK-NEXT:    %u = urem i32 %num, 4
+; CHECK-NEXT:    --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4)
+; CHECK-NEXT:    %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+; CHECK-NEXT:    --> {0,+,4}<%for.body> U: [0,-3) S: [-2147483648,2147483645) Exits: <<Unknown>> LoopDispositions: { %for.body: Computable }
+; CHECK-NEXT:    %inc = add i32 %i.010, 4
+; CHECK-NEXT:    --> {4,+,4}<%for.body> U: [0,-3) S: [-2147483648,2147483645) Exits: <<Unknown>> LoopDispositions: { %for.body: Computable }
+; CHECK-NEXT:  Determining loop execution counts for: @test_trip_multiple_4_vectorized_iv
+; CHECK-NEXT:  Loop %for.body: Unpredictable backedge-taken count.
+; CHECK-NEXT:  Loop %for.body: Unpredictable constant max backedge-taken count.
+; CHECK-NEXT:  Loop %for.body: Unpredictable symbolic max backedge-taken count.
+; CHECK-NEXT:  Loop %for.body: Unpredictable predicated backedge-taken count.
+;
+entry:
+  %u = urem i32 %num, 4
+  %cmp = icmp eq i32 %u, 0
+  tail call void @llvm.assume(i1 %cmp)
+  br label %for.body
+
+for.body:
+  %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+  %inc = add i32 %i.010, 4
+  %cmp2 = icmp ult i32 %inc, %num
+  br i1 %cmp2, label %for.body, label %exit
+
+exit:
+  ret void
+}
+
 declare void @llvm.assume(i1)
 declare void @llvm.experimental.guard(i1, ...)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143644.496108.patch
Type: text/x-patch
Size: 3127 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230209/4fe3fefa/attachment.bin>


More information about the llvm-commits mailing list