Skip to content

Commit 86f9655

Browse files
committed
[LV][RISCV] Add test showing poor choice of VF for short loop
1 parent 0807bc7 commit 86f9655

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -S -mtriple=riscv64 -mattr=+v -loop-vectorize < %s | FileCheck %s
3+
4+
; FIXME: Using a <4 x i32> would be strictly better than tail folded
5+
; scalable vectorization in this case.
6+
define void @small_trip_count(i32* nocapture %a) nounwind vscale_range(4,1024) {
7+
; CHECK-LABEL: @small_trip_count(
8+
; CHECK-NEXT: entry:
9+
; CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.vscale.i32()
10+
; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[TMP0]], 2
11+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i32 -5, [[TMP1]]
12+
; CHECK-NEXT: br i1 [[TMP2]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
13+
; CHECK: vector.ph:
14+
; CHECK-NEXT: [[TMP3:%.*]] = call i32 @llvm.vscale.i32()
15+
; CHECK-NEXT: [[TMP4:%.*]] = mul i32 [[TMP3]], 2
16+
; CHECK-NEXT: [[TMP5:%.*]] = call i32 @llvm.vscale.i32()
17+
; CHECK-NEXT: [[TMP6:%.*]] = mul i32 [[TMP5]], 2
18+
; CHECK-NEXT: [[TMP7:%.*]] = sub i32 [[TMP6]], 1
19+
; CHECK-NEXT: [[N_RND_UP:%.*]] = add i32 4, [[TMP7]]
20+
; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 [[N_RND_UP]], [[TMP4]]
21+
; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 [[N_RND_UP]], [[N_MOD_VF]]
22+
; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
23+
; CHECK: vector.body:
24+
; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
25+
; CHECK-NEXT: [[TMP8:%.*]] = add i32 [[INDEX]], 0
26+
; CHECK-NEXT: [[ACTIVE_LANE_MASK:%.*]] = call <vscale x 2 x i1> @llvm.get.active.lane.mask.nxv2i1.i32(i32 [[TMP8]], i32 4)
27+
; CHECK-NEXT: [[TMP9:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i32 [[TMP8]]
28+
; CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds i32, i32* [[TMP9]], i32 0
29+
; CHECK-NEXT: [[TMP11:%.*]] = bitcast i32* [[TMP10]] to <vscale x 2 x i32>*
30+
; CHECK-NEXT: [[WIDE_MASKED_LOAD:%.*]] = call <vscale x 2 x i32> @llvm.masked.load.nxv2i32.p0nxv2i32(<vscale x 2 x i32>* [[TMP11]], i32 4, <vscale x 2 x i1> [[ACTIVE_LANE_MASK]], <vscale x 2 x i32> poison)
31+
; CHECK-NEXT: [[TMP12:%.*]] = add nsw <vscale x 2 x i32> [[WIDE_MASKED_LOAD]], shufflevector (<vscale x 2 x i32> insertelement (<vscale x 2 x i32> poison, i32 1, i32 0), <vscale x 2 x i32> poison, <vscale x 2 x i32> zeroinitializer)
32+
; CHECK-NEXT: [[TMP13:%.*]] = bitcast i32* [[TMP10]] to <vscale x 2 x i32>*
33+
; CHECK-NEXT: call void @llvm.masked.store.nxv2i32.p0nxv2i32(<vscale x 2 x i32> [[TMP12]], <vscale x 2 x i32>* [[TMP13]], i32 4, <vscale x 2 x i1> [[ACTIVE_LANE_MASK]])
34+
; CHECK-NEXT: [[TMP14:%.*]] = call i32 @llvm.vscale.i32()
35+
; CHECK-NEXT: [[TMP15:%.*]] = mul i32 [[TMP14]], 2
36+
; CHECK-NEXT: [[INDEX_NEXT]] = add i32 [[INDEX]], [[TMP15]]
37+
; CHECK-NEXT: [[TMP16:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
38+
; CHECK-NEXT: br i1 [[TMP16]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
39+
; CHECK: middle.block:
40+
; CHECK-NEXT: br i1 true, label [[EXIT:%.*]], label [[SCALAR_PH]]
41+
; CHECK: scalar.ph:
42+
; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
43+
; CHECK-NEXT: br label [[LOOP:%.*]]
44+
; CHECK: loop:
45+
; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
46+
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, i32* [[A]], i32 [[IV]]
47+
; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[GEP]], align 4
48+
; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[V]], 1
49+
; CHECK-NEXT: store i32 [[ADD]], i32* [[GEP]], align 4
50+
; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1
51+
; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV]], 3
52+
; CHECK-NEXT: br i1 [[COND]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP2:![0-9]+]]
53+
; CHECK: exit:
54+
; CHECK-NEXT: ret void
55+
;
56+
entry:
57+
br label %loop
58+
59+
loop:
60+
%iv = phi i32 [ %iv.next, %loop ], [ 0, %entry ]
61+
%gep = getelementptr inbounds i32, i32* %a, i32 %iv
62+
%v = load i32, i32* %gep, align 4
63+
%add = add nsw i32 %v, 1
64+
store i32 %add, i32* %gep, align 4
65+
%iv.next = add i32 %iv, 1
66+
%cond = icmp eq i32 %iv, 3
67+
br i1 %cond, label %exit, label %loop
68+
69+
exit:
70+
ret void
71+
}

0 commit comments

Comments
 (0)