1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
2 ; RUN: opt < %s -mattr=+sve2 -passes=loop-vectorize,instcombine -enable-histogram-loop-vectorization -sve-gather-overhead=2 -sve-scatter-overhead=2 -epilogue-vectorization-minimum-VF=4 -debug-only=loop-vectorize -force-vector-interleave=1 -S 2>&1 | FileCheck %s
5 target triple = "aarch64-unknown-linux-gnu"
7 define void @simple_histogram(ptr noalias %buckets, ptr readonly %indices, i64 %N) {
8 ; CHECK-LABEL: define void @simple_histogram(
9 ; CHECK-SAME: ptr noalias [[BUCKETS:%.*]], ptr readonly [[INDICES:%.*]], i64 [[N:%.*]]) #[[ATTR0:[0-9]+]] {
10 ; CHECK-NEXT: iter.check:
11 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
12 ; CHECK-NEXT: [[TMP1:%.*]] = shl i64 [[TMP0]], 1
13 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], [[TMP1]]
14 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
15 ; CHECK: vector.main.loop.iter.check:
16 ; CHECK-NEXT: [[TMP6:%.*]] = call i64 @llvm.vscale.i64()
17 ; CHECK-NEXT: [[TMP3:%.*]] = shl i64 [[TMP6]], 2
18 ; CHECK-NEXT: [[MIN_ITERS_CHECK1:%.*]] = icmp ult i64 [[N]], [[TMP3]]
19 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK1]], label [[VEC_EPILOG_PH:%.*]], label [[VECTOR_PH1:%.*]]
21 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
22 ; CHECK-NEXT: [[TMP7:%.*]] = shl i64 [[TMP2]], 2
23 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N]], [[TMP7]]
24 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[N_MOD_VF]]
25 ; CHECK-NEXT: [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
26 ; CHECK-NEXT: [[TMP5:%.*]] = shl i64 [[TMP4]], 2
27 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
29 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH1]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
30 ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds i32, ptr [[INDICES]], i64 [[INDEX]]
31 ; CHECK-NEXT: [[WIDE_LOAD1:%.*]] = load <vscale x 4 x i32>, ptr [[TMP8]], align 4
32 ; CHECK-NEXT: [[TMP14:%.*]] = zext <vscale x 4 x i32> [[WIDE_LOAD1]] to <vscale x 4 x i64>
33 ; CHECK-NEXT: [[TMP15:%.*]] = getelementptr inbounds i32, ptr [[BUCKETS]], <vscale x 4 x i64> [[TMP14]]
34 ; CHECK-NEXT: call void @llvm.experimental.vector.histogram.add.nxv4p0.i32(<vscale x 4 x ptr> [[TMP15]], i32 1, <vscale x 4 x i1> splat (i1 true))
35 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
36 ; CHECK-NEXT: [[TMP11:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
37 ; CHECK-NEXT: br i1 [[TMP11]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
38 ; CHECK: middle.block:
39 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N_MOD_VF]], 0
40 ; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_EXIT:%.*]], label [[VEC_EPILOG_ITER_CHECK:%.*]]
41 ; CHECK: vec.epilog.iter.check:
42 ; CHECK-NEXT: [[TMP22:%.*]] = call i64 @llvm.vscale.i64()
43 ; CHECK-NEXT: [[TMP23:%.*]] = shl i64 [[TMP22]], 1
44 ; CHECK-NEXT: [[MIN_EPILOG_ITERS_CHECK:%.*]] = icmp ult i64 [[N_MOD_VF]], [[TMP23]]
45 ; CHECK-NEXT: br i1 [[MIN_EPILOG_ITERS_CHECK]], label [[SCALAR_PH]], label [[VEC_EPILOG_PH]]
46 ; CHECK: vec.epilog.ph:
47 ; CHECK-NEXT: [[VEC_EPILOG_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[VEC_EPILOG_ITER_CHECK]] ], [ 0, [[VECTOR_PH]] ]
48 ; CHECK-NEXT: [[TMP24:%.*]] = call i64 @llvm.vscale.i64()
49 ; CHECK-NEXT: [[TMP25:%.*]] = shl i64 [[TMP24]], 1
50 ; CHECK-NEXT: [[N_MOD_VF2:%.*]] = urem i64 [[N]], [[TMP25]]
51 ; CHECK-NEXT: [[N_VEC3:%.*]] = sub i64 [[N]], [[N_MOD_VF2]]
52 ; CHECK-NEXT: [[TMP16:%.*]] = call i64 @llvm.vscale.i64()
53 ; CHECK-NEXT: [[TMP17:%.*]] = shl i64 [[TMP16]], 1
54 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
55 ; CHECK: vec.epilog.vector.body:
56 ; CHECK-NEXT: [[INDEX4:%.*]] = phi i64 [ [[VEC_EPILOG_RESUME_VAL]], [[VEC_EPILOG_PH]] ], [ [[INDEX_NEXT6:%.*]], [[FOR_BODY]] ]
57 ; CHECK-NEXT: [[TMP18:%.*]] = getelementptr inbounds i32, ptr [[INDICES]], i64 [[INDEX4]]
58 ; CHECK-NEXT: [[WIDE_LOAD5:%.*]] = load <vscale x 2 x i32>, ptr [[TMP18]], align 4
59 ; CHECK-NEXT: [[TMP19:%.*]] = zext <vscale x 2 x i32> [[WIDE_LOAD5]] to <vscale x 2 x i64>
60 ; CHECK-NEXT: [[TMP20:%.*]] = getelementptr inbounds i32, ptr [[BUCKETS]], <vscale x 2 x i64> [[TMP19]]
61 ; CHECK-NEXT: call void @llvm.experimental.vector.histogram.add.nxv2p0.i32(<vscale x 2 x ptr> [[TMP20]], i32 1, <vscale x 2 x i1> splat (i1 true))
62 ; CHECK-NEXT: [[INDEX_NEXT6]] = add nuw i64 [[INDEX4]], [[TMP17]]
63 ; CHECK-NEXT: [[TMP21:%.*]] = icmp eq i64 [[INDEX_NEXT6]], [[N_VEC3]]
64 ; CHECK-NEXT: br i1 [[TMP21]], label [[VEC_EPILOG_MIDDLE_BLOCK:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
65 ; CHECK: vec.epilog.middle.block:
66 ; CHECK-NEXT: [[CMP_N7:%.*]] = icmp eq i64 [[N_MOD_VF2]], 0
67 ; CHECK-NEXT: br i1 [[CMP_N7]], label [[FOR_EXIT]], label [[SCALAR_PH]]
68 ; CHECK: vec.epilog.scalar.ph:
69 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC3]], [[VEC_EPILOG_MIDDLE_BLOCK]] ], [ [[N_VEC]], [[VEC_EPILOG_ITER_CHECK]] ], [ 0, [[ITER_CHECK:%.*]] ]
70 ; CHECK-NEXT: br label [[FOR_BODY1:%.*]]
72 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY1]] ]
73 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[INDICES]], i64 [[IV]]
74 ; CHECK-NEXT: [[TMP12:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
75 ; CHECK-NEXT: [[IDXPROM1:%.*]] = zext i32 [[TMP12]] to i64
76 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds nuw i32, ptr [[BUCKETS]], i64 [[IDXPROM1]]
77 ; CHECK-NEXT: [[TMP13:%.*]] = load i32, ptr [[ARRAYIDX2]], align 4
78 ; CHECK-NEXT: [[INC:%.*]] = add nsw i32 [[TMP13]], 1
79 ; CHECK-NEXT: store i32 [[INC]], ptr [[ARRAYIDX2]], align 4
80 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
81 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
82 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_EXIT]], label [[FOR_BODY1]], !llvm.loop [[LOOP4:![0-9]+]]
84 ; CHECK-NEXT: ret void
90 %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
91 %gep.indices = getelementptr inbounds i32, ptr %indices, i64 %iv
92 %l.idx = load i32, ptr %gep.indices, align 4
93 %idxprom1 = zext i32 %l.idx to i64
94 %gep.bucket = getelementptr inbounds i32, ptr %buckets, i64 %idxprom1
95 %l.bucket = load i32, ptr %gep.bucket, align 4
96 %inc = add nsw i32 %l.bucket, 1
97 store i32 %inc, ptr %gep.bucket, align 4
98 %iv.next = add nuw nsw i64 %iv, 1
99 %exitcond = icmp eq i64 %iv.next, %N
100 br i1 %exitcond, label %for.exit, label %for.body