Skip to content

Commit 77df976

Browse files
rickyzfhahn
authored andcommitted
[LV] Add test case for #51677.
1 parent cf59d67 commit 77df976

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2+
; RUN: opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s | FileCheck %s
3+
4+
; The vectorizer should refuse to fold the tail by masking because
5+
; %conv is used outside of the loop.
6+
define i32 @test(ptr nocapture %arr, i64 %n) {
7+
Test for this by checking that
8+
; CHECK-LABEL: define i32 @test
9+
; CHECK-SAME: (ptr nocapture [[ARR:%.*]], i64 [[N:%.*]]) {
10+
; CHECK-NEXT: entry:
11+
; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i64 [[N]], 1
12+
; CHECK-NEXT: br i1 [[CMP1]], label [[PREHEADER:%.*]], label [[DONE:%.*]]
13+
; CHECK: preheader:
14+
; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[N]], -1
15+
; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
16+
; CHECK: vector.scevcheck:
17+
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[N]], -2
18+
; CHECK-NEXT: [[TMP2:%.*]] = trunc i64 [[TMP1]] to i8
19+
; CHECK-NEXT: [[TMP3:%.*]] = add i8 1, [[TMP2]]
20+
; CHECK-NEXT: [[TMP4:%.*]] = icmp ult i8 [[TMP3]], 1
21+
; CHECK-NEXT: [[TMP5:%.*]] = icmp ugt i64 [[TMP1]], 255
22+
; CHECK-NEXT: [[TMP6:%.*]] = or i1 [[TMP4]], [[TMP5]]
23+
; CHECK-NEXT: [[TMP7:%.*]] = trunc i64 [[TMP1]] to i8
24+
; CHECK-NEXT: [[TMP8:%.*]] = add i8 2, [[TMP7]]
25+
; CHECK-NEXT: [[TMP9:%.*]] = icmp ult i8 [[TMP8]], 2
26+
; CHECK-NEXT: [[TMP10:%.*]] = icmp ugt i64 [[TMP1]], 255
27+
; CHECK-NEXT: [[TMP11:%.*]] = or i1 [[TMP9]], [[TMP10]]
28+
; CHECK-NEXT: [[TMP12:%.*]] = or i1 [[TMP6]], [[TMP11]]
29+
; CHECK-NEXT: br i1 [[TMP12]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
30+
; CHECK: vector.ph:
31+
; CHECK-NEXT: [[N_RND_UP:%.*]] = add i64 [[TMP0]], 3
32+
; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], 4
33+
; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
34+
; CHECK-NEXT: [[IND_END:%.*]] = add i64 1, [[N_VEC]]
35+
; CHECK-NEXT: [[DOTCAST:%.*]] = trunc i64 [[N_VEC]] to i8
36+
; CHECK-NEXT: [[IND_END1:%.*]] = add i8 1, [[DOTCAST]]
37+
; CHECK-NEXT: [[TRIP_COUNT_MINUS_1:%.*]] = sub i64 [[TMP0]], 1
38+
; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[TRIP_COUNT_MINUS_1]], i64 0
39+
; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer
40+
; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
41+
; CHECK: vector.body:
42+
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[PRED_STORE_CONTINUE10:%.*]] ]
43+
; CHECK-NEXT: [[VEC_IND:%.*]] = phi <4 x i64> [ <i64 1, i64 2, i64 3, i64 4>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[PRED_STORE_CONTINUE10]] ]
44+
; CHECK-NEXT: [[OFFSET_IDX:%.*]] = add i64 1, [[INDEX]]
45+
; CHECK-NEXT: [[TMP13:%.*]] = add i64 [[OFFSET_IDX]], 0
46+
; CHECK-NEXT: [[TMP14:%.*]] = add i64 [[OFFSET_IDX]], 1
47+
; CHECK-NEXT: [[TMP15:%.*]] = add i64 [[OFFSET_IDX]], 2
48+
; CHECK-NEXT: [[TMP16:%.*]] = add i64 [[OFFSET_IDX]], 3
49+
; CHECK-NEXT: [[BROADCAST_SPLATINSERT3:%.*]] = insertelement <4 x i64> poison, i64 [[INDEX]], i64 0
50+
; CHECK-NEXT: [[BROADCAST_SPLAT4:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT3]], <4 x i64> poison, <4 x i32> zeroinitializer
51+
; CHECK-NEXT: [[VEC_IV:%.*]] = add <4 x i64> [[BROADCAST_SPLAT4]], <i64 0, i64 1, i64 2, i64 3>
52+
; CHECK-NEXT: [[TMP17:%.*]] = icmp ule <4 x i64> [[VEC_IV]], [[BROADCAST_SPLAT]]
53+
; CHECK-NEXT: [[TMP18:%.*]] = add nsw <4 x i64> [[VEC_IND]], <i64 -1, i64 -1, i64 -1, i64 -1>
54+
; CHECK-NEXT: [[TMP19:%.*]] = extractelement <4 x i1> [[TMP17]], i32 0
55+
; CHECK-NEXT: br i1 [[TMP19]], label [[PRED_STORE_IF:%.*]], label [[PRED_STORE_CONTINUE:%.*]]
56+
; CHECK: pred.store.if:
57+
; CHECK-NEXT: [[TMP20:%.*]] = extractelement <4 x i64> [[TMP18]], i32 0
58+
; CHECK-NEXT: [[TMP21:%.*]] = getelementptr inbounds i32, ptr [[ARR]], i64 [[TMP20]]
59+
; CHECK-NEXT: store i32 65, ptr [[TMP21]], align 4
60+
; CHECK-NEXT: br label [[PRED_STORE_CONTINUE]]
61+
; CHECK: pred.store.continue:
62+
; CHECK-NEXT: [[TMP22:%.*]] = extractelement <4 x i1> [[TMP17]], i32 1
63+
; CHECK-NEXT: br i1 [[TMP22]], label [[PRED_STORE_IF5:%.*]], label [[PRED_STORE_CONTINUE6:%.*]]
64+
; CHECK: pred.store.if5:
65+
; CHECK-NEXT: [[TMP23:%.*]] = extractelement <4 x i64> [[TMP18]], i32 1
66+
; CHECK-NEXT: [[TMP24:%.*]] = getelementptr inbounds i32, ptr [[ARR]], i64 [[TMP23]]
67+
; CHECK-NEXT: store i32 65, ptr [[TMP24]], align 4
68+
; CHECK-NEXT: br label [[PRED_STORE_CONTINUE6]]
69+
; CHECK: pred.store.continue6:
70+
; CHECK-NEXT: [[TMP25:%.*]] = extractelement <4 x i1> [[TMP17]], i32 2
71+
; CHECK-NEXT: br i1 [[TMP25]], label [[PRED_STORE_IF7:%.*]], label [[PRED_STORE_CONTINUE8:%.*]]
72+
; CHECK: pred.store.if7:
73+
; CHECK-NEXT: [[TMP26:%.*]] = extractelement <4 x i64> [[TMP18]], i32 2
74+
; CHECK-NEXT: [[TMP27:%.*]] = getelementptr inbounds i32, ptr [[ARR]], i64 [[TMP26]]
75+
; CHECK-NEXT: store i32 65, ptr [[TMP27]], align 4
76+
; CHECK-NEXT: br label [[PRED_STORE_CONTINUE8]]
77+
; CHECK: pred.store.continue8:
78+
; CHECK-NEXT: [[TMP28:%.*]] = extractelement <4 x i1> [[TMP17]], i32 3
79+
; CHECK-NEXT: br i1 [[TMP28]], label [[PRED_STORE_IF9:%.*]], label [[PRED_STORE_CONTINUE10]]
80+
; CHECK: pred.store.if9:
81+
; CHECK-NEXT: [[TMP29:%.*]] = extractelement <4 x i64> [[TMP18]], i32 3
82+
; CHECK-NEXT: [[TMP30:%.*]] = getelementptr inbounds i32, ptr [[ARR]], i64 [[TMP29]]
83+
; CHECK-NEXT: store i32 65, ptr [[TMP30]], align 4
84+
; CHECK-NEXT: br label [[PRED_STORE_CONTINUE10]]
85+
; CHECK: pred.store.continue10:
86+
; CHECK-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 4
87+
; CHECK-NEXT: [[VEC_IND_NEXT]] = add <4 x i64> [[VEC_IND]], <i64 4, i64 4, i64 4, i64 4>
88+
; CHECK-NEXT: [[TMP31:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
89+
; CHECK-NEXT: br i1 [[TMP31]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
90+
; CHECK: middle.block:
91+
; CHECK-NEXT: [[CMO:%.*]] = sub i64 [[N_VEC]], 1
92+
; CHECK-NEXT: [[IND_ESCAPE:%.*]] = add i64 1, [[CMO]]
93+
; CHECK-NEXT: br i1 true, label [[LOAD_VAL:%.*]], label [[SCALAR_PH]]
94+
; CHECK: scalar.ph:
95+
; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 1, [[PREHEADER]] ], [ 1, [[VECTOR_SCEVCHECK]] ]
96+
; CHECK-NEXT: [[BC_RESUME_VAL2:%.*]] = phi i8 [ [[IND_END1]], [[MIDDLE_BLOCK]] ], [ 1, [[PREHEADER]] ], [ 1, [[VECTOR_SCEVCHECK]] ]
97+
; CHECK-NEXT: br label [[LOOP:%.*]]
98+
; CHECK: loop:
99+
; CHECK-NEXT: [[CONV:%.*]] = phi i64 [ [[CONV2:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
100+
; CHECK-NEXT: [[I:%.*]] = phi i8 [ [[INC:%.*]], [[LOOP]] ], [ [[BC_RESUME_VAL2]], [[SCALAR_PH]] ]
101+
; CHECK-NEXT: [[SUB:%.*]] = add nsw i64 [[CONV]], -1
102+
; CHECK-NEXT: [[PTR:%.*]] = getelementptr inbounds i32, ptr [[ARR]], i64 [[SUB]]
103+
; CHECK-NEXT: store i32 65, ptr [[PTR]], align 4
104+
; CHECK-NEXT: [[INC]] = add i8 [[I]], 1
105+
; CHECK-NEXT: [[CONV2]] = zext i8 [[INC]] to i64
106+
; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i64 [[CONV2]], [[N]]
107+
; CHECK-NEXT: br i1 [[CMP2]], label [[LOOP]], label [[LOAD_VAL]], !llvm.loop [[LOOP4:![0-9]+]]
108+
; CHECK: load_val:
109+
; CHECK-NEXT: [[FINAL:%.*]] = phi i64 [ [[CONV]], [[LOOP]] ], [ [[IND_ESCAPE]], [[MIDDLE_BLOCK]] ]
110+
; CHECK-NEXT: [[PTR2:%.*]] = getelementptr inbounds i32, ptr [[ARR]], i64 [[FINAL]]
111+
; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr [[PTR2]], align 4
112+
; CHECK-NEXT: br label [[DONE]]
113+
; CHECK: done:
114+
; CHECK-NEXT: [[VALUE:%.*]] = phi i32 [ [[VAL]], [[LOAD_VAL]] ], [ 0, [[ENTRY:%.*]] ]
115+
; CHECK-NEXT: ret i32 [[VALUE]]
116+
;
117+
entry:
118+
%cmp1 = icmp ugt i64 %n, 1
119+
br i1 %cmp1, label %preheader, label %done
120+
121+
preheader:
122+
br label %loop
123+
124+
loop:
125+
%conv = phi i64 [ %conv2, %loop ], [ 1, %preheader ]
126+
%i = phi i8 [ %inc, %loop ], [ 1, %preheader ]
127+
%sub = add nsw i64 %conv, -1
128+
%ptr = getelementptr inbounds i32, ptr %arr, i64 %sub
129+
store i32 65, ptr %ptr, align 4
130+
%inc = add i8 %i, 1
131+
%conv2 = zext i8 %inc to i64
132+
%cmp2 = icmp ult i64 %conv2, %n
133+
br i1 %cmp2, label %loop, label %load_val, !llvm.loop !0
134+
135+
load_val:
136+
%final = phi i64 [ %conv, %loop ]
137+
%ptr2 = getelementptr inbounds i32, ptr %arr, i64 %final
138+
%val = load i32, ptr %ptr2, align 4
139+
br label %done
140+
141+
done:
142+
%value = phi i32 [ %val, %load_val ], [ 0, %entry ]
143+
ret i32 %value
144+
145+
}
146+
147+
!0 = distinct !{!0, !1, !2, !3}
148+
!1 = !{!"llvm.loop.unroll.disable"}
149+
!2 = !{!"llvm.loop.vectorize.predicate.enable", i1 true}
150+
!3 = !{!"llvm.loop.vectorize.enable", i1 true}

0 commit comments

Comments
 (0)