Skip to content

Commit d82e056

Browse files
committed
Initial test for histogram autovec
1 parent 20fe328 commit d82e056

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
2+
; RUN: opt < %s -passes=loop-vectorize -force-vector-interleave=1 -S | FileCheck %s
3+
4+
target triple = "aarch64-unknown-linux-gnu"
5+
6+
;; Based on the following C code:
7+
;;
8+
;; void simple_histogram(int *buckets, unsigned *indices, int N) {
9+
;; for (int i = 0; i < N; ++i)
10+
;; buckets[indices[i]]++;
11+
;; }
12+
13+
define void @simple_histogram(ptr noalias %buckets, ptr readonly %indices, i64 %N) #0 {
14+
; CHECK-LABEL: define void @simple_histogram(
15+
; CHECK-SAME: ptr noalias [[BUCKETS:%.*]], ptr readonly [[INDICES:%.*]], i64 [[N:%.*]]) #[[ATTR0:[0-9]+]] {
16+
; CHECK-NEXT: entry:
17+
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
18+
; CHECK: for.body:
19+
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
20+
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[INDICES]], i64 [[IV]]
21+
; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
22+
; CHECK-NEXT: [[IDXPROM1:%.*]] = zext i32 [[TMP0]] to i64
23+
; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, ptr [[BUCKETS]], i64 [[IDXPROM1]]
24+
; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[ARRAYIDX2]], align 4
25+
; CHECK-NEXT: [[INC:%.*]] = add nsw i32 [[TMP1]], 1
26+
; CHECK-NEXT: store i32 [[INC]], ptr [[ARRAYIDX2]], align 4
27+
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
28+
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
29+
; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_EXIT:%.*]], label [[FOR_BODY]]
30+
; CHECK: for.exit:
31+
; CHECK-NEXT: ret void
32+
;
33+
entry:
34+
br label %for.body
35+
36+
for.body:
37+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
38+
%arrayidx = getelementptr inbounds i32, ptr %indices, i64 %iv
39+
%0 = load i32, ptr %arrayidx, align 4
40+
%idxprom1 = zext i32 %0 to i64
41+
%arrayidx2 = getelementptr inbounds i32, ptr %buckets, i64 %idxprom1
42+
%1 = load i32, ptr %arrayidx2, align 4
43+
%inc = add nsw i32 %1, 1
44+
store i32 %inc, ptr %arrayidx2, align 4
45+
%iv.next = add nuw nsw i64 %iv, 1
46+
%exitcond = icmp eq i64 %iv.next, %N
47+
br i1 %exitcond, label %for.exit, label %for.body
48+
49+
for.exit:
50+
ret void
51+
}
52+
53+
attributes #0 = { "target-features"="+sve2" vscale_range(1,16) }

0 commit comments

Comments
 (0)