xref: /llvm-project/llvm/test/Transforms/LoopVectorize/histograms.ll (revision 462cb3cd6cecd0511ecaf0e3ebcaba455ece587d)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
2; RUN: opt < %s -passes=loop-vectorize,instcombine -enable-histogram-loop-vectorization -force-vector-width=2 -S | FileCheck %s
3
4;; Currently we don't expect this to vectorize, since the generic cost model returns
5;; invalid for the histogram intrinsic.
6define void @simple_histogram(ptr noalias %buckets, ptr readonly %indices, i64 %N) {
7; CHECK-LABEL: define void @simple_histogram(
8; CHECK-SAME: ptr noalias [[BUCKETS:%.*]], ptr readonly [[INDICES:%.*]], i64 [[N:%.*]]) {
9; CHECK-NEXT:  entry:
10; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
11; CHECK:       for.body:
12; CHECK-NEXT:    [[IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
13; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds nuw i32, ptr [[INDICES]], i64 [[IV]]
14; CHECK-NEXT:    [[TMP12:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
15; CHECK-NEXT:    [[IDXPROM1:%.*]] = zext i32 [[TMP12]] to i64
16; CHECK-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds nuw i32, ptr [[BUCKETS]], i64 [[IDXPROM1]]
17; CHECK-NEXT:    [[TMP13:%.*]] = load i32, ptr [[ARRAYIDX2]], align 4
18; CHECK-NEXT:    [[INC:%.*]] = add nsw i32 [[TMP13]], 1
19; CHECK-NEXT:    store i32 [[INC]], ptr [[ARRAYIDX2]], align 4
20; CHECK-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
21; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
22; CHECK-NEXT:    br i1 [[EXITCOND]], label [[FOR_EXIT:%.*]], label [[FOR_BODY]]
23; CHECK:       for.exit:
24; CHECK-NEXT:    ret void
25;
26entry:
27  br label %for.body
28
29for.body:
30  %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
31  %gep.indices = getelementptr inbounds i32, ptr %indices, i64 %iv
32  %l.idx = load i32, ptr %gep.indices, align 4
33  %idxprom1 = zext i32 %l.idx to i64
34  %gep.bucket = getelementptr inbounds i32, ptr %buckets, i64 %idxprom1
35  %l.bucket = load i32, ptr %gep.bucket, align 4
36  %inc = add nsw i32 %l.bucket, 1
37  store i32 %inc, ptr %gep.bucket, align 4
38  %iv.next = add nuw nsw i64 %iv, 1
39  %exitcond = icmp eq i64 %iv.next, %N
40  br i1 %exitcond, label %for.exit, label %for.body
41
42for.exit:
43  ret void
44}
45