[PATCH] D156124: LoopVectorize/iv-select-cmp: add test for wide trip count (NFC)

Ramkumar Ramachandra via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 24 07:14:31 PDT 2023


artagnon created this revision.
artagnon added reviewers: Mel-Chen, fhahn, Ayal, shiva0217.
Herald added a subscriber: StephenFan.
Herald added a project: All.
artagnon requested review of this revision.
Herald added subscribers: llvm-commits, wangpc.
Herald added a project: LLVM.

The current tests in iv-select-cmp.ll are not representative of clang
output of common real-world C programs, which are often written with i32
induction vars, as opposed to i64 induction vars. Hence, add a test
corresponding to the following program:

  int test(int *a, int n) {
    int rdx = 331;
    for (int i = 0; i < n; i++) {
      if (a[i] > 3)
        rdx = i;
    }
    return rdx;
  }

This issue was found while reviewing D150851 <https://reviews.llvm.org/D150851>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156124

Files:
  llvm/test/Transforms/LoopVectorize/iv-select-cmp.ll


Index: llvm/test/Transforms/LoopVectorize/iv-select-cmp.ll
===================================================================
--- llvm/test/Transforms/LoopVectorize/iv-select-cmp.ll
+++ llvm/test/Transforms/LoopVectorize/iv-select-cmp.ll
@@ -68,6 +68,35 @@
   ret i64 %cond
 }
 
+define i32 @select_icmp_const_wide_trip_count(ptr nocapture noundef readonly %a, i32 %n) {
+; CHECK-LABEL: define i32 @select_icmp_const_wide_trip_count
+; CHECK-NOT:   vector.body:
+;
+entry:
+  %cmp5 = icmp sgt i32 %n, 0
+  br i1 %cmp5, label %for.body.preheader, label %for.cond.cleanup
+
+for.body.preheader:                               ; preds = %entry
+  %wide.trip.count = zext i32 %n to i64
+  br label %for.body
+
+for.cond.cleanup:                                 ; preds = %for.body, %entry
+  %rdx.lcssa = phi i32 [ 331, %entry ], [ %spec.select, %for.body ]
+  ret i32 %rdx.lcssa
+
+for.body:                                         ; preds = %for.body.preheader, %for.body
+  %iv = phi i64 [ 0, %for.body.preheader ], [ %inc, %for.body ]
+  %rdx = phi i32 [ 331, %for.body.preheader ], [ %spec.select, %for.body ]
+  %arrayidx = getelementptr inbounds i32, ptr %a, i64 %iv
+  %0 = load i32, ptr %arrayidx, align 4
+  %cmp = icmp sgt i32 %0, 3
+  %1 = trunc i64 %iv to i32
+  %spec.select = select i1 %cmp, i32 %1, i32 %rdx
+  %inc = add nuw nsw i64 %iv, 1
+  %exitcond.not = icmp eq i64 %inc, %wide.trip.count
+  br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
+}
+
 define i64 @select_fcmp_const_fast(ptr nocapture readonly %a, i64 %n) {
 ; CHECK-LABEL: define i64 @select_fcmp_const_fast
 ; CHECK-NOT:   vector.body:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156124.543532.patch
Type: text/x-patch
Size: 1630 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230724/a8863da9/attachment.bin>


More information about the llvm-commits mailing list