1 ; RUN: opt -mtriple=armv8m.main-none-none-eabi -mattr=+dsp -arm-parallel-dsp %s -S -o - | FileCheck %s
2 ; RUN: opt -mtriple=armv6m-none-none-eabi < %s -arm-parallel-dsp -S | FileCheck %s --check-prefix=CHECK-UNSUPPORTED
3 ; RUN: opt -mtriple=armv8m.main-none-none-eabi -mattr=-dsp < %s -arm-parallel-dsp -S | FileCheck %s --check-prefix=CHECK-UNSUPPORTED
4 ; RUN: opt -mtriple=armv8m.maineb-none-none-eabi -mattr=+dsp < %s -arm-parallel-dsp -S | FileCheck %s --check-prefix=CHECK-UNSUPPORTED
6 define i32 @smladx(ptr nocapture readonly %pIn1, ptr 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: [[IN21:%[^ ]+]] = load i32, ptr %pIn2.1, align 2
12 ; CHECK: [[IN10:%[^ ]+]] = load i32, ptr %pIn1.0, align 2
13 ; CHECK: [[ACC1:%[^ ]+]] = call i32 @llvm.arm.smladx(i32 [[IN21]], i32 [[IN10]], i32 [[ACC0]])
15 ; CHECK: [[IN23:%[^ ]+]] = load i32, ptr %pIn2.3, align 2
16 ; CHECK: [[IN12:%[^ ]+]] = load i32, ptr %pIn1.2, align 2
17 ; CHECK: [[ACC2]] = call i32 @llvm.arm.smladx(i32 [[IN23]], i32 [[IN12]], i32 [[ACC1]])
18 ; CHECK-NOT: call i32 @llvm.arm.smlad
19 ; CHECK-UNSUPPORTED-NOT: call i32 @llvm.arm.smlad
22 %cmp9 = icmp eq i32 %limit, 0
23 br i1 %cmp9, label %for.cond.cleanup, label %for.body.preheader
26 %0 = add i32 %limit, -1
27 %xtraiter = and i32 %limit, 3
28 %1 = icmp ult i32 %0, 3
29 br i1 %1, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body.preheader.new
31 for.body.preheader.new:
32 %unroll_iter = sub i32 %limit, %xtraiter
35 for.cond.cleanup.loopexit.unr-lcssa:
36 %add.lcssa.ph = phi i32 [ undef, %for.body.preheader ], [ %add.3, %for.body ]
37 %i.011.unr = phi i32 [ 0, %for.body.preheader ], [ %inc.3, %for.body ]
38 %sum.010.unr = phi i32 [ 0, %for.body.preheader ], [ %add.3, %for.body ]
39 %lcmp.mod = icmp eq i32 %xtraiter, 0
40 br i1 %lcmp.mod, label %for.cond.cleanup, label %for.body.epil
43 %i.011.epil = phi i32 [ %inc.epil, %for.body.epil ], [ %i.011.unr, %for.cond.cleanup.loopexit.unr-lcssa ]
44 %sum.010.epil = phi i32 [ %add.epil, %for.body.epil ], [ %sum.010.unr, %for.cond.cleanup.loopexit.unr-lcssa ]
45 %epil.iter = phi i32 [ %epil.iter.sub, %for.body.epil ], [ %xtraiter, %for.cond.cleanup.loopexit.unr-lcssa ]
46 %sub.epil = sub i32 %j, %i.011.epil
47 %arrayidx.epil = getelementptr inbounds i16, ptr %pIn2, i32 %sub.epil
48 %2 = load i16, ptr %arrayidx.epil, align 2
49 %conv.epil = sext i16 %2 to i32
50 %arrayidx1.epil = getelementptr inbounds i16, ptr %pIn1, i32 %i.011.epil
51 %3 = load i16, ptr %arrayidx1.epil, align 2
52 %conv2.epil = sext i16 %3 to i32
53 %mul.epil = mul nsw i32 %conv2.epil, %conv.epil
54 %add.epil = add nsw i32 %mul.epil, %sum.010.epil
55 %inc.epil = add nuw i32 %i.011.epil, 1
56 %epil.iter.sub = add i32 %epil.iter, -1
57 %epil.iter.cmp = icmp eq i32 %epil.iter.sub, 0
58 br i1 %epil.iter.cmp, label %for.cond.cleanup, label %for.body.epil
61 %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add.lcssa.ph, %for.cond.cleanup.loopexit.unr-lcssa ], [ %add.epil, %for.body.epil ]
65 %i.011 = phi i32 [ 0, %for.body.preheader.new ], [ %inc.3, %for.body ]
66 %sum.010 = phi i32 [ 0, %for.body.preheader.new ], [ %add.3, %for.body ]
67 %niter = phi i32 [ %unroll_iter, %for.body.preheader.new ], [ %niter.nsub.3, %for.body ]
68 %pIn2Base = phi ptr [ %pIn2, %for.body.preheader.new ], [ %pIn2.4, %for.body ]
69 %In2 = load i16, ptr %pIn2Base, align 2
70 %pIn1.0 = getelementptr inbounds i16, ptr %pIn1, i32 %i.011
71 %In1 = load i16, ptr %pIn1.0, align 2
72 %inc = or i32 %i.011, 1
73 %pIn2.1 = getelementptr inbounds i16, ptr %pIn2Base, i32 -1
74 %In2.1 = load i16, ptr %pIn2.1, align 2
75 %pIn1.1 = getelementptr inbounds i16, ptr %pIn1, i32 %inc
76 %In1.1 = load i16, ptr %pIn1.1, align 2
77 %inc.1 = or i32 %i.011, 2
78 %pIn2.2 = getelementptr inbounds i16, ptr %pIn2Base, i32 -2
79 %In2.2 = load i16, ptr %pIn2.2, align 2
80 %pIn1.2 = getelementptr inbounds i16, ptr %pIn1, i32 %inc.1
81 %In1.2 = load i16, ptr %pIn1.2, align 2
82 %inc.2 = or i32 %i.011, 3
83 %pIn2.3 = getelementptr inbounds i16, ptr %pIn2Base, i32 -3
84 %In2.3 = load i16, ptr %pIn2.3, align 2
85 %pIn1.3 = getelementptr inbounds i16, ptr %pIn1, i32 %inc.2
86 %In1.3 = load i16, ptr %pIn1.3, align 2
87 %sextIn1 = sext i16 %In1 to i32
88 %sextIn1.1 = sext i16 %In1.1 to i32
89 %sextIn1.2 = sext i16 %In1.2 to i32
90 %sextIn1.3 = sext i16 %In1.3 to i32
91 %sextIn2 = sext i16 %In2 to i32
92 %sextIn2.1 = sext i16 %In2.1 to i32
93 %sextIn2.2 = sext i16 %In2.2 to i32
94 %sextIn2.3 = sext i16 %In2.3 to i32
95 %mul = mul nsw i32 %sextIn1, %sextIn2
96 %mul.1 = mul nsw i32 %sextIn1.1, %sextIn2.1
97 %mul.2 = mul nsw i32 %sextIn1.2, %sextIn2.2
98 %mul.3 = mul nsw i32 %sextIn1.3, %sextIn2.3
99 %add = add nsw i32 %mul, %sum.010
100 %add.1 = add nsw i32 %mul.1, %add
101 %add.2 = add nsw i32 %mul.2, %add.1
102 %add.3 = add nsw i32 %mul.3, %add.2
103 %inc.3 = add i32 %i.011, 4
104 %pIn2.4 = getelementptr inbounds i16, ptr %pIn2Base, i32 -4
105 %niter.nsub.3 = add i32 %niter, -4
106 %niter.ncmp.3 = icmp eq i32 %niter.nsub.3, 0
107 br i1 %niter.ncmp.3, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body
110 define i32 @smladx_swap(ptr nocapture readonly %pIn1, ptr nocapture readonly %pIn2, i32 %j, i32 %limit) {
112 ; CHECK-LABEL: smladx_swap
113 ; CHECK: for.body.preheader.new:
114 ; CHECK: [[PIN1Base:[^ ]+]] = getelementptr i16, ptr %pIn1
115 ; CHECK: [[PIN2Base:[^ ]+]] = getelementptr i16, ptr %pIn2
118 ; CHECK: [[PIN2:%[^ ]+]] = phi ptr [ [[PIN2_NEXT:%[^ ]+]], %for.body ], [ [[PIN2Base]], %for.body.preheader.new ]
119 ; CHECK: [[PIN1:%[^ ]+]] = phi ptr [ [[PIN1_NEXT:%[^ ]+]], %for.body ], [ [[PIN1Base]], %for.body.preheader.new ]
120 ; CHECK: [[IV:%[^ ]+]] = phi i32
121 ; CHECK: [[ACC0:%[^ ]+]] = phi i32 [ 0, %for.body.preheader.new ], [ [[ACC2:%[^ ]+]], %for.body ]
123 ; CHECK: [[IN2:%[^ ]+]] = load i32, ptr [[PIN2]], align 2
125 ; CHECK: [[PIN1_2:%[^ ]+]] = getelementptr i16, ptr [[PIN1]], i32 -2
126 ; CHECK: [[IN1_2:%[^ ]+]] = load i32, ptr [[PIN1_2]], align 2
127 ; CHECK: [[ACC1:%[^ ]+]] = call i32 @llvm.arm.smladx(i32 [[IN2]], i32 [[IN1_2]], i32 [[ACC0]])
129 ; CHECK: [[PIN2_2:%[^ ]+]] = getelementptr i16, ptr [[PIN2]], i32 -2
130 ; CHECK: [[IN2_2:%[^ ]+]] = load i32, ptr [[PIN2_2]], align 2
132 ; CHECK: [[IN1:%[^ ]+]] = load i32, ptr [[PIN1]], align 2
134 ; CHECK: [[ACC2]] = call i32 @llvm.arm.smladx(i32 [[IN2_2]], i32 [[IN1]], i32 [[ACC1]])
136 ; CHECK: [[PIN1_NEXT]] = getelementptr i16, ptr [[PIN1]], i32 4
137 ; CHECK: [[PIN2_NEXT]] = getelementptr i16, ptr [[PIN2]], i32 -4
139 ; CHECK-NOT: call i32 @llvm.arm.smlad
140 ; CHECK-UNSUPPORTED-NOT: call i32 @llvm.arm.smlad
143 %cmp9 = icmp eq i32 %limit, 0
144 br i1 %cmp9, label %for.cond.cleanup, label %for.body.preheader
147 %0 = add i32 %limit, -1
148 %xtraiter = and i32 %limit, 3
149 %1 = icmp ult i32 %0, 3
150 br i1 %1, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body.preheader.new
152 for.body.preheader.new:
153 %unroll_iter = sub i32 %limit, %xtraiter
154 %scevgep6 = getelementptr i16, ptr %pIn1, i32 2
156 %scevgep11 = getelementptr i16, ptr %pIn2, i32 %2
159 for.cond.cleanup.loopexit.unr-lcssa:
160 %add.lcssa.ph = phi i32 [ undef, %for.body.preheader ], [ %add.3, %for.body ]
161 %i.011.unr = phi i32 [ 0, %for.body.preheader ], [ %inc.3, %for.body ]
162 %sum.010.unr = phi i32 [ 0, %for.body.preheader ], [ %add.3, %for.body ]
163 %lcmp.mod = icmp eq i32 %xtraiter, 0
164 br i1 %lcmp.mod, label %for.cond.cleanup, label %for.body.epil.preheader
166 for.body.epil.preheader:
167 %scevgep = getelementptr i16, ptr %pIn1, i32 %i.011.unr
168 %3 = sub i32 %j, %i.011.unr
169 %scevgep2 = getelementptr i16, ptr %pIn2, i32 %3
170 %4 = sub i32 0, %xtraiter
171 br label %for.body.epil
174 %lsr.iv5 = phi i32 [ %4, %for.body.epil.preheader ], [ %lsr.iv.next, %for.body.epil ]
175 %lsr.iv3 = phi ptr [ %scevgep2, %for.body.epil.preheader ], [ %scevgep4, %for.body.epil ]
176 %lsr.iv = phi ptr [ %scevgep, %for.body.epil.preheader ], [ %scevgep1, %for.body.epil ]
177 %sum.010.epil = phi i32 [ %add.epil, %for.body.epil ], [ %sum.010.unr, %for.body.epil.preheader ]
178 %5 = load i16, ptr %lsr.iv3, align 2
179 %conv.epil = sext i16 %5 to i32
180 %6 = load i16, ptr %lsr.iv, align 2
181 %conv2.epil = sext i16 %6 to i32
182 %mul.epil = mul nsw i32 %conv2.epil, %conv.epil
183 %add.epil = add nsw i32 %mul.epil, %sum.010.epil
184 %scevgep1 = getelementptr i16, ptr %lsr.iv, i32 1
185 %scevgep4 = getelementptr i16, ptr %lsr.iv3, i32 -1
186 %lsr.iv.next = add nsw i32 %lsr.iv5, 1
187 %epil.iter.cmp = icmp eq i32 %lsr.iv.next, 0
188 br i1 %epil.iter.cmp, label %for.cond.cleanup, label %for.body.epil
191 %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add.lcssa.ph, %for.cond.cleanup.loopexit.unr-lcssa ], [ %add.epil, %for.body.epil ]
195 %pin2 = phi ptr [ %pin2_sub4, %for.body ], [ %scevgep11, %for.body.preheader.new ]
196 %pin1 = phi ptr [ %pin1_add4, %for.body ], [ %scevgep6, %for.body.preheader.new ]
197 %i.011 = phi i32 [ 0, %for.body.preheader.new ], [ %inc.3, %for.body ]
198 %sum.010 = phi i32 [ 0, %for.body.preheader.new ], [ %add.3, %for.body ]
199 %pin2_add1 = getelementptr i16, ptr %pin2, i32 1
200 %In2 = load i16, ptr %pin2_add1, align 2
201 %pin1_sub2 = getelementptr i16, ptr %pin1, i32 -2
202 %In1 = load i16, ptr %pin1_sub2, align 2
203 %In2.1 = load i16, ptr %pin2, align 2
204 %pin1_sub1 = getelementptr i16, ptr %pin1, i32 -1
205 %In1.1 = load i16, ptr %pin1_sub1, align 2
206 %pin2_sub1 = getelementptr i16, ptr %pin2, i32 -1
207 %In2.2 = load i16, ptr %pin2_sub1, align 2
208 %In1.2 = load i16, ptr %pin1, align 2
209 %pin2_sub2 = getelementptr i16, ptr %pin2, i32 -2
210 %In2.3 = load i16, ptr %pin2_sub2, align 2
211 %pin1_add1 = getelementptr i16, ptr %pin1, i32 1
212 %In1.3 = load i16, ptr %pin1_add1, align 2
213 %sextIn2 = sext i16 %In2 to i32
214 %sextIn1 = sext i16 %In1 to i32
215 %sextIn2.1 = sext i16 %In2.1 to i32
216 %sextIn1.1 = sext i16 %In1.1 to i32
217 %sextIn2.2 = sext i16 %In2.2 to i32
218 %sextIn1.2 = sext i16 %In1.2 to i32
219 %sextIn2.3 = sext i16 %In2.3 to i32
220 %sextIn1.3 = sext i16 %In1.3 to i32
221 %mul = mul nsw i32 %sextIn2, %sextIn1
222 %add = add nsw i32 %mul, %sum.010
223 %mul.1 = mul nsw i32 %sextIn2.1, %sextIn1.1
224 %add.1 = add nsw i32 %mul.1, %add
225 %mul.2 = mul nsw i32 %sextIn2.2, %sextIn1.2
226 %add.2 = add nsw i32 %mul.2, %add.1
227 %mul.3 = mul nsw i32 %sextIn2.3, %sextIn1.3
228 %add.3 = add nsw i32 %mul.3, %add.2
229 %inc.3 = add i32 %i.011, 4
230 %pin1_add4 = getelementptr i16, ptr %pin1, i32 4
231 %pin2_sub4 = getelementptr i16, ptr %pin2, i32 -4
232 %niter.ncmp.3 = icmp eq i32 %unroll_iter, %inc.3
233 br i1 %niter.ncmp.3, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body