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

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 25 05:20:41 PDT 2023


Author: Ramkumar Ramachandra
Date: 2023-09-25T13:20:11+01:00
New Revision: ef48e90489dc219568f46a9c36da80adfb759ad7

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

LOG: LoopVectorize/iv-select-cmp: add test for decreasing IV out-of-bound

The most straightforward extension to D150851 would involve handling the
decreasing IV case, for which tests have been added in 110ec1863a
(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;
  }

Differential Revision: https://reviews.llvm.org/D157969

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/LoopVectorize/iv-select-cmp.ll b/llvm/test/Transforms/LoopVectorize/iv-select-cmp.ll
index 045c27b8f7e0535..9f180d97526c853 100644
--- a/llvm/test/Transforms/LoopVectorize/iv-select-cmp.ll
+++ b/llvm/test/Transforms/LoopVectorize/iv-select-cmp.ll
@@ -452,6 +452,28 @@ exit:                                             ; preds = %for.body
   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:


        


More information about the llvm-commits mailing list