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: [[PIN23:%[^ ]+]] = bitcast i16* %pIn2.3 to i32*
16 ; CHECK: [[IN23:%[^ ]+]] = load i32, i32* [[PIN23]], align 2
17 ; CHECK: [[PIN12:%[^ ]+]] = bitcast i16* %pIn1.2 to i32*
18 ; CHECK: [[IN12:%[^ ]+]] = load i32, i32* [[PIN12]], align 2
19 ; CHECK: [[ACC1:%[^ ]+]] = call i32 @llvm.arm.smladx(i32 [[IN23]], i32 [[IN12]], i32 [[ACC0]])
20 ; CHECK: [[ACC2]] = call i32 @llvm.arm.smladx(i32 [[IN21]], i32 [[IN10]], i32 [[ACC1]])
21 ; CHECK-NOT: call i32 @llvm.arm.smlad
22 ; CHECK-UNSUPPORTED-NOT: call i32 @llvm.arm.smlad
25 %cmp9 = icmp eq i32 %limit, 0
26 br i1 %cmp9, label %for.cond.cleanup, label %for.body.preheader
29 %0 = add i32 %limit, -1
30 %xtraiter = and i32 %limit, 3
31 %1 = icmp ult i32 %0, 3
32 br i1 %1, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body.preheader.new
34 for.body.preheader.new:
35 %unroll_iter = sub i32 %limit, %xtraiter
38 for.cond.cleanup.loopexit.unr-lcssa:
39 %add.lcssa.ph = phi i32 [ undef, %for.body.preheader ], [ %add.3, %for.body ]
40 %i.011.unr = phi i32 [ 0, %for.body.preheader ], [ %inc.3, %for.body ]
41 %sum.010.unr = phi i32 [ 0, %for.body.preheader ], [ %add.3, %for.body ]
42 %lcmp.mod = icmp eq i32 %xtraiter, 0
43 br i1 %lcmp.mod, label %for.cond.cleanup, label %for.body.epil
46 %i.011.epil = phi i32 [ %inc.epil, %for.body.epil ], [ %i.011.unr, %for.cond.cleanup.loopexit.unr-lcssa ]
47 %sum.010.epil = phi i32 [ %add.epil, %for.body.epil ], [ %sum.010.unr, %for.cond.cleanup.loopexit.unr-lcssa ]
48 %epil.iter = phi i32 [ %epil.iter.sub, %for.body.epil ], [ %xtraiter, %for.cond.cleanup.loopexit.unr-lcssa ]
49 %sub.epil = sub i32 %j, %i.011.epil
50 %arrayidx.epil = getelementptr inbounds i16, i16* %pIn2, i32 %sub.epil
51 %2 = load i16, i16* %arrayidx.epil, align 2
52 %conv.epil = sext i16 %2 to i32
53 %arrayidx1.epil = getelementptr inbounds i16, i16* %pIn1, i32 %i.011.epil
54 %3 = load i16, i16* %arrayidx1.epil, align 2
55 %conv2.epil = sext i16 %3 to i32
56 %mul.epil = mul nsw i32 %conv2.epil, %conv.epil
57 %add.epil = add nsw i32 %mul.epil, %sum.010.epil
58 %inc.epil = add nuw i32 %i.011.epil, 1
59 %epil.iter.sub = add i32 %epil.iter, -1
60 %epil.iter.cmp = icmp eq i32 %epil.iter.sub, 0
61 br i1 %epil.iter.cmp, label %for.cond.cleanup, label %for.body.epil
64 %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add.lcssa.ph, %for.cond.cleanup.loopexit.unr-lcssa ], [ %add.epil, %for.body.epil ]
68 %i.011 = phi i32 [ 0, %for.body.preheader.new ], [ %inc.3, %for.body ]
69 %sum.010 = phi i32 [ 0, %for.body.preheader.new ], [ %add.3, %for.body ]
70 %niter = phi i32 [ %unroll_iter, %for.body.preheader.new ], [ %niter.nsub.3, %for.body ]
71 %pIn2Base = phi i16* [ %pIn2, %for.body.preheader.new ], [ %pIn2.4, %for.body ]
72 %pIn2.0 = getelementptr inbounds i16, i16* %pIn2Base, i32 0
73 %In2 = load i16, i16* %pIn2.0, align 2
74 %pIn1.0 = getelementptr inbounds i16, i16* %pIn1, i32 %i.011
75 %In1 = load i16, i16* %pIn1.0, align 2
76 %inc = or i32 %i.011, 1
77 %pIn2.1 = getelementptr inbounds i16, i16* %pIn2Base, i32 -1
78 %In2.1 = load i16, i16* %pIn2.1, align 2
79 %pIn1.1 = getelementptr inbounds i16, i16* %pIn1, i32 %inc
80 %In1.1 = load i16, i16* %pIn1.1, align 2
81 %inc.1 = or i32 %i.011, 2
82 %pIn2.2 = getelementptr inbounds i16, i16* %pIn2Base, i32 -2
83 %In2.2 = load i16, i16* %pIn2.2, align 2
84 %pIn1.2 = getelementptr inbounds i16, i16* %pIn1, i32 %inc.1
85 %In1.2 = load i16, i16* %pIn1.2, align 2
86 %inc.2 = or i32 %i.011, 3
87 %pIn2.3 = getelementptr inbounds i16, i16* %pIn2Base, i32 -3
88 %In2.3 = load i16, i16* %pIn2.3, align 2
89 %pIn1.3 = getelementptr inbounds i16, i16* %pIn1, i32 %inc.2
90 %In1.3 = load i16, i16* %pIn1.3, align 2
91 %sextIn1 = sext i16 %In1 to i32
92 %sextIn1.1 = sext i16 %In1.1 to i32
93 %sextIn1.2 = sext i16 %In1.2 to i32
94 %sextIn1.3 = sext i16 %In1.3 to i32
95 %sextIn2 = sext i16 %In2 to i32
96 %sextIn2.1 = sext i16 %In2.1 to i32
97 %sextIn2.2 = sext i16 %In2.2 to i32
98 %sextIn2.3 = sext i16 %In2.3 to i32
99 %mul = mul nsw i32 %sextIn1, %sextIn2
100 %mul.1 = mul nsw i32 %sextIn1.1, %sextIn2.1
101 %mul.2 = mul nsw i32 %sextIn1.2, %sextIn2.2
102 %mul.3 = mul nsw i32 %sextIn1.3, %sextIn2.3
103 %add = add nsw i32 %mul, %sum.010
104 %add.1 = add nsw i32 %mul.1, %add
105 %add.2 = add nsw i32 %mul.2, %add.1
106 %add.3 = add nsw i32 %mul.3, %add.2
107 %inc.3 = add i32 %i.011, 4
108 %pIn2.4 = getelementptr inbounds i16, i16* %pIn2Base, i32 -4
109 %niter.nsub.3 = add i32 %niter, -4
110 %niter.ncmp.3 = icmp eq i32 %niter.nsub.3, 0
111 br i1 %niter.ncmp.3, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body
114 define i32 @smladx_swap(i16* nocapture readonly %pIn1, i16* nocapture readonly %pIn2, i32 %j, i32 %limit) {
116 ; CHECK-LABEL: smladx_swap
117 ; CHECK: for.body.preheader.new:
118 ; CHECK: [[PIN1Base:[^ ]+]] = getelementptr i16, i16* %pIn1
119 ; CHECK: [[PIN2Base:[^ ]+]] = getelementptr i16, i16* %pIn2
122 ; CHECK: [[PIN2:%[^ ]+]] = phi i16* [ [[PIN2_NEXT:%[^ ]+]], %for.body ], [ [[PIN2Base]], %for.body.preheader.new ]
123 ; CHECK: [[PIN1:%[^ ]+]] = phi i16* [ [[PIN1_NEXT:%[^ ]+]], %for.body ], [ [[PIN1Base]], %for.body.preheader.new ]
124 ; CHECK: [[IV:%[^ ]+]] = phi i32
125 ; CHECK: [[ACC0:%[^ ]+]] = phi i32 [ 0, %for.body.preheader.new ], [ [[ACC2:%[^ ]+]], %for.body ]
127 ; CHECK: [[PIN2_CAST:%[^ ]+]] = bitcast i16* [[PIN2]] to i32*
128 ; CHECK: [[IN2:%[^ ]+]] = load i32, i32* [[PIN2_CAST]], align 2
130 ; CHECK: [[PIN1_2:%[^ ]+]] = getelementptr i16, i16* [[PIN1]], i32 -2
131 ; CHECK: [[PIN1_2_CAST:%[^ ]+]] = bitcast i16* [[PIN1_2]] to i32*
132 ; CHECK: [[IN1_2:%[^ ]+]] = load i32, i32* [[PIN1_2_CAST]], align 2
134 ; CHECK: [[PIN2_2:%[^ ]+]] = getelementptr i16, i16* [[PIN2]], i32 -2
135 ; CHECK: [[PIN2_2_CAST:%[^ ]+]] = bitcast i16* [[PIN2_2]] to i32*
136 ; CHECK: [[IN2_2:%[^ ]+]] = load i32, i32* [[PIN2_2_CAST]], align 2
138 ; CHECK: [[PIN1_CAST:%[^ ]+]] = bitcast i16* [[PIN1]] to i32*
139 ; CHECK: [[IN1:%[^ ]+]] = load i32, i32* [[PIN1_CAST]], align 2
141 ; CHECK: [[ACC1:%[^ ]+]] = call i32 @llvm.arm.smladx(i32 [[IN2_2]], i32 [[IN1]], i32 [[ACC0]])
142 ; CHECK: [[ACC2]] = call i32 @llvm.arm.smladx(i32 [[IN2]], i32 [[IN1_2]], i32 [[ACC1]])
144 ; CHECK: [[PIN1_NEXT]] = getelementptr i16, i16* [[PIN1]], i32 4
145 ; CHECK: [[PIN2_NEXT]] = getelementptr i16, i16* [[PIN2]], i32 -4
147 ; CHECK-NOT: call i32 @llvm.arm.smlad
148 ; CHECK-UNSUPPORTED-NOT: call i32 @llvm.arm.smlad
151 %cmp9 = icmp eq i32 %limit, 0
152 br i1 %cmp9, label %for.cond.cleanup, label %for.body.preheader
155 %0 = add i32 %limit, -1
156 %xtraiter = and i32 %limit, 3
157 %1 = icmp ult i32 %0, 3
158 br i1 %1, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body.preheader.new
160 for.body.preheader.new:
161 %unroll_iter = sub i32 %limit, %xtraiter
162 %scevgep6 = getelementptr i16, i16* %pIn1, i32 2
164 %scevgep11 = getelementptr i16, i16* %pIn2, i32 %2
167 for.cond.cleanup.loopexit.unr-lcssa:
168 %add.lcssa.ph = phi i32 [ undef, %for.body.preheader ], [ %add.3, %for.body ]
169 %i.011.unr = phi i32 [ 0, %for.body.preheader ], [ %inc.3, %for.body ]
170 %sum.010.unr = phi i32 [ 0, %for.body.preheader ], [ %add.3, %for.body ]
171 %lcmp.mod = icmp eq i32 %xtraiter, 0
172 br i1 %lcmp.mod, label %for.cond.cleanup, label %for.body.epil.preheader
174 for.body.epil.preheader:
175 %scevgep = getelementptr i16, i16* %pIn1, i32 %i.011.unr
176 %3 = sub i32 %j, %i.011.unr
177 %scevgep2 = getelementptr i16, i16* %pIn2, i32 %3
178 %4 = sub i32 0, %xtraiter
179 br label %for.body.epil
182 %lsr.iv5 = phi i32 [ %4, %for.body.epil.preheader ], [ %lsr.iv.next, %for.body.epil ]
183 %lsr.iv3 = phi i16* [ %scevgep2, %for.body.epil.preheader ], [ %scevgep4, %for.body.epil ]
184 %lsr.iv = phi i16* [ %scevgep, %for.body.epil.preheader ], [ %scevgep1, %for.body.epil ]
185 %sum.010.epil = phi i32 [ %add.epil, %for.body.epil ], [ %sum.010.unr, %for.body.epil.preheader ]
186 %5 = load i16, i16* %lsr.iv3, align 2
187 %conv.epil = sext i16 %5 to i32
188 %6 = load i16, i16* %lsr.iv, align 2
189 %conv2.epil = sext i16 %6 to i32
190 %mul.epil = mul nsw i32 %conv2.epil, %conv.epil
191 %add.epil = add nsw i32 %mul.epil, %sum.010.epil
192 %scevgep1 = getelementptr i16, i16* %lsr.iv, i32 1
193 %scevgep4 = getelementptr i16, i16* %lsr.iv3, i32 -1
194 %lsr.iv.next = add nsw i32 %lsr.iv5, 1
195 %epil.iter.cmp = icmp eq i32 %lsr.iv.next, 0
196 br i1 %epil.iter.cmp, label %for.cond.cleanup, label %for.body.epil
199 %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add.lcssa.ph, %for.cond.cleanup.loopexit.unr-lcssa ], [ %add.epil, %for.body.epil ]
203 %pin2 = phi i16* [ %pin2_sub4, %for.body ], [ %scevgep11, %for.body.preheader.new ]
204 %pin1 = phi i16* [ %pin1_add4, %for.body ], [ %scevgep6, %for.body.preheader.new ]
205 %i.011 = phi i32 [ 0, %for.body.preheader.new ], [ %inc.3, %for.body ]
206 %sum.010 = phi i32 [ 0, %for.body.preheader.new ], [ %add.3, %for.body ]
207 %pin2_add1 = getelementptr i16, i16* %pin2, i32 1
208 %In2 = load i16, i16* %pin2_add1, align 2
209 %pin1_sub2 = getelementptr i16, i16* %pin1, i32 -2
210 %In1 = load i16, i16* %pin1_sub2, align 2
211 %In2.1 = load i16, i16* %pin2, align 2
212 %pin1_sub1 = getelementptr i16, i16* %pin1, i32 -1
213 %In1.1 = load i16, i16* %pin1_sub1, align 2
214 %pin2_sub1 = getelementptr i16, i16* %pin2, i32 -1
215 %In2.2 = load i16, i16* %pin2_sub1, align 2
216 %In1.2 = load i16, i16* %pin1, align 2
217 %pin2_sub2 = getelementptr i16, i16* %pin2, i32 -2
218 %In2.3 = load i16, i16* %pin2_sub2, align 2
219 %pin1_add1 = getelementptr i16, i16* %pin1, i32 1
220 %In1.3 = load i16, i16* %pin1_add1, align 2
221 %sextIn2 = sext i16 %In2 to i32
222 %sextIn1 = sext i16 %In1 to i32
223 %sextIn2.1 = sext i16 %In2.1 to i32
224 %sextIn1.1 = sext i16 %In1.1 to i32
225 %sextIn2.2 = sext i16 %In2.2 to i32
226 %sextIn1.2 = sext i16 %In1.2 to i32
227 %sextIn2.3 = sext i16 %In2.3 to i32
228 %sextIn1.3 = sext i16 %In1.3 to i32
229 %mul = mul nsw i32 %sextIn2, %sextIn1
230 %add = add nsw i32 %mul, %sum.010
231 %mul.1 = mul nsw i32 %sextIn2.1, %sextIn1.1
232 %add.1 = add nsw i32 %mul.1, %add
233 %mul.2 = mul nsw i32 %sextIn2.2, %sextIn1.2
234 %add.2 = add nsw i32 %mul.2, %add.1
235 %mul.3 = mul nsw i32 %sextIn2.3, %sextIn1.3
236 %add.3 = add nsw i32 %mul.3, %add.2
237 %inc.3 = add i32 %i.011, 4
238 %pin1_add4 = getelementptr i16, i16* %pin1, i32 4
239 %pin2_sub4 = getelementptr i16, i16* %pin2, i32 -4
240 %niter.ncmp.3 = icmp eq i32 %unroll_iter, %inc.3
241 br i1 %niter.ncmp.3, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body