1 ; RUN: opt -mtriple=thumbv8m.main -mcpu=cortex-m33 -arm-parallel-dsp %s -S -o - | FileCheck %s
2 ; RUN: opt -mtriple=arm-arm-eabi -mcpu=cortex-m0 < %s -arm-parallel-dsp -S | FileCheck %s --check-prefix=CHECK-UNSUPPORTED
3 ; RUN: opt -mtriple=arm-arm-eabi -mcpu=cortex-m33 -mattr=-dsp < %s -arm-parallel-dsp -S | FileCheck %s --check-prefix=CHECK-UNSUPPORTED
4 ; RUN: opt -mtriple=armeb-arm-eabi -mcpu=cortex-m33 < %s -arm-parallel-dsp -S | FileCheck %s --check-prefix=CHECK-UNSUPPORTED
6 define i32 @smladx(i16* nocapture readonly %pIn1, i16* nocapture readonly %pIn2, i32 %j, i32 %limit) {
9 ; CHECK: = phi i32 [ 0, %for.body.preheader.new ],
10 ; CHECK: [[ACC0:%[^ ]+]] = phi i32 [ 0, %for.body.preheader.new ], [ [[ACC2:%[^ ]+]], %for.body ]
11 ; CHECK: [[PIN21:%[^ ]+]] = bitcast i16* %pIn2.1 to i32*
12 ; CHECK: [[IN21:%[^ ]+]] = load i32, i32* [[PIN21]], align 2
13 ; CHECK: [[PIN10:%[^ ]+]] = bitcast i16* %pIn1.0 to i32*
14 ; CHECK: [[IN10:%[^ ]+]] = load i32, i32* [[PIN10]], align 2
15 ; CHECK: [[ACC1:%[^ ]+]] = call i32 @llvm.arm.smladx(i32 [[IN21]], i32 [[IN10]], i32 [[ACC0]])
17 ; CHECK: [[PIN23:%[^ ]+]] = bitcast i16* %pIn2.3 to i32*
18 ; CHECK: [[IN23:%[^ ]+]] = load i32, i32* [[PIN23]], align 2
19 ; CHECK: [[PIN12:%[^ ]+]] = bitcast i16* %pIn1.2 to i32*
20 ; CHECK: [[IN12:%[^ ]+]] = load i32, i32* [[PIN12]], align 2
21 ; CHECK: [[ACC2]] = call i32 @llvm.arm.smladx(i32 [[IN23]], i32 [[IN12]], i32 [[ACC1]])
22 ; CHECK-NOT: call i32 @llvm.arm.smlad
23 ; CHECK-UNSUPPORTED-NOT: call i32 @llvm.arm.smlad
26 %cmp9 = icmp eq i32 %limit, 0
27 br i1 %cmp9, label %for.cond.cleanup, label %for.body.preheader
30 %0 = add i32 %limit, -1
31 %xtraiter = and i32 %limit, 3
32 %1 = icmp ult i32 %0, 3
33 br i1 %1, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body.preheader.new
35 for.body.preheader.new:
36 %unroll_iter = sub i32 %limit, %xtraiter
39 for.cond.cleanup.loopexit.unr-lcssa:
40 %add.lcssa.ph = phi i32 [ undef, %for.body.preheader ], [ %add.3, %for.body ]
41 %i.011.unr = phi i32 [ 0, %for.body.preheader ], [ %inc.3, %for.body ]
42 %sum.010.unr = phi i32 [ 0, %for.body.preheader ], [ %add.3, %for.body ]
43 %lcmp.mod = icmp eq i32 %xtraiter, 0
44 br i1 %lcmp.mod, label %for.cond.cleanup, label %for.body.epil
47 %i.011.epil = phi i32 [ %inc.epil, %for.body.epil ], [ %i.011.unr, %for.cond.cleanup.loopexit.unr-lcssa ]
48 %sum.010.epil = phi i32 [ %add.epil, %for.body.epil ], [ %sum.010.unr, %for.cond.cleanup.loopexit.unr-lcssa ]
49 %epil.iter = phi i32 [ %epil.iter.sub, %for.body.epil ], [ %xtraiter, %for.cond.cleanup.loopexit.unr-lcssa ]
50 %sub.epil = sub i32 %j, %i.011.epil
51 %arrayidx.epil = getelementptr inbounds i16, i16* %pIn2, i32 %sub.epil
52 %2 = load i16, i16* %arrayidx.epil, align 2
53 %conv.epil = sext i16 %2 to i32
54 %arrayidx1.epil = getelementptr inbounds i16, i16* %pIn1, i32 %i.011.epil
55 %3 = load i16, i16* %arrayidx1.epil, align 2
56 %conv2.epil = sext i16 %3 to i32
57 %mul.epil = mul nsw i32 %conv2.epil, %conv.epil
58 %add.epil = add nsw i32 %mul.epil, %sum.010.epil
59 %inc.epil = add nuw i32 %i.011.epil, 1
60 %epil.iter.sub = add i32 %epil.iter, -1
61 %epil.iter.cmp = icmp eq i32 %epil.iter.sub, 0
62 br i1 %epil.iter.cmp, label %for.cond.cleanup, label %for.body.epil
65 %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add.lcssa.ph, %for.cond.cleanup.loopexit.unr-lcssa ], [ %add.epil, %for.body.epil ]
69 %i.011 = phi i32 [ 0, %for.body.preheader.new ], [ %inc.3, %for.body ]
70 %sum.010 = phi i32 [ 0, %for.body.preheader.new ], [ %add.3, %for.body ]
71 %niter = phi i32 [ %unroll_iter, %for.body.preheader.new ], [ %niter.nsub.3, %for.body ]
72 %pIn2Base = phi i16* [ %pIn2, %for.body.preheader.new ], [ %pIn2.4, %for.body ]
73 %pIn2.0 = getelementptr inbounds i16, i16* %pIn2Base, i32 0
74 %In2 = load i16, i16* %pIn2.0, align 2
75 %pIn1.0 = getelementptr inbounds i16, i16* %pIn1, i32 %i.011
76 %In1 = load i16, i16* %pIn1.0, align 2
77 %inc = or i32 %i.011, 1
78 %pIn2.1 = getelementptr inbounds i16, i16* %pIn2Base, i32 -1
79 %In2.1 = load i16, i16* %pIn2.1, align 2
80 %pIn1.1 = getelementptr inbounds i16, i16* %pIn1, i32 %inc
81 %In1.1 = load i16, i16* %pIn1.1, align 2
82 %inc.1 = or i32 %i.011, 2
83 %pIn2.2 = getelementptr inbounds i16, i16* %pIn2Base, i32 -2
84 %In2.2 = load i16, i16* %pIn2.2, align 2
85 %pIn1.2 = getelementptr inbounds i16, i16* %pIn1, i32 %inc.1
86 %In1.2 = load i16, i16* %pIn1.2, align 2
87 %inc.2 = or i32 %i.011, 3
88 %pIn2.3 = getelementptr inbounds i16, i16* %pIn2Base, i32 -3
89 %In2.3 = load i16, i16* %pIn2.3, align 2
90 %pIn1.3 = getelementptr inbounds i16, i16* %pIn1, i32 %inc.2
91 %In1.3 = load i16, i16* %pIn1.3, align 2
92 %sextIn1 = sext i16 %In1 to i32
93 %sextIn1.1 = sext i16 %In1.1 to i32
94 %sextIn1.2 = sext i16 %In1.2 to i32
95 %sextIn1.3 = sext i16 %In1.3 to i32
96 %sextIn2 = sext i16 %In2 to i32
97 %sextIn2.1 = sext i16 %In2.1 to i32
98 %sextIn2.2 = sext i16 %In2.2 to i32
99 %sextIn2.3 = sext i16 %In2.3 to i32
100 %mul = mul nsw i32 %sextIn1, %sextIn2
101 %mul.1 = mul nsw i32 %sextIn1.1, %sextIn2.1
102 %mul.2 = mul nsw i32 %sextIn1.2, %sextIn2.2
103 %mul.3 = mul nsw i32 %sextIn1.3, %sextIn2.3
104 %add = add nsw i32 %mul, %sum.010
105 %add.1 = add nsw i32 %mul.1, %add
106 %add.2 = add nsw i32 %mul.2, %add.1
107 %add.3 = add nsw i32 %mul.3, %add.2
108 %inc.3 = add i32 %i.011, 4
109 %pIn2.4 = getelementptr inbounds i16, i16* %pIn2Base, i32 -4
110 %niter.nsub.3 = add i32 %niter, -4
111 %niter.ncmp.3 = icmp eq i32 %niter.nsub.3, 0
112 br i1 %niter.ncmp.3, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body
115 define i32 @smladx_swap(i16* nocapture readonly %pIn1, i16* nocapture readonly %pIn2, i32 %j, i32 %limit) {
117 ; CHECK-LABEL: smladx_swap
118 ; CHECK: for.body.preheader.new:
119 ; CHECK: [[PIN1Base:[^ ]+]] = getelementptr i16, i16* %pIn1
120 ; CHECK: [[PIN2Base:[^ ]+]] = getelementptr i16, i16* %pIn2
123 ; CHECK: [[PIN2:%[^ ]+]] = phi i16* [ [[PIN2_NEXT:%[^ ]+]], %for.body ], [ [[PIN2Base]], %for.body.preheader.new ]
124 ; CHECK: [[PIN1:%[^ ]+]] = phi i16* [ [[PIN1_NEXT:%[^ ]+]], %for.body ], [ [[PIN1Base]], %for.body.preheader.new ]
125 ; CHECK: [[IV:%[^ ]+]] = phi i32
126 ; CHECK: [[ACC0:%[^ ]+]] = phi i32 [ 0, %for.body.preheader.new ], [ [[ACC2:%[^ ]+]], %for.body ]
128 ; CHECK: [[PIN2_CAST:%[^ ]+]] = bitcast i16* [[PIN2]] to i32*
129 ; CHECK: [[IN2:%[^ ]+]] = load i32, i32* [[PIN2_CAST]], align 2
131 ; CHECK: [[PIN1_2:%[^ ]+]] = getelementptr i16, i16* [[PIN1]], i32 -2
132 ; CHECK: [[PIN1_2_CAST:%[^ ]+]] = bitcast i16* [[PIN1_2]] to i32*
133 ; CHECK: [[IN1_2:%[^ ]+]] = load i32, i32* [[PIN1_2_CAST]], align 2
134 ; CHECK: [[ACC1:%[^ ]+]] = call i32 @llvm.arm.smladx(i32 [[IN2]], i32 [[IN1_2]], i32 [[ACC0]])
136 ; CHECK: [[PIN2_2:%[^ ]+]] = getelementptr i16, i16* [[PIN2]], i32 -2
137 ; CHECK: [[PIN2_2_CAST:%[^ ]+]] = bitcast i16* [[PIN2_2]] to i32*
138 ; CHECK: [[IN2_2:%[^ ]+]] = load i32, i32* [[PIN2_2_CAST]], align 2
140 ; CHECK: [[PIN1_CAST:%[^ ]+]] = bitcast i16* [[PIN1]] to i32*
141 ; CHECK: [[IN1:%[^ ]+]] = load i32, i32* [[PIN1_CAST]], align 2
143 ; CHECK: [[ACC2]] = call i32 @llvm.arm.smladx(i32 [[IN2_2]], i32 [[IN1]], i32 [[ACC1]])
145 ; CHECK: [[PIN1_NEXT]] = getelementptr i16, i16* [[PIN1]], i32 4
146 ; CHECK: [[PIN2_NEXT]] = getelementptr i16, i16* [[PIN2]], i32 -4
148 ; CHECK-NOT: call i32 @llvm.arm.smlad
149 ; CHECK-UNSUPPORTED-NOT: call i32 @llvm.arm.smlad
152 %cmp9 = icmp eq i32 %limit, 0
153 br i1 %cmp9, label %for.cond.cleanup, label %for.body.preheader
156 %0 = add i32 %limit, -1
157 %xtraiter = and i32 %limit, 3
158 %1 = icmp ult i32 %0, 3
159 br i1 %1, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body.preheader.new
161 for.body.preheader.new:
162 %unroll_iter = sub i32 %limit, %xtraiter
163 %scevgep6 = getelementptr i16, i16* %pIn1, i32 2
165 %scevgep11 = getelementptr i16, i16* %pIn2, i32 %2
168 for.cond.cleanup.loopexit.unr-lcssa:
169 %add.lcssa.ph = phi i32 [ undef, %for.body.preheader ], [ %add.3, %for.body ]
170 %i.011.unr = phi i32 [ 0, %for.body.preheader ], [ %inc.3, %for.body ]
171 %sum.010.unr = phi i32 [ 0, %for.body.preheader ], [ %add.3, %for.body ]
172 %lcmp.mod = icmp eq i32 %xtraiter, 0
173 br i1 %lcmp.mod, label %for.cond.cleanup, label %for.body.epil.preheader
175 for.body.epil.preheader:
176 %scevgep = getelementptr i16, i16* %pIn1, i32 %i.011.unr
177 %3 = sub i32 %j, %i.011.unr
178 %scevgep2 = getelementptr i16, i16* %pIn2, i32 %3
179 %4 = sub i32 0, %xtraiter
180 br label %for.body.epil
183 %lsr.iv5 = phi i32 [ %4, %for.body.epil.preheader ], [ %lsr.iv.next, %for.body.epil ]
184 %lsr.iv3 = phi i16* [ %scevgep2, %for.body.epil.preheader ], [ %scevgep4, %for.body.epil ]
185 %lsr.iv = phi i16* [ %scevgep, %for.body.epil.preheader ], [ %scevgep1, %for.body.epil ]
186 %sum.010.epil = phi i32 [ %add.epil, %for.body.epil ], [ %sum.010.unr, %for.body.epil.preheader ]
187 %5 = load i16, i16* %lsr.iv3, align 2
188 %conv.epil = sext i16 %5 to i32
189 %6 = load i16, i16* %lsr.iv, align 2
190 %conv2.epil = sext i16 %6 to i32
191 %mul.epil = mul nsw i32 %conv2.epil, %conv.epil
192 %add.epil = add nsw i32 %mul.epil, %sum.010.epil
193 %scevgep1 = getelementptr i16, i16* %lsr.iv, i32 1
194 %scevgep4 = getelementptr i16, i16* %lsr.iv3, i32 -1
195 %lsr.iv.next = add nsw i32 %lsr.iv5, 1
196 %epil.iter.cmp = icmp eq i32 %lsr.iv.next, 0
197 br i1 %epil.iter.cmp, label %for.cond.cleanup, label %for.body.epil
200 %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add.lcssa.ph, %for.cond.cleanup.loopexit.unr-lcssa ], [ %add.epil, %for.body.epil ]
204 %pin2 = phi i16* [ %pin2_sub4, %for.body ], [ %scevgep11, %for.body.preheader.new ]
205 %pin1 = phi i16* [ %pin1_add4, %for.body ], [ %scevgep6, %for.body.preheader.new ]
206 %i.011 = phi i32 [ 0, %for.body.preheader.new ], [ %inc.3, %for.body ]
207 %sum.010 = phi i32 [ 0, %for.body.preheader.new ], [ %add.3, %for.body ]
208 %pin2_add1 = getelementptr i16, i16* %pin2, i32 1
209 %In2 = load i16, i16* %pin2_add1, align 2
210 %pin1_sub2 = getelementptr i16, i16* %pin1, i32 -2
211 %In1 = load i16, i16* %pin1_sub2, align 2
212 %In2.1 = load i16, i16* %pin2, align 2
213 %pin1_sub1 = getelementptr i16, i16* %pin1, i32 -1
214 %In1.1 = load i16, i16* %pin1_sub1, align 2
215 %pin2_sub1 = getelementptr i16, i16* %pin2, i32 -1
216 %In2.2 = load i16, i16* %pin2_sub1, align 2
217 %In1.2 = load i16, i16* %pin1, align 2
218 %pin2_sub2 = getelementptr i16, i16* %pin2, i32 -2
219 %In2.3 = load i16, i16* %pin2_sub2, align 2
220 %pin1_add1 = getelementptr i16, i16* %pin1, i32 1
221 %In1.3 = load i16, i16* %pin1_add1, align 2
222 %sextIn2 = sext i16 %In2 to i32
223 %sextIn1 = sext i16 %In1 to i32
224 %sextIn2.1 = sext i16 %In2.1 to i32
225 %sextIn1.1 = sext i16 %In1.1 to i32
226 %sextIn2.2 = sext i16 %In2.2 to i32
227 %sextIn1.2 = sext i16 %In1.2 to i32
228 %sextIn2.3 = sext i16 %In2.3 to i32
229 %sextIn1.3 = sext i16 %In1.3 to i32
230 %mul = mul nsw i32 %sextIn2, %sextIn1
231 %add = add nsw i32 %mul, %sum.010
232 %mul.1 = mul nsw i32 %sextIn2.1, %sextIn1.1
233 %add.1 = add nsw i32 %mul.1, %add
234 %mul.2 = mul nsw i32 %sextIn2.2, %sextIn1.2
235 %add.2 = add nsw i32 %mul.2, %add.1
236 %mul.3 = mul nsw i32 %sextIn2.3, %sextIn1.3
237 %add.3 = add nsw i32 %mul.3, %add.2
238 %inc.3 = add i32 %i.011, 4
239 %pin1_add4 = getelementptr i16, i16* %pin1, i32 4
240 %pin2_sub4 = getelementptr i16, i16* %pin2, i32 -4
241 %niter.ncmp.3 = icmp eq i32 %unroll_iter, %inc.3
242 br i1 %niter.ncmp.3, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body