1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-unknown-unknown | FileCheck %s --check-prefixes=X86,X86-NOBMI
3 ; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+bmi2 | FileCheck %s --check-prefixes=X86,X86-BMI
4 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefixes=X64,X64-NOBMI
5 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+bmi2 | FileCheck %s --check-prefixes=X64,X64-BMI
9 define i64 @foo(i64 %x, i64 %y) nounwind {
12 ; X86-NEXT: pushl %ebp
13 ; X86-NEXT: pushl %ebx
14 ; X86-NEXT: pushl %edi
15 ; X86-NEXT: pushl %esi
16 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
17 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ebp
18 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ebx
19 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
20 ; X86-NEXT: movl %ecx, %eax
22 ; X86-NEXT: movl %edx, %edi
23 ; X86-NEXT: movl %ebp, %eax
25 ; X86-NEXT: movl %edx, %ebx
26 ; X86-NEXT: movl %eax, %ebp
27 ; X86-NEXT: addl %edi, %ebp
28 ; X86-NEXT: adcl $0, %ebx
29 ; X86-NEXT: movl %ecx, %eax
31 ; X86-NEXT: movl %edx, %ecx
32 ; X86-NEXT: addl %ebp, %eax
33 ; X86-NEXT: adcl %ebx, %ecx
35 ; X86-NEXT: movzbl %al, %edi
36 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
38 ; X86-NEXT: addl %ecx, %eax
39 ; X86-NEXT: adcl %edi, %edx
48 ; X64-NEXT: movq %rdi, %rax
50 ; X64-NEXT: movq %rdx, %rax
52 %tmp0 = zext i64 %x to i128
53 %tmp1 = zext i64 %y to i128
54 %tmp2 = mul i128 %tmp0, %tmp1
55 %tmp7 = zext i32 64 to i128
56 %tmp3 = lshr i128 %tmp2, %tmp7
57 %tmp4 = trunc i128 %tmp3 to i64
61 ; <rdar://problem/14096009> superfluous multiply by high part of
62 ; zero-extended value.
64 define i64 @mul1(i64 %n, i64* nocapture %z, i64* nocapture %x, i64 %y) nounwind {
66 ; X86: # %bb.0: # %entry
67 ; X86-NEXT: pushl %ebp
68 ; X86-NEXT: pushl %ebx
69 ; X86-NEXT: pushl %edi
70 ; X86-NEXT: pushl %esi
71 ; X86-NEXT: subl $24, %esp
72 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
73 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
74 ; X86-NEXT: orl %ecx, %eax
75 ; X86-NEXT: je .LBB1_3
76 ; X86-NEXT: # %bb.1: # %for.body.preheader
77 ; X86-NEXT: xorl %eax, %eax
78 ; X86-NEXT: xorl %edx, %edx
79 ; X86-NEXT: xorl %ebp, %ebp
80 ; X86-NEXT: movl $0, (%esp) # 4-byte Folded Spill
81 ; X86-NEXT: .p2align 4, 0x90
82 ; X86-NEXT: .LBB1_2: # %for.body
83 ; X86-NEXT: # =>This Inner Loop Header: Depth=1
84 ; X86-NEXT: movl %edx, {{[-0-9]+}}(%e{{[sb]}}p) # 4-byte Spill
85 ; X86-NEXT: movl %eax, {{[-0-9]+}}(%e{{[sb]}}p) # 4-byte Spill
86 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
87 ; X86-NEXT: movl (%eax,%ebp,8), %esi
88 ; X86-NEXT: movl 4(%eax,%ebp,8), %ecx
89 ; X86-NEXT: movl %ecx, {{[-0-9]+}}(%e{{[sb]}}p) # 4-byte Spill
90 ; X86-NEXT: movl %esi, %eax
91 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
92 ; X86-NEXT: movl %edx, %edi
94 ; X86-NEXT: movl %edx, {{[-0-9]+}}(%e{{[sb]}}p) # 4-byte Spill
95 ; X86-NEXT: movl %eax, {{[-0-9]+}}(%e{{[sb]}}p) # 4-byte Spill
96 ; X86-NEXT: movl %ecx, %eax
98 ; X86-NEXT: movl %edx, %ecx
99 ; X86-NEXT: movl %eax, %ebx
100 ; X86-NEXT: addl {{[-0-9]+}}(%e{{[sb]}}p), %ebx # 4-byte Folded Reload
101 ; X86-NEXT: adcl $0, %ecx
102 ; X86-NEXT: movl %esi, %eax
103 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
104 ; X86-NEXT: mull %edx
105 ; X86-NEXT: movl %edx, %esi
106 ; X86-NEXT: movl %eax, %edi
107 ; X86-NEXT: addl %ebx, %edi
108 ; X86-NEXT: adcl %ecx, %esi
110 ; X86-NEXT: movl {{[-0-9]+}}(%e{{[sb]}}p), %eax # 4-byte Reload
111 ; X86-NEXT: mull {{[0-9]+}}(%esp)
112 ; X86-NEXT: addl %esi, %eax
113 ; X86-NEXT: movzbl %bl, %esi
114 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ebx
115 ; X86-NEXT: adcl %esi, %edx
116 ; X86-NEXT: movl {{[-0-9]+}}(%e{{[sb]}}p), %ecx # 4-byte Reload
117 ; X86-NEXT: addl {{[-0-9]+}}(%e{{[sb]}}p), %ecx # 4-byte Folded Reload
118 ; X86-NEXT: adcl {{[-0-9]+}}(%e{{[sb]}}p), %edi # 4-byte Folded Reload
119 ; X86-NEXT: adcl $0, %eax
120 ; X86-NEXT: adcl $0, %edx
121 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
122 ; X86-NEXT: movl %ecx, (%esi,%ebp,8)
123 ; X86-NEXT: movl %edi, 4(%esi,%ebp,8)
124 ; X86-NEXT: addl $1, %ebp
125 ; X86-NEXT: movl (%esp), %edi # 4-byte Reload
126 ; X86-NEXT: adcl $0, %edi
127 ; X86-NEXT: movl %ebp, %esi
128 ; X86-NEXT: xorl %ebx, %esi
129 ; X86-NEXT: movl %edi, (%esp) # 4-byte Spill
130 ; X86-NEXT: xorl {{[0-9]+}}(%esp), %edi
131 ; X86-NEXT: orl %esi, %edi
132 ; X86-NEXT: jne .LBB1_2
133 ; X86-NEXT: .LBB1_3: # %for.end
134 ; X86-NEXT: xorl %eax, %eax
135 ; X86-NEXT: xorl %edx, %edx
136 ; X86-NEXT: addl $24, %esp
137 ; X86-NEXT: popl %esi
138 ; X86-NEXT: popl %edi
139 ; X86-NEXT: popl %ebx
140 ; X86-NEXT: popl %ebp
144 ; X64: # %bb.0: # %entry
145 ; X64-NEXT: testq %rdi, %rdi
146 ; X64-NEXT: je .LBB1_3
147 ; X64-NEXT: # %bb.1: # %for.body.preheader
148 ; X64-NEXT: movq %rcx, %r8
149 ; X64-NEXT: movq %rdx, %r9
150 ; X64-NEXT: xorl %r10d, %r10d
151 ; X64-NEXT: xorl %ecx, %ecx
152 ; X64-NEXT: .p2align 4, 0x90
153 ; X64-NEXT: .LBB1_2: # %for.body
154 ; X64-NEXT: # =>This Inner Loop Header: Depth=1
155 ; X64-NEXT: movq %r8, %rax
156 ; X64-NEXT: mulq (%r9,%rcx,8)
157 ; X64-NEXT: addq %r10, %rax
158 ; X64-NEXT: adcq $0, %rdx
159 ; X64-NEXT: movq %rax, (%rsi,%rcx,8)
160 ; X64-NEXT: incq %rcx
161 ; X64-NEXT: cmpq %rcx, %rdi
162 ; X64-NEXT: movq %rdx, %r10
163 ; X64-NEXT: jne .LBB1_2
164 ; X64-NEXT: .LBB1_3: # %for.end
165 ; X64-NEXT: xorl %eax, %eax
168 %conv = zext i64 %y to i128
169 %cmp11 = icmp eq i64 %n, 0
170 br i1 %cmp11, label %for.end, label %for.body
172 for.body: ; preds = %entry, %for.body
173 %carry.013 = phi i64 [ %conv6, %for.body ], [ 0, %entry ]
174 %i.012 = phi i64 [ %inc, %for.body ], [ 0, %entry ]
175 %arrayidx = getelementptr inbounds i64, i64* %x, i64 %i.012
176 %0 = load i64, i64* %arrayidx, align 8
177 %conv2 = zext i64 %0 to i128
178 %mul = mul i128 %conv2, %conv
179 %conv3 = zext i64 %carry.013 to i128
180 %add = add i128 %mul, %conv3
181 %conv4 = trunc i128 %add to i64
182 %arrayidx5 = getelementptr inbounds i64, i64* %z, i64 %i.012
183 store i64 %conv4, i64* %arrayidx5, align 8
184 %shr = lshr i128 %add, 64
185 %conv6 = trunc i128 %shr to i64
186 %inc = add i64 %i.012, 1
187 %exitcond = icmp eq i64 %inc, %n
188 br i1 %exitcond, label %for.end, label %for.body
190 for.end: ; preds = %for.body, %entry