1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-unknown-unknown | FileCheck %s --check-prefix=X86-NOBMI
3 ; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+bmi2 | FileCheck %s --check-prefix=X86-BMI
4 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefix=X64-NOBMI
5 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+bmi2 | FileCheck %s --check-prefix=X64-BMI
9 define i64 @foo(i64 %x, i64 %y) nounwind {
10 ; X86-NOBMI-LABEL: foo:
12 ; X86-NOBMI-NEXT: pushl %ebp
13 ; X86-NOBMI-NEXT: pushl %ebx
14 ; X86-NOBMI-NEXT: pushl %edi
15 ; X86-NOBMI-NEXT: pushl %esi
16 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %ecx
17 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %ebp
18 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %ebx
19 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi
20 ; X86-NOBMI-NEXT: movl %ecx, %eax
21 ; X86-NOBMI-NEXT: mull %ebx
22 ; X86-NOBMI-NEXT: movl %edx, %edi
23 ; X86-NOBMI-NEXT: movl %ebp, %eax
24 ; X86-NOBMI-NEXT: mull %ebx
25 ; X86-NOBMI-NEXT: movl %edx, %ebx
26 ; X86-NOBMI-NEXT: movl %eax, %ebp
27 ; X86-NOBMI-NEXT: addl %edi, %ebp
28 ; X86-NOBMI-NEXT: adcl $0, %ebx
29 ; X86-NOBMI-NEXT: movl %ecx, %eax
30 ; X86-NOBMI-NEXT: mull %esi
31 ; X86-NOBMI-NEXT: movl %edx, %ecx
32 ; X86-NOBMI-NEXT: addl %ebp, %eax
33 ; X86-NOBMI-NEXT: adcl %ebx, %ecx
34 ; X86-NOBMI-NEXT: setb %al
35 ; X86-NOBMI-NEXT: movzbl %al, %edi
36 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
37 ; X86-NOBMI-NEXT: mull %esi
38 ; X86-NOBMI-NEXT: addl %ecx, %eax
39 ; X86-NOBMI-NEXT: adcl %edi, %edx
40 ; X86-NOBMI-NEXT: popl %esi
41 ; X86-NOBMI-NEXT: popl %edi
42 ; X86-NOBMI-NEXT: popl %ebx
43 ; X86-NOBMI-NEXT: popl %ebp
44 ; X86-NOBMI-NEXT: retl
48 ; X86-BMI-NEXT: pushl %ebp
49 ; X86-BMI-NEXT: pushl %ebx
50 ; X86-BMI-NEXT: pushl %edi
51 ; X86-BMI-NEXT: pushl %esi
52 ; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %eax
53 ; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %ecx
54 ; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %esi
55 ; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %edi
56 ; X86-BMI-NEXT: movl %eax, %edx
57 ; X86-BMI-NEXT: mulxl %esi, %ebx, %ebx
58 ; X86-BMI-NEXT: movl %ecx, %edx
59 ; X86-BMI-NEXT: mulxl %esi, %esi, %ebp
60 ; X86-BMI-NEXT: addl %ebx, %esi
61 ; X86-BMI-NEXT: adcl $0, %ebp
62 ; X86-BMI-NEXT: movl %eax, %edx
63 ; X86-BMI-NEXT: mulxl %edi, %eax, %ebx
64 ; X86-BMI-NEXT: addl %esi, %eax
65 ; X86-BMI-NEXT: adcl %ebp, %ebx
66 ; X86-BMI-NEXT: setb %al
67 ; X86-BMI-NEXT: movzbl %al, %esi
68 ; X86-BMI-NEXT: movl %ecx, %edx
69 ; X86-BMI-NEXT: mulxl %edi, %eax, %edx
70 ; X86-BMI-NEXT: addl %ebx, %eax
71 ; X86-BMI-NEXT: adcl %esi, %edx
72 ; X86-BMI-NEXT: popl %esi
73 ; X86-BMI-NEXT: popl %edi
74 ; X86-BMI-NEXT: popl %ebx
75 ; X86-BMI-NEXT: popl %ebp
78 ; X64-NOBMI-LABEL: foo:
80 ; X64-NOBMI-NEXT: movq %rdi, %rax
81 ; X64-NOBMI-NEXT: mulq %rsi
82 ; X64-NOBMI-NEXT: movq %rdx, %rax
83 ; X64-NOBMI-NEXT: retq
87 ; X64-BMI-NEXT: movq %rdi, %rdx
88 ; X64-BMI-NEXT: mulxq %rsi, %rax, %rax
90 %tmp0 = zext i64 %x to i128
91 %tmp1 = zext i64 %y to i128
92 %tmp2 = mul i128 %tmp0, %tmp1
93 %tmp7 = zext i32 64 to i128
94 %tmp3 = lshr i128 %tmp2, %tmp7
95 %tmp4 = trunc i128 %tmp3 to i64
99 ; <rdar://problem/14096009> superfluous multiply by high part of
100 ; zero-extended value.
102 define i64 @mul1(i64 %n, i64* nocapture %z, i64* nocapture %x, i64 %y) nounwind {
103 ; X86-NOBMI-LABEL: mul1:
104 ; X86-NOBMI: # %bb.0: # %entry
105 ; X86-NOBMI-NEXT: pushl %ebp
106 ; X86-NOBMI-NEXT: pushl %ebx
107 ; X86-NOBMI-NEXT: pushl %edi
108 ; X86-NOBMI-NEXT: pushl %esi
109 ; X86-NOBMI-NEXT: subl $24, %esp
110 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %ecx
111 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
112 ; X86-NOBMI-NEXT: orl %ecx, %eax
113 ; X86-NOBMI-NEXT: je .LBB1_3
114 ; X86-NOBMI-NEXT: # %bb.1: # %for.body.preheader
115 ; X86-NOBMI-NEXT: xorl %eax, %eax
116 ; X86-NOBMI-NEXT: xorl %edx, %edx
117 ; X86-NOBMI-NEXT: xorl %ebp, %ebp
118 ; X86-NOBMI-NEXT: movl $0, (%esp) # 4-byte Folded Spill
119 ; X86-NOBMI-NEXT: .p2align 4, 0x90
120 ; X86-NOBMI-NEXT: .LBB1_2: # %for.body
121 ; X86-NOBMI-NEXT: # =>This Inner Loop Header: Depth=1
122 ; X86-NOBMI-NEXT: movl %edx, {{[-0-9]+}}(%e{{[sb]}}p) # 4-byte Spill
123 ; X86-NOBMI-NEXT: movl %eax, {{[-0-9]+}}(%e{{[sb]}}p) # 4-byte Spill
124 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
125 ; X86-NOBMI-NEXT: movl (%eax,%ebp,8), %esi
126 ; X86-NOBMI-NEXT: movl 4(%eax,%ebp,8), %ecx
127 ; X86-NOBMI-NEXT: movl %ecx, {{[-0-9]+}}(%e{{[sb]}}p) # 4-byte Spill
128 ; X86-NOBMI-NEXT: movl %esi, %eax
129 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi
130 ; X86-NOBMI-NEXT: mull %edi
131 ; X86-NOBMI-NEXT: movl %edx, {{[-0-9]+}}(%e{{[sb]}}p) # 4-byte Spill
132 ; X86-NOBMI-NEXT: movl %eax, {{[-0-9]+}}(%e{{[sb]}}p) # 4-byte Spill
133 ; X86-NOBMI-NEXT: movl %ecx, %eax
134 ; X86-NOBMI-NEXT: mull %edi
135 ; X86-NOBMI-NEXT: movl %edx, %ecx
136 ; X86-NOBMI-NEXT: movl %eax, %ebx
137 ; X86-NOBMI-NEXT: addl {{[-0-9]+}}(%e{{[sb]}}p), %ebx # 4-byte Folded Reload
138 ; X86-NOBMI-NEXT: adcl $0, %ecx
139 ; X86-NOBMI-NEXT: movl %esi, %eax
140 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx
141 ; X86-NOBMI-NEXT: mull %edx
142 ; X86-NOBMI-NEXT: movl %edx, %esi
143 ; X86-NOBMI-NEXT: movl %eax, %edi
144 ; X86-NOBMI-NEXT: addl %ebx, %edi
145 ; X86-NOBMI-NEXT: adcl %ecx, %esi
146 ; X86-NOBMI-NEXT: setb %bl
147 ; X86-NOBMI-NEXT: movl {{[-0-9]+}}(%e{{[sb]}}p), %eax # 4-byte Reload
148 ; X86-NOBMI-NEXT: mull {{[0-9]+}}(%esp)
149 ; X86-NOBMI-NEXT: addl %esi, %eax
150 ; X86-NOBMI-NEXT: movzbl %bl, %esi
151 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %ebx
152 ; X86-NOBMI-NEXT: adcl %esi, %edx
153 ; X86-NOBMI-NEXT: movl {{[-0-9]+}}(%e{{[sb]}}p), %ecx # 4-byte Reload
154 ; X86-NOBMI-NEXT: addl {{[-0-9]+}}(%e{{[sb]}}p), %ecx # 4-byte Folded Reload
155 ; X86-NOBMI-NEXT: adcl {{[-0-9]+}}(%e{{[sb]}}p), %edi # 4-byte Folded Reload
156 ; X86-NOBMI-NEXT: adcl $0, %eax
157 ; X86-NOBMI-NEXT: adcl $0, %edx
158 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi
159 ; X86-NOBMI-NEXT: movl %ecx, (%esi,%ebp,8)
160 ; X86-NOBMI-NEXT: movl %edi, 4(%esi,%ebp,8)
161 ; X86-NOBMI-NEXT: addl $1, %ebp
162 ; X86-NOBMI-NEXT: movl (%esp), %edi # 4-byte Reload
163 ; X86-NOBMI-NEXT: adcl $0, %edi
164 ; X86-NOBMI-NEXT: movl %ebp, %esi
165 ; X86-NOBMI-NEXT: xorl {{[0-9]+}}(%esp), %esi
166 ; X86-NOBMI-NEXT: movl %edi, (%esp) # 4-byte Spill
167 ; X86-NOBMI-NEXT: xorl %ebx, %edi
168 ; X86-NOBMI-NEXT: orl %esi, %edi
169 ; X86-NOBMI-NEXT: jne .LBB1_2
170 ; X86-NOBMI-NEXT: .LBB1_3: # %for.end
171 ; X86-NOBMI-NEXT: xorl %eax, %eax
172 ; X86-NOBMI-NEXT: xorl %edx, %edx
173 ; X86-NOBMI-NEXT: addl $24, %esp
174 ; X86-NOBMI-NEXT: popl %esi
175 ; X86-NOBMI-NEXT: popl %edi
176 ; X86-NOBMI-NEXT: popl %ebx
177 ; X86-NOBMI-NEXT: popl %ebp
178 ; X86-NOBMI-NEXT: retl
180 ; X86-BMI-LABEL: mul1:
181 ; X86-BMI: # %bb.0: # %entry
182 ; X86-BMI-NEXT: pushl %ebp
183 ; X86-BMI-NEXT: pushl %ebx
184 ; X86-BMI-NEXT: pushl %edi
185 ; X86-BMI-NEXT: pushl %esi
186 ; X86-BMI-NEXT: subl $16, %esp
187 ; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %ecx
188 ; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %eax
189 ; X86-BMI-NEXT: orl %ecx, %eax
190 ; X86-BMI-NEXT: je .LBB1_3
191 ; X86-BMI-NEXT: # %bb.1: # %for.body.preheader
192 ; X86-BMI-NEXT: xorl %ecx, %ecx
193 ; X86-BMI-NEXT: xorl %edx, %edx
194 ; X86-BMI-NEXT: xorl %ebx, %ebx
195 ; X86-BMI-NEXT: xorl %ebp, %ebp
196 ; X86-BMI-NEXT: .p2align 4, 0x90
197 ; X86-BMI-NEXT: .LBB1_2: # %for.body
198 ; X86-BMI-NEXT: # =>This Inner Loop Header: Depth=1
199 ; X86-BMI-NEXT: movl %edx, {{[-0-9]+}}(%e{{[sb]}}p) # 4-byte Spill
200 ; X86-BMI-NEXT: movl %ecx, {{[-0-9]+}}(%e{{[sb]}}p) # 4-byte Spill
201 ; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %ecx
202 ; X86-BMI-NEXT: movl (%ecx,%ebx,8), %eax
203 ; X86-BMI-NEXT: movl 4(%ecx,%ebx,8), %esi
204 ; X86-BMI-NEXT: movl %esi, (%esp) # 4-byte Spill
205 ; X86-BMI-NEXT: movl %eax, %edx
206 ; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %ecx
207 ; X86-BMI-NEXT: mulxl %ecx, %edx, %edi
208 ; X86-BMI-NEXT: movl %edx, {{[-0-9]+}}(%e{{[sb]}}p) # 4-byte Spill
209 ; X86-BMI-NEXT: movl %esi, %edx
210 ; X86-BMI-NEXT: mulxl %ecx, %esi, %ecx
211 ; X86-BMI-NEXT: addl %edi, %esi
212 ; X86-BMI-NEXT: adcl $0, %ecx
213 ; X86-BMI-NEXT: movl %eax, %edx
214 ; X86-BMI-NEXT: mulxl {{[0-9]+}}(%esp), %edi, %eax
215 ; X86-BMI-NEXT: addl %esi, %edi
216 ; X86-BMI-NEXT: adcl %ecx, %eax
217 ; X86-BMI-NEXT: movl (%esp), %edx # 4-byte Reload
218 ; X86-BMI-NEXT: mulxl {{[0-9]+}}(%esp), %ecx, %edx
219 ; X86-BMI-NEXT: setb (%esp) # 1-byte Folded Spill
220 ; X86-BMI-NEXT: addl %eax, %ecx
221 ; X86-BMI-NEXT: movzbl (%esp), %eax # 1-byte Folded Reload
222 ; X86-BMI-NEXT: adcl %eax, %edx
223 ; X86-BMI-NEXT: movl {{[-0-9]+}}(%e{{[sb]}}p), %esi # 4-byte Reload
224 ; X86-BMI-NEXT: addl {{[-0-9]+}}(%e{{[sb]}}p), %esi # 4-byte Folded Reload
225 ; X86-BMI-NEXT: adcl {{[-0-9]+}}(%e{{[sb]}}p), %edi # 4-byte Folded Reload
226 ; X86-BMI-NEXT: adcl $0, %ecx
227 ; X86-BMI-NEXT: adcl $0, %edx
228 ; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %eax
229 ; X86-BMI-NEXT: movl %esi, (%eax,%ebx,8)
230 ; X86-BMI-NEXT: movl %edi, 4(%eax,%ebx,8)
231 ; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %edi
232 ; X86-BMI-NEXT: addl $1, %ebx
233 ; X86-BMI-NEXT: adcl $0, %ebp
234 ; X86-BMI-NEXT: movl %ebx, %eax
235 ; X86-BMI-NEXT: xorl {{[0-9]+}}(%esp), %eax
236 ; X86-BMI-NEXT: movl %ebp, %esi
237 ; X86-BMI-NEXT: xorl %edi, %esi
238 ; X86-BMI-NEXT: orl %eax, %esi
239 ; X86-BMI-NEXT: jne .LBB1_2
240 ; X86-BMI-NEXT: .LBB1_3: # %for.end
241 ; X86-BMI-NEXT: xorl %eax, %eax
242 ; X86-BMI-NEXT: xorl %edx, %edx
243 ; X86-BMI-NEXT: addl $16, %esp
244 ; X86-BMI-NEXT: popl %esi
245 ; X86-BMI-NEXT: popl %edi
246 ; X86-BMI-NEXT: popl %ebx
247 ; X86-BMI-NEXT: popl %ebp
250 ; X64-NOBMI-LABEL: mul1:
251 ; X64-NOBMI: # %bb.0: # %entry
252 ; X64-NOBMI-NEXT: testq %rdi, %rdi
253 ; X64-NOBMI-NEXT: je .LBB1_3
254 ; X64-NOBMI-NEXT: # %bb.1: # %for.body.preheader
255 ; X64-NOBMI-NEXT: movq %rcx, %r8
256 ; X64-NOBMI-NEXT: movq %rdx, %r9
257 ; X64-NOBMI-NEXT: xorl %r10d, %r10d
258 ; X64-NOBMI-NEXT: xorl %ecx, %ecx
259 ; X64-NOBMI-NEXT: .p2align 4, 0x90
260 ; X64-NOBMI-NEXT: .LBB1_2: # %for.body
261 ; X64-NOBMI-NEXT: # =>This Inner Loop Header: Depth=1
262 ; X64-NOBMI-NEXT: movq %r8, %rax
263 ; X64-NOBMI-NEXT: mulq (%r9,%rcx,8)
264 ; X64-NOBMI-NEXT: addq %r10, %rax
265 ; X64-NOBMI-NEXT: adcq $0, %rdx
266 ; X64-NOBMI-NEXT: movq %rax, (%rsi,%rcx,8)
267 ; X64-NOBMI-NEXT: incq %rcx
268 ; X64-NOBMI-NEXT: cmpq %rcx, %rdi
269 ; X64-NOBMI-NEXT: movq %rdx, %r10
270 ; X64-NOBMI-NEXT: jne .LBB1_2
271 ; X64-NOBMI-NEXT: .LBB1_3: # %for.end
272 ; X64-NOBMI-NEXT: xorl %eax, %eax
273 ; X64-NOBMI-NEXT: retq
275 ; X64-BMI-LABEL: mul1:
276 ; X64-BMI: # %bb.0: # %entry
277 ; X64-BMI-NEXT: testq %rdi, %rdi
278 ; X64-BMI-NEXT: je .LBB1_3
279 ; X64-BMI-NEXT: # %bb.1: # %for.body.preheader
280 ; X64-BMI-NEXT: movq %rcx, %r8
281 ; X64-BMI-NEXT: movq %rdx, %r9
282 ; X64-BMI-NEXT: xorl %r10d, %r10d
283 ; X64-BMI-NEXT: xorl %ecx, %ecx
284 ; X64-BMI-NEXT: .p2align 4, 0x90
285 ; X64-BMI-NEXT: .LBB1_2: # %for.body
286 ; X64-BMI-NEXT: # =>This Inner Loop Header: Depth=1
287 ; X64-BMI-NEXT: movq %r8, %rdx
288 ; X64-BMI-NEXT: mulxq (%r9,%rcx,8), %rax, %rdx
289 ; X64-BMI-NEXT: addq %r10, %rax
290 ; X64-BMI-NEXT: adcq $0, %rdx
291 ; X64-BMI-NEXT: movq %rax, (%rsi,%rcx,8)
292 ; X64-BMI-NEXT: incq %rcx
293 ; X64-BMI-NEXT: cmpq %rcx, %rdi
294 ; X64-BMI-NEXT: movq %rdx, %r10
295 ; X64-BMI-NEXT: jne .LBB1_2
296 ; X64-BMI-NEXT: .LBB1_3: # %for.end
297 ; X64-BMI-NEXT: xorl %eax, %eax
300 %conv = zext i64 %y to i128
301 %cmp11 = icmp eq i64 %n, 0
302 br i1 %cmp11, label %for.end, label %for.body
304 for.body: ; preds = %entry, %for.body
305 %carry.013 = phi i64 [ %conv6, %for.body ], [ 0, %entry ]
306 %i.012 = phi i64 [ %inc, %for.body ], [ 0, %entry ]
307 %arrayidx = getelementptr inbounds i64, i64* %x, i64 %i.012
308 %0 = load i64, i64* %arrayidx, align 8
309 %conv2 = zext i64 %0 to i128
310 %mul = mul i128 %conv2, %conv
311 %conv3 = zext i64 %carry.013 to i128
312 %add = add i128 %mul, %conv3
313 %conv4 = trunc i128 %add to i64
314 %arrayidx5 = getelementptr inbounds i64, i64* %z, i64 %i.012
315 store i64 %conv4, i64* %arrayidx5, align 8
316 %shr = lshr i128 %add, 64
317 %conv6 = trunc i128 %shr to i64
318 %inc = add i64 %i.012, 1
319 %exitcond = icmp eq i64 %inc, %n
320 br i1 %exitcond, label %for.end, label %for.body
322 for.end: ; preds = %for.body, %entry