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
5 define i64 @smlaldx(ptr nocapture readonly %pIn1, ptr nocapture readonly %pIn2, i32 %j, i32 %limit) {
8 ; CHECK: = phi i32 [ 0, %for.body.preheader.new ],
9 ; CHECK: [[ACC0:%[^ ]+]] = phi i64 [ 0, %for.body.preheader.new ], [ [[ACC2:%[^ ]+]], %for.body ]
10 ; CHECK: [[IN21:%[^ ]+]] = load i32, ptr %pIn2.1, align 2
11 ; CHECK: [[IN10:%[^ ]+]] = load i32, ptr %pIn1.0, align 2
12 ; CHECK: [[ACC1:%[^ ]+]] = call i64 @llvm.arm.smlaldx(i32 [[IN21]], i32 [[IN10]], i64 [[ACC0]])
13 ; CHECK: [[IN23:%[^ ]+]] = load i32, ptr %pIn2.3, align 2
14 ; CHECK: [[IN12:%[^ ]+]] = load i32, ptr %pIn1.2, align 2
15 ; CHECK: [[ACC2]] = call i64 @llvm.arm.smlaldx(i32 [[IN23]], i32 [[IN12]], i64 [[ACC1]])
16 ; CHECK-NOT: call i64 @llvm.arm.smlad
17 ; CHECK-UNSUPPORTED-NOT: call i64 @llvm.arm.smlad
20 %cmp9 = icmp eq i32 %limit, 0
21 br i1 %cmp9, label %for.cond.cleanup, label %for.body.preheader
24 %0 = add i32 %limit, -1
25 %xtraiter = and i32 %limit, 3
26 %1 = icmp ult i32 %0, 3
27 br i1 %1, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body.preheader.new
29 for.body.preheader.new:
30 %unroll_iter = sub i32 %limit, %xtraiter
33 for.cond.cleanup.loopexit.unr-lcssa:
34 %add.lcssa.ph = phi i64 [ undef, %for.body.preheader ], [ %add.3, %for.body ]
35 %i.011.unr = phi i32 [ 0, %for.body.preheader ], [ %inc.3, %for.body ]
36 %sum.010.unr = phi i64 [ 0, %for.body.preheader ], [ %add.3, %for.body ]
37 %lcmp.mod = icmp eq i32 %xtraiter, 0
38 br i1 %lcmp.mod, label %for.cond.cleanup, label %for.body.epil
41 %i.011.epil = phi i32 [ %inc.epil, %for.body.epil ], [ %i.011.unr, %for.cond.cleanup.loopexit.unr-lcssa ]
42 %sum.010.epil = phi i64 [ %add.epil, %for.body.epil ], [ %sum.010.unr, %for.cond.cleanup.loopexit.unr-lcssa ]
43 %epil.iter = phi i32 [ %epil.iter.sub, %for.body.epil ], [ %xtraiter, %for.cond.cleanup.loopexit.unr-lcssa ]
44 %sub.epil = sub i32 %j, %i.011.epil
45 %arrayidx.epil = getelementptr inbounds i16, ptr %pIn2, i32 %sub.epil
46 %2 = load i16, ptr %arrayidx.epil, align 2
47 %conv.epil = sext i16 %2 to i32
48 %arrayidx1.epil = getelementptr inbounds i16, ptr %pIn1, i32 %i.011.epil
49 %3 = load i16, ptr %arrayidx1.epil, align 2
50 %conv2.epil = sext i16 %3 to i32
51 %mul.epil = mul nsw i32 %conv2.epil, %conv.epil
52 %sext.mul.epil = sext i32 %mul.epil to i64
53 %add.epil = add nsw i64 %sext.mul.epil, %sum.010.epil
54 %inc.epil = add nuw i32 %i.011.epil, 1
55 %epil.iter.sub = add i32 %epil.iter, -1
56 %epil.iter.cmp = icmp eq i32 %epil.iter.sub, 0
57 br i1 %epil.iter.cmp, label %for.cond.cleanup, label %for.body.epil
60 %sum.0.lcssa = phi i64 [ 0, %entry ], [ %add.lcssa.ph, %for.cond.cleanup.loopexit.unr-lcssa ], [ %add.epil, %for.body.epil ]
64 %i.011 = phi i32 [ 0, %for.body.preheader.new ], [ %inc.3, %for.body ]
65 %sum.010 = phi i64 [ 0, %for.body.preheader.new ], [ %add.3, %for.body ]
66 %niter = phi i32 [ %unroll_iter, %for.body.preheader.new ], [ %niter.nsub.3, %for.body ]
67 %pIn2Base = phi ptr [ %pIn2, %for.body.preheader.new ], [ %pIn2.4, %for.body ]
68 %In2 = load i16, ptr %pIn2Base, align 2
69 %pIn1.0 = getelementptr inbounds i16, ptr %pIn1, i32 %i.011
70 %In1 = load i16, ptr %pIn1.0, align 2
71 %inc = or disjoint i32 %i.011, 1
72 %pIn2.1 = getelementptr inbounds i16, ptr %pIn2Base, i32 -1
73 %In2.1 = load i16, ptr %pIn2.1, align 2
74 %pIn1.1 = getelementptr inbounds i16, ptr %pIn1, i32 %inc
75 %In1.1 = load i16, ptr %pIn1.1, align 2
76 %inc.1 = or disjoint i32 %i.011, 2
77 %pIn2.2 = getelementptr inbounds i16, ptr %pIn2Base, i32 -2
78 %In2.2 = load i16, ptr %pIn2.2, align 2
79 %pIn1.2 = getelementptr inbounds i16, ptr %pIn1, i32 %inc.1
80 %In1.2 = load i16, ptr %pIn1.2, align 2
81 %inc.2 = or disjoint i32 %i.011, 3
82 %pIn2.3 = getelementptr inbounds i16, ptr %pIn2Base, i32 -3
83 %In2.3 = load i16, ptr %pIn2.3, align 2
84 %pIn1.3 = getelementptr inbounds i16, ptr %pIn1, i32 %inc.2
85 %In1.3 = load i16, ptr %pIn1.3, align 2
86 %sextIn1 = sext i16 %In1 to i32
87 %sextIn1.1 = sext i16 %In1.1 to i32
88 %sextIn1.2 = sext i16 %In1.2 to i32
89 %sextIn1.3 = sext i16 %In1.3 to i32
90 %sextIn2 = sext i16 %In2 to i32
91 %sextIn2.1 = sext i16 %In2.1 to i32
92 %sextIn2.2 = sext i16 %In2.2 to i32
93 %sextIn2.3 = sext i16 %In2.3 to i32
94 %mul = mul nsw i32 %sextIn1, %sextIn2
95 %mul.1 = mul nsw i32 %sextIn1.1, %sextIn2.1
96 %mul.2 = mul nsw i32 %sextIn1.2, %sextIn2.2
97 %mul.3 = mul nsw i32 %sextIn1.3, %sextIn2.3
98 %sext.mul = sext i32 %mul to i64
99 %sext.mul.1 = sext i32 %mul.1 to i64
100 %sext.mul.2 = sext i32 %mul.2 to i64
101 %sext.mul.3 = sext i32 %mul.3 to i64
102 %add = add nsw i64 %sum.010, %sext.mul
103 %add.1 = add nsw i64 %sext.mul.1, %add
104 %add.2 = add nsw i64 %add.1, %sext.mul.2
105 %add.3 = add nsw i64 %sext.mul.3, %add.2
106 %inc.3 = add i32 %i.011, 4
107 %pIn2.4 = getelementptr inbounds i16, ptr %pIn2Base, i32 -4
108 %niter.nsub.3 = add i32 %niter, -4
109 %niter.ncmp.3 = icmp eq i32 %niter.nsub.3, 0
110 br i1 %niter.ncmp.3, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body
113 define i64 @smlaldx_swap(ptr nocapture readonly %pIn1, ptr nocapture readonly %pIn2, i32 %j, i32 %limit) {
116 %cmp9 = icmp eq i32 %limit, 0
117 br i1 %cmp9, label %for.cond.cleanup, label %for.body.preheader
120 %0 = add i32 %limit, -1
121 %xtraiter = and i32 %limit, 3
122 %1 = icmp ult i32 %0, 3
123 br i1 %1, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body.preheader.new
125 for.body.preheader.new:
126 %unroll_iter = sub i32 %limit, %xtraiter
127 %scevgep6 = getelementptr i16, ptr %pIn1, i32 2
129 %scevgep11 = getelementptr i16, ptr %pIn2, i32 %2
132 for.cond.cleanup.loopexit.unr-lcssa:
133 %add.lcssa.ph = phi i64 [ undef, %for.body.preheader ], [ %add.3, %for.body ]
134 %i.011.unr = phi i32 [ 0, %for.body.preheader ], [ %inc.3, %for.body ]
135 %sum.010.unr = phi i64 [ 0, %for.body.preheader ], [ %add.3, %for.body ]
136 %lcmp.mod = icmp eq i32 %xtraiter, 0
137 br i1 %lcmp.mod, label %for.cond.cleanup, label %for.body.epil.preheader
139 for.body.epil.preheader:
140 %scevgep = getelementptr i16, ptr %pIn1, i32 %i.011.unr
141 %3 = sub i32 %j, %i.011.unr
142 %scevgep2 = getelementptr i16, ptr %pIn2, i32 %3
143 %4 = sub i32 0, %xtraiter
144 br label %for.body.epil
147 %lsr.iv5 = phi i32 [ %4, %for.body.epil.preheader ], [ %lsr.iv.next, %for.body.epil ]
148 %lsr.iv3 = phi ptr [ %scevgep2, %for.body.epil.preheader ], [ %scevgep4, %for.body.epil ]
149 %lsr.iv = phi ptr [ %scevgep, %for.body.epil.preheader ], [ %scevgep1, %for.body.epil ]
150 %sum.010.epil = phi i64 [ %add.epil, %for.body.epil ], [ %sum.010.unr, %for.body.epil.preheader ]
151 %5 = load i16, ptr %lsr.iv3, align 2
152 %conv.epil = sext i16 %5 to i32
153 %6 = load i16, ptr %lsr.iv, align 2
154 %conv2.epil = sext i16 %6 to i32
155 %mul.epil = mul nsw i32 %conv2.epil, %conv.epil
156 %sext.mul.epil = sext i32 %mul.epil to i64
157 %add.epil = add nsw i64 %sext.mul.epil, %sum.010.epil
158 %scevgep1 = getelementptr i16, ptr %lsr.iv, i32 1
159 %scevgep4 = getelementptr i16, ptr %lsr.iv3, i32 -1
160 %lsr.iv.next = add nsw i32 %lsr.iv5, 1
161 %epil.iter.cmp = icmp eq i32 %lsr.iv.next, 0
162 br i1 %epil.iter.cmp, label %for.cond.cleanup, label %for.body.epil
165 %sum.0.lcssa = phi i64 [ 0, %entry ], [ %add.lcssa.ph, %for.cond.cleanup.loopexit.unr-lcssa ], [ %add.epil, %for.body.epil ]
168 ; CHECK-LABEL: smlaldx_swap
169 ; CHECK: for.body.preheader.new:
170 ; CHECK: [[PIN1Base:[^ ]+]] = getelementptr i16, ptr %pIn1
171 ; CHECK: [[PIN2Base:[^ ]+]] = getelementptr i16, ptr %pIn2
174 ; CHECK: [[PIN2:%[^ ]+]] = phi ptr [ [[PIN2_NEXT:%[^ ]+]], %for.body ], [ [[PIN2Base]], %for.body.preheader.new ]
175 ; CHECK: [[PIN1:%[^ ]+]] = phi ptr [ [[PIN1_NEXT:%[^ ]+]], %for.body ], [ [[PIN1Base]], %for.body.preheader.new ]
176 ; CHECK: [[IV:%[^ ]+]] = phi i32
177 ; CHECK: [[ACC0:%[^ ]+]] = phi i64 [ 0, %for.body.preheader.new ], [ [[ACC2:%[^ ]+]], %for.body ]
179 ; CHECK: [[IN2:%[^ ]+]] = load i32, ptr [[PIN2]], align 2
181 ; CHECK: [[PIN1_2:%[^ ]+]] = getelementptr i16, ptr [[PIN1]], i32 -2
182 ; CHECK: [[IN1_2:%[^ ]+]] = load i32, ptr [[PIN1_2]], align 2
183 ; CHECK: [[ACC1:%[^ ]+]] = call i64 @llvm.arm.smlaldx(i32 [[IN2]], i32 [[IN1_2]], i64 [[ACC0]])
185 ; CHECK: [[PIN2_2:%[^ ]+]] = getelementptr i16, ptr [[PIN2]], i32 -2
186 ; CHECK: [[IN2_2:%[^ ]+]] = load i32, ptr [[PIN2_2]], align 2
188 ; CHECK: [[IN1:%[^ ]+]] = load i32, ptr [[PIN1]], align 2
189 ; CHECK: [[ACC2]] = call i64 @llvm.arm.smlaldx(i32 [[IN2_2]], i32 [[IN1]], i64 [[ACC1]])
191 ; CHECK: [[PIN1_NEXT]] = getelementptr i16, ptr [[PIN1]], i32 4
192 ; CHECK: [[PIN2_NEXT]] = getelementptr i16, ptr [[PIN2]], i32 -4
194 ; CHECK-NOT: call i64 @llvm.arm.smlad
195 ; CHECK-UNSUPPORTED-NOT: call i64 @llvm.arm.smlad
198 %pin2 = phi ptr [ %pin2.sub4, %for.body ], [ %scevgep11, %for.body.preheader.new ]
199 %pin1 = phi ptr [ %pin1.add4, %for.body ], [ %scevgep6, %for.body.preheader.new ]
200 %i.011 = phi i32 [ 0, %for.body.preheader.new ], [ %inc.3, %for.body ]
201 %sum.010 = phi i64 [ 0, %for.body.preheader.new ], [ %add.3, %for.body ]
202 %pin2.add1 = getelementptr i16, ptr %pin2, i32 1
203 %In2 = load i16, ptr %pin2.add1, align 2
204 %pin1.sub2 = getelementptr i16, ptr %pin1, i32 -2
205 %In1 = load i16, ptr %pin1.sub2, align 2
206 %In2.1 = load i16, ptr %pin2, align 2
207 %pin1.sub1 = getelementptr i16, ptr %pin1, i32 -1
208 %In1.1 = load i16, ptr %pin1.sub1, align 2
209 %pin2.sub1 = getelementptr i16, ptr %pin2, i32 -1
210 %In2.2 = load i16, ptr %pin2.sub1, align 2
211 %In1.2 = load i16, ptr %pin1, align 2
212 %pin2.sub2 = getelementptr i16, ptr %pin2, i32 -2
213 %In2.3 = load i16, ptr %pin2.sub2, align 2
214 %pin1.add1 = getelementptr i16, ptr %pin1, i32 1
215 %In1.3 = load i16, ptr %pin1.add1, align 2
216 %sextIn2 = sext i16 %In2 to i32
217 %sextIn1 = sext i16 %In1 to i32
218 %sextIn2.1 = sext i16 %In2.1 to i32
219 %sextIn1.1 = sext i16 %In1.1 to i32
220 %sextIn2.2 = sext i16 %In2.2 to i32
221 %sextIn1.2 = sext i16 %In1.2 to i32
222 %sextIn2.3 = sext i16 %In2.3 to i32
223 %sextIn1.3 = sext i16 %In1.3 to i32
224 %mul = mul nsw i32 %sextIn2, %sextIn1
225 %sext.mul = sext i32 %mul to i64
226 %add = add nsw i64 %sext.mul, %sum.010
227 %mul.1 = mul nsw i32 %sextIn2.1, %sextIn1.1
228 %sext.mul.1 = sext i32 %mul.1 to i64
229 %add.1 = add nsw i64 %sext.mul.1, %add
230 %mul.2 = mul nsw i32 %sextIn2.2, %sextIn1.2
231 %sext.mul.2 = sext i32 %mul.2 to i64
232 %add.2 = add nsw i64 %add.1, %sext.mul.2
233 %mul.3 = mul nsw i32 %sextIn2.3, %sextIn1.3
234 %sext.mul.3 = sext i32 %mul.3 to i64
235 %add.3 = add nsw i64 %add.2, %sext.mul.3
236 %inc.3 = add i32 %i.011, 4
237 %pin1.add4 = getelementptr i16, ptr %pin1, i32 4
238 %pin2.sub4 = getelementptr i16, ptr %pin2, i32 -4
239 %niter.ncmp.3 = icmp eq i32 %unroll_iter, %inc.3
240 br i1 %niter.ncmp.3, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body