[PATCH] D157969: LoopVectorize/iv-select-cmp: add test for decreasing IV out-of-bound

Ramkumar Ramachandra via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 15 05:16:00 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 most straightforward extension to D150851 <https://reviews.llvm.org/D150851> would involve handling the
decreasing IV case, for which tests have been added in 110ec1863a <https://reviews.llvm.org/rG110ec1863af6a54d0cb646ca93867aec9f1e8fdc>
(LoopVectorize/iv-select-cmp: add test for decreasing IV, const start).
However, the commit missed a testcase for the out-of-bound sentinel
value LONG_MAX, which should not be vectorized. Fix this by adding a
test corresponding to the following program:

  long test(long *a) {
    long rdx = 331;
    for (long i = LONG_MAX; i >= 0; i--) {
      if (a[i] > 3)
        rdx = i;
    }
    return rdx;
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157969

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
@@ -286,6 +286,28 @@
   ret i64 %cond
 }
 
+define i64 @not_vectorized_select_decreasing_induction_icmp_iv_out_of_bound(ptr nocapture readonly %a) {
+; CHECK-LABEL: @not_vectorized_select_decreasing_induction_icmp_iv_out_of_bound
+; CHECK-NOT:   vector.body:
+;
+entry:
+  br label %for.body
+
+for.body:                                         ; preds = %entry, %for.body
+  %iv = phi i64 [ 9223372036854775807, %entry ], [ %dec, %for.body ]
+  %rdx = phi i64 [ 331, %entry ], [ %spec.select, %for.body ]
+  %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
+  %0 = load i64, ptr %arrayidx, align 8
+  %cmp1 = icmp sgt i64 %0, 3
+  %spec.select = select i1 %cmp1, i64 %iv, i64 %rdx
+  %dec = add nsw i64 %iv, -1
+  %cmp.not = icmp eq i64 %iv, 0
+  br i1 %cmp.not, label %exit, label %for.body
+
+exit:                                             ; preds = %for.body
+  ret i64 %spec.select
+}
+
 define i64 @not_vectorized_select_icmp_non_const_iv_start_value(ptr nocapture readonly %a, ptr nocapture readonly %b, i64 %ivstart, i64 %rdx.start, i64 %n) {
 ; CHECK-LABEL: define i64 @not_vectorized_select_icmp_non_const_iv_start_value
 ; CHECK-NOT:   vector.body:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157969.550278.patch
Type: text/x-patch
Size: 1409 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230815/1be3fbbc/attachment.bin>


More information about the llvm-commits mailing list