1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2 ; RUN: opt -p loop-vectorize -S %s | FileCheck %s
4 target triple = "arm64-apple-macosx11.0.0"
6 define void @fshl_operand_first_order_recurrence(ptr %dst, ptr noalias %src) {
7 ; CHECK-LABEL: define void @fshl_operand_first_order_recurrence(
8 ; CHECK-SAME: ptr [[DST:%.*]], ptr noalias [[SRC:%.*]]) {
9 ; CHECK-NEXT: [[ENTRY:.*]]:
10 ; CHECK-NEXT: br i1 false, label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
11 ; CHECK: [[VECTOR_PH]]:
12 ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
13 ; CHECK: [[VECTOR_BODY]]:
14 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
15 ; CHECK-NEXT: [[VECTOR_RECUR:%.*]] = phi <2 x i64> [ <i64 poison, i64 0>, %[[VECTOR_PH]] ], [ [[WIDE_LOAD1:%.*]], %[[VECTOR_BODY]] ]
16 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
17 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[SRC]], i64 [[TMP0]]
18 ; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 0
19 ; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds i64, ptr [[TMP2]], i32 2
20 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <2 x i64>, ptr [[TMP4]], align 8
21 ; CHECK-NEXT: [[WIDE_LOAD1]] = load <2 x i64>, ptr [[TMP5]], align 8
22 ; CHECK-NEXT: [[TMP6:%.*]] = shufflevector <2 x i64> [[VECTOR_RECUR]], <2 x i64> [[WIDE_LOAD]], <2 x i32> <i32 1, i32 2>
23 ; CHECK-NEXT: [[TMP7:%.*]] = shufflevector <2 x i64> [[WIDE_LOAD]], <2 x i64> [[WIDE_LOAD1]], <2 x i32> <i32 1, i32 2>
24 ; CHECK-NEXT: [[TMP8:%.*]] = call <2 x i64> @llvm.fshl.v2i64(<2 x i64> splat (i64 1), <2 x i64> [[TMP6]], <2 x i64> splat (i64 1))
25 ; CHECK-NEXT: [[TMP9:%.*]] = call <2 x i64> @llvm.fshl.v2i64(<2 x i64> splat (i64 1), <2 x i64> [[TMP7]], <2 x i64> splat (i64 1))
26 ; CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds i64, ptr [[DST]], i64 [[TMP0]]
27 ; CHECK-NEXT: [[TMP12:%.*]] = getelementptr inbounds i64, ptr [[TMP10]], i32 0
28 ; CHECK-NEXT: [[TMP13:%.*]] = getelementptr inbounds i64, ptr [[TMP10]], i32 2
29 ; CHECK-NEXT: store <2 x i64> [[TMP8]], ptr [[TMP12]], align 8
30 ; CHECK-NEXT: store <2 x i64> [[TMP9]], ptr [[TMP13]], align 8
31 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
32 ; CHECK-NEXT: [[TMP14:%.*]] = icmp eq i64 [[INDEX_NEXT]], 100
33 ; CHECK-NEXT: br i1 [[TMP14]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
34 ; CHECK: [[MIDDLE_BLOCK]]:
35 ; CHECK-NEXT: [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <2 x i64> [[WIDE_LOAD1]], i32 1
36 ; CHECK-NEXT: br i1 false, label %[[EXIT:.*]], label %[[SCALAR_PH]]
37 ; CHECK: [[SCALAR_PH]]:
38 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 100, %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
39 ; CHECK-NEXT: [[SCALAR_RECUR_INIT:%.*]] = phi i64 [ [[VECTOR_RECUR_EXTRACT]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
40 ; CHECK-NEXT: br label %[[LOOP:.*]]
42 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
43 ; CHECK-NEXT: [[RECUR:%.*]] = phi i64 [ [[SCALAR_RECUR_INIT]], %[[SCALAR_PH]] ], [ [[L:%.*]], %[[LOOP]] ]
44 ; CHECK-NEXT: [[GEP_SRC:%.*]] = getelementptr inbounds i64, ptr [[SRC]], i64 [[IV]]
45 ; CHECK-NEXT: [[L]] = load i64, ptr [[GEP_SRC]], align 8
46 ; CHECK-NEXT: [[OR:%.*]] = tail call i64 @llvm.fshl.i64(i64 1, i64 [[RECUR]], i64 1)
47 ; CHECK-NEXT: [[GEP_DST:%.*]] = getelementptr inbounds i64, ptr [[DST]], i64 [[IV]]
48 ; CHECK-NEXT: store i64 [[OR]], ptr [[GEP_DST]], align 8
49 ; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1
50 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV]], 100
51 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT]], label %[[LOOP]], !llvm.loop [[LOOP3:![0-9]+]]
53 ; CHECK-NEXT: ret void
59 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
60 %recur = phi i64 [ 0, %entry ], [ %l, %loop ]
61 %gep.src = getelementptr inbounds i64, ptr %src, i64 %iv
62 %l = load i64, ptr %gep.src, align 8
63 %or = tail call i64 @llvm.fshl.i64(i64 1, i64 %recur, i64 1)
64 %gep.dst = getelementptr inbounds i64, ptr %dst, i64 %iv
65 store i64 %or, ptr %gep.dst, align 8
66 %iv.next = add i64 %iv, 1
67 %exitcond.not = icmp eq i64 %iv, 100
68 br i1 %exitcond.not, label %exit, label %loop
74 ; Test case for https://github.com/llvm/llvm-project/issues/107016.
75 define void @powi_call(ptr %P) {
76 ; CHECK-LABEL: define void @powi_call(
77 ; CHECK-SAME: ptr [[P:%.*]]) {
78 ; CHECK-NEXT: [[ENTRY:.*]]:
79 ; CHECK-NEXT: br i1 false, label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
80 ; CHECK: [[VECTOR_PH]]:
81 ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
82 ; CHECK: [[VECTOR_BODY]]:
83 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
84 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
85 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds double, ptr [[P]], i64 [[TMP0]]
86 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds double, ptr [[TMP1]], i32 0
87 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <2 x double>, ptr [[TMP2]], align 8
88 ; CHECK-NEXT: [[TMP3:%.*]] = call <2 x double> @llvm.powi.v2f64.i32(<2 x double> [[WIDE_LOAD]], i32 3)
89 ; CHECK-NEXT: store <2 x double> [[TMP3]], ptr [[TMP2]], align 8
90 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
91 ; CHECK-NEXT: br i1 true, label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
92 ; CHECK: [[MIDDLE_BLOCK]]:
93 ; CHECK-NEXT: br i1 true, label %[[EXIT:.*]], label %[[SCALAR_PH]]
94 ; CHECK: [[SCALAR_PH]]:
95 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 2, %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
96 ; CHECK-NEXT: br label %[[LOOP:.*]]
98 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
99 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds double, ptr [[P]], i64 [[IV]]
100 ; CHECK-NEXT: [[L:%.*]] = load double, ptr [[GEP]], align 8
101 ; CHECK-NEXT: [[POWI:%.*]] = tail call double @llvm.powi.f64.i32(double [[L]], i32 3)
102 ; CHECK-NEXT: store double [[POWI]], ptr [[GEP]], align 8
103 ; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1
104 ; CHECK-NEXT: [[EC:%.*]] = icmp eq i64 [[IV]], 1
105 ; CHECK-NEXT: br i1 [[EC]], label %[[EXIT]], label %[[LOOP]], !llvm.loop [[LOOP5:![0-9]+]]
107 ; CHECK-NEXT: ret void
113 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
114 %gep = getelementptr inbounds double, ptr %P, i64 %iv
115 %l = load double, ptr %gep
116 %powi = tail call double @llvm.powi.f64.i32(double %l, i32 3)
117 store double %powi, ptr %gep, align 8
118 %iv.next = add i64 %iv, 1
119 %ec = icmp eq i64 %iv, 1
120 br i1 %ec, label %exit, label %loop
126 define void @call_scalarized(ptr noalias %src, ptr noalias %dst) {
127 ; CHECK-LABEL: define void @call_scalarized(
128 ; CHECK-SAME: ptr noalias [[SRC:%.*]], ptr noalias [[DST:%.*]]) {
129 ; CHECK-NEXT: [[ENTRY:.*]]:
130 ; CHECK-NEXT: br label %[[LOOP_HEADER:.*]]
131 ; CHECK: [[LOOP_HEADER]]:
132 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 100, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP_LATCH:.*]] ]
133 ; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], -1
134 ; CHECK-NEXT: [[GEP_SRC:%.*]] = getelementptr double, ptr [[SRC]], i64 [[IV_NEXT]]
135 ; CHECK-NEXT: [[L:%.*]] = load double, ptr [[GEP_SRC]], align 8
136 ; CHECK-NEXT: [[CMP295:%.*]] = fcmp une double [[L]], 4.000000e+00
137 ; CHECK-NEXT: [[CMP299:%.*]] = fcmp ugt double [[L]], 0.000000e+00
138 ; CHECK-NEXT: [[OR_COND:%.*]] = or i1 [[CMP295]], [[CMP299]]
139 ; CHECK-NEXT: br i1 [[OR_COND]], label %[[LOOP_LATCH]], label %[[THEN:.*]]
141 ; CHECK-NEXT: [[SQRT:%.*]] = call double @llvm.sqrt.f64(double [[L]])
142 ; CHECK-NEXT: [[GEP_DST:%.*]] = getelementptr double, ptr [[DST]], i64 [[IV_NEXT]]
143 ; CHECK-NEXT: store double [[SQRT]], ptr [[GEP_DST]], align 8
144 ; CHECK-NEXT: br label %[[LOOP_LATCH]]
145 ; CHECK: [[LOOP_LATCH]]:
146 ; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], 0
147 ; CHECK-NEXT: br i1 [[TOBOOL_NOT]], label %[[EXIT:.*]], label %[[LOOP_HEADER]]
149 ; CHECK-NEXT: ret void
152 br label %loop.header
155 %iv = phi i64 [ 100, %entry ], [ %iv.next, %loop.latch ]
156 %iv.next = add i64 %iv, -1
157 %gep.src = getelementptr double, ptr %src, i64 %iv.next
158 %l = load double, ptr %gep.src, align 8
159 %cmp295 = fcmp une double %l, 4.000000e+00
160 %cmp299 = fcmp ugt double %l, 0.000000e+00
161 %or.cond = or i1 %cmp295, %cmp299
162 br i1 %or.cond, label %loop.latch, label %then
165 %sqrt = call double @llvm.sqrt.f64(double %l)
166 %gep.dst = getelementptr double, ptr %dst, i64 %iv.next
167 store double %sqrt, ptr %gep.dst, align 8
171 %tobool.not = icmp eq i64 %iv.next, 0
172 br i1 %tobool.not, label %exit, label %loop.header
178 define void @call_forced_scalar(ptr %src.1, ptr %src.2, ptr noalias %dst.1, ptr noalias %dst.2) {
179 ; CHECK-LABEL: define void @call_forced_scalar(
180 ; CHECK-SAME: ptr [[SRC_1:%.*]], ptr [[SRC_2:%.*]], ptr noalias [[DST_1:%.*]], ptr noalias [[DST_2:%.*]]) {
181 ; CHECK-NEXT: [[ENTRY:.*]]:
182 ; CHECK-NEXT: br label %[[LOOP:.*]]
184 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
185 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[SRC_1]], align 4
186 ; CHECK-NEXT: [[SMAX:%.*]] = tail call i32 @llvm.smax.i32(i32 [[TMP0]], i32 0)
187 ; CHECK-NEXT: [[UMIN:%.*]] = tail call i32 @llvm.umin.i32(i32 [[SMAX]], i32 1)
188 ; CHECK-NEXT: [[UMIN_EXT:%.*]] = zext i32 [[UMIN]] to i64
189 ; CHECK-NEXT: [[GEP_SRC_2:%.*]] = getelementptr i8, ptr [[SRC_2]], i64 [[UMIN_EXT]]
190 ; CHECK-NEXT: [[TMP1:%.*]] = load i8, ptr [[GEP_SRC_2]], align 1
191 ; CHECK-NEXT: [[L_EXT:%.*]] = zext i8 [[TMP1]] to i32
192 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 3, [[L_EXT]]
193 ; CHECK-NEXT: store i32 [[MUL]], ptr [[DST_1]], align 4
194 ; CHECK-NEXT: [[GEP_DST_2:%.*]] = getelementptr i32, ptr [[DST_2]], i64 [[IV]]
195 ; CHECK-NEXT: store i32 0, ptr [[GEP_DST_2]], align 4
196 ; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1
197 ; CHECK-NEXT: [[EC:%.*]] = icmp eq i64 [[IV_NEXT]], 0
198 ; CHECK-NEXT: br i1 [[EC]], label %[[EXIT:.*]], label %[[LOOP]]
200 ; CHECK-NEXT: ret void
206 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
207 %0 = load i32, ptr %src.1, align 4
208 %smax = tail call i32 @llvm.smax.i32(i32 %0, i32 0)
209 %umin = tail call i32 @llvm.umin.i32(i32 %smax, i32 1)
210 %umin.ext = zext i32 %umin to i64
211 %gep.src.2 = getelementptr i8, ptr %src.2, i64 %umin.ext
212 %1 = load i8, ptr %gep.src.2, align 1
213 %l.ext = zext i8 %1 to i32
214 %mul = mul i32 3, %l.ext
215 store i32 %mul, ptr %dst.1, align 4
216 %gep.dst.2 = getelementptr i32, ptr %dst.2, i64 %iv
217 store i32 0, ptr %gep.dst.2, align 4
218 %iv.next = add i64 %iv, 1
219 %ec = icmp eq i64 %iv.next, 0
220 br i1 %ec, label %exit, label %loop
226 declare i32 @llvm.smax.i32(i32, i32)
227 declare i32 @llvm.umin.i32(i32, i32)
228 declare double @llvm.sqrt.f64(double)
229 declare double @llvm.powi.f64.i32(double, i32)
230 declare i64 @llvm.fshl.i64(i64, i64, i64)
232 ; CHECK: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]]}
233 ; CHECK: [[META1]] = !{!"llvm.loop.isvectorized", i32 1}
234 ; CHECK: [[META2]] = !{!"llvm.loop.unroll.runtime.disable"}
235 ; CHECK: [[LOOP3]] = distinct !{[[LOOP3]], [[META2]], [[META1]]}
236 ; CHECK: [[LOOP4]] = distinct !{[[LOOP4]], [[META1]], [[META2]]}
237 ; CHECK: [[LOOP5]] = distinct !{[[LOOP5]], [[META2]], [[META1]]}