[PowerPC] Recommit r314244 with refactoring and off by default
[llvm-core.git] / test / CodeGen / X86 / addcarry.ll
blobebeb85c2c8378c2121337426164d46830fb62e45
1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown | FileCheck %s
4 define void @a(i64* nocapture %s, i64* nocapture %t, i64 %a, i64 %b, i64 %c) nounwind {
5 ; CHECK-LABEL: a:
6 ; CHECK:       # BB#0: # %entry
7 ; CHECK-NEXT:    addq %rcx, %rdx
8 ; CHECK-NEXT:    adcq $0, %r8
9 ; CHECK-NEXT:    movq %r8, (%rdi)
10 ; CHECK-NEXT:    movq %rdx, (%rsi)
11 ; CHECK-NEXT:    retq
12 entry:
13  %0 = zext i64 %a to i128
14  %1 = zext i64 %b to i128
15  %2 = add i128 %1, %0
16  %3 = zext i64 %c to i128
17  %4 = shl i128 %3, 64
18  %5 = add i128 %4, %2
19  %6 = lshr i128 %5, 64
20  %7 = trunc i128 %6 to i64
21  store i64 %7, i64* %s, align 8
22  %8 = trunc i128 %2 to i64
23  store i64 %8, i64* %t, align 8
24  ret void
27 define void @b(i32* nocapture %r, i64 %a, i64 %b, i32 %c) nounwind {
28 ; CHECK-LABEL: b:
29 ; CHECK:       # BB#0: # %entry
30 ; CHECK-NEXT:    addq %rdx, %rsi
31 ; CHECK-NEXT:    adcl $0, %ecx
32 ; CHECK-NEXT:    movl %ecx, (%rdi)
33 ; CHECK-NEXT:    retq
34 entry:
35  %0 = zext i64 %a to i128
36  %1 = zext i64 %b to i128
37  %2 = zext i32 %c to i128
38  %3 = add i128 %1, %0
39  %4 = lshr i128 %3, 64
40  %5 = add i128 %4, %2
41  %6 = trunc i128 %5 to i32
42  store i32 %6, i32* %r, align 4
43  ret void
46 define void @c(i16* nocapture %r, i64 %a, i64 %b, i16 %c) nounwind {
47 ; CHECK-LABEL: c:
48 ; CHECK:       # BB#0: # %entry
49 ; CHECK-NEXT:    addq %rdx, %rsi
50 ; CHECK-NEXT:    adcw $0, %cx
51 ; CHECK-NEXT:    movw %cx, (%rdi)
52 ; CHECK-NEXT:    retq
53 entry:
54  %0 = zext i64 %a to i128
55  %1 = zext i64 %b to i128
56  %2 = zext i16 %c to i128
57  %3 = add i128 %1, %0
58  %4 = lshr i128 %3, 64
59  %5 = add i128 %4, %2
60  %6 = trunc i128 %5 to i16
61  store i16 %6, i16* %r, align 4
62  ret void
65 define void @d(i8* nocapture %r, i64 %a, i64 %b, i8 %c) nounwind {
66 ; CHECK-LABEL: d:
67 ; CHECK:       # BB#0: # %entry
68 ; CHECK-NEXT:    addq %rdx, %rsi
69 ; CHECK-NEXT:    adcb $0, %cl
70 ; CHECK-NEXT:    movb %cl, (%rdi)
71 ; CHECK-NEXT:    retq
72 entry:
73  %0 = zext i64 %a to i128
74  %1 = zext i64 %b to i128
75  %2 = zext i8 %c to i128
76  %3 = add i128 %1, %0
77  %4 = lshr i128 %3, 64
78  %5 = add i128 %4, %2
79  %6 = trunc i128 %5 to i8
80  store i8 %6, i8* %r, align 4
81  ret void
84 define i8 @e(i32* nocapture %a, i32 %b) nounwind {
85 ; CHECK-LABEL: e:
86 ; CHECK:       # BB#0:
87 ; CHECK-NEXT:    # kill: %esi<def> %esi<kill> %rsi<def>
88 ; CHECK-NEXT:    movl (%rdi), %ecx
89 ; CHECK-NEXT:    leal (%rsi,%rcx), %edx
90 ; CHECK-NEXT:    addl %esi, %edx
91 ; CHECK-NEXT:    setb %al
92 ; CHECK-NEXT:    addl %esi, %ecx
93 ; CHECK-NEXT:    movl %edx, (%rdi)
94 ; CHECK-NEXT:    adcb $0, %al
95 ; CHECK-NEXT:    retq
96   %1 = load i32, i32* %a, align 4
97   %2 = add i32 %1, %b
98   %3 = icmp ult i32 %2, %b
99   %4 = zext i1 %3 to i8
100   %5 = add i32 %2, %b
101   store i32 %5, i32* %a, align 4
102   %6 = icmp ult i32 %5, %b
103   %7 = zext i1 %6 to i8
104   %8 = add nuw nsw i8 %7, %4
105   ret i8 %8
108 %scalar = type { [4 x i64] }
110 define %scalar @pr31719(%scalar* nocapture readonly %this, %scalar %arg.b) {
111 ; CHECK-LABEL: pr31719:
112 ; CHECK:       # BB#0: # %entry
113 ; CHECK-NEXT:    addq (%rsi), %rdx
114 ; CHECK-NEXT:    adcq 8(%rsi), %rcx
115 ; CHECK-NEXT:    adcq 16(%rsi), %r8
116 ; CHECK-NEXT:    adcq 24(%rsi), %r9
117 ; CHECK-NEXT:    movq %rdx, (%rdi)
118 ; CHECK-NEXT:    movq %rcx, 8(%rdi)
119 ; CHECK-NEXT:    movq %r8, 16(%rdi)
120 ; CHECK-NEXT:    movq %r9, 24(%rdi)
121 ; CHECK-NEXT:    movq %rdi, %rax
122 ; CHECK-NEXT:    retq
123 entry:
124   %0 = extractvalue %scalar %arg.b, 0
125   %.elt = extractvalue [4 x i64] %0, 0
126   %.elt24 = extractvalue [4 x i64] %0, 1
127   %.elt26 = extractvalue [4 x i64] %0, 2
128   %.elt28 = extractvalue [4 x i64] %0, 3
129   %1 = getelementptr inbounds %scalar , %scalar* %this, i64 0, i32 0, i64 0
130   %2 = load i64, i64* %1, align 8
131   %3 = zext i64 %2 to i128
132   %4 = zext i64 %.elt to i128
133   %5 = add nuw nsw i128 %3, %4
134   %6 = trunc i128 %5 to i64
135   %7 = lshr i128 %5, 64
136   %8 = getelementptr inbounds %scalar , %scalar * %this, i64 0, i32 0, i64 1
137   %9 = load i64, i64* %8, align 8
138   %10 = zext i64 %9 to i128
139   %11 = zext i64 %.elt24 to i128
140   %12 = add nuw nsw i128 %10, %11
141   %13 = add nuw nsw i128 %12, %7
142   %14 = trunc i128 %13 to i64
143   %15 = lshr i128 %13, 64
144   %16 = getelementptr inbounds %scalar , %scalar* %this, i64 0, i32 0, i64 2
145   %17 = load i64, i64* %16, align 8
146   %18 = zext i64 %17 to i128
147   %19 = zext i64 %.elt26 to i128
148   %20 = add nuw nsw i128 %18, %19
149   %21 = add nuw nsw i128 %20, %15
150   %22 = trunc i128 %21 to i64
151   %23 = lshr i128 %21, 64
152   %24 = getelementptr inbounds %scalar , %scalar* %this, i64 0, i32 0, i64 3
153   %25 = load i64, i64* %24, align 8
154   %26 = zext i64 %25 to i128
155   %27 = zext i64 %.elt28 to i128
156   %28 = add nuw nsw i128 %26, %27
157   %29 = add nuw nsw i128 %28, %23
158   %30 = trunc i128 %29 to i64
159   %31 = insertvalue [4 x i64] undef, i64 %6, 0
160   %32 = insertvalue [4 x i64] %31, i64 %14, 1
161   %33 = insertvalue [4 x i64] %32, i64 %22, 2
162   %34 = insertvalue [4 x i64] %33, i64 %30, 3
163   %35 = insertvalue %scalar undef, [4 x i64] %34, 0
164   ret %scalar %35
167 %accumulator= type { i64, i64, i32 }
169 define void @muladd(%accumulator* nocapture %this, i64 %arg.a, i64 %arg.b) {
170 ; CHECK-LABEL: muladd:
171 ; CHECK:       # BB#0: # %entry
172 ; CHECK-NEXT:    movq %rdx, %rax
173 ; CHECK-NEXT:    mulq %rsi
174 ; CHECK-NEXT:    addq %rax, (%rdi)
175 ; CHECK-NEXT:    adcq 8(%rdi), %rdx
176 ; CHECK-NEXT:    movq %rdx, 8(%rdi)
177 ; CHECK-NEXT:    adcl $0, 16(%rdi)
178 ; CHECK-NEXT:    retq
179 entry:
180   %0 = zext i64 %arg.a to i128
181   %1 = zext i64 %arg.b to i128
182   %2 = mul nuw i128 %1, %0
183   %3 = getelementptr inbounds %accumulator, %accumulator* %this, i64 0, i32 0
184   %4 = load i64, i64* %3, align 8
185   %5 = zext i64 %4 to i128
186   %6 = add i128 %5, %2
187   %7 = trunc i128 %6 to i64
188   store i64 %7, i64* %3, align 8
189   %8 = lshr i128 %6, 64
190   %9 = getelementptr inbounds %accumulator, %accumulator* %this, i64 0, i32 1
191   %10 = load i64, i64* %9, align 8
192   %11 = zext i64 %10 to i128
193   %12 = add nuw nsw i128 %8, %11
194   %13 = trunc i128 %12 to i64
195   store i64 %13, i64* %9, align 8
196   %14 = lshr i128 %12, 64
197   %15 = getelementptr inbounds %accumulator, %accumulator* %this, i64 0, i32 2
198   %16 = load i32, i32* %15, align 4
199   %17 = zext i32 %16 to i128
200   %18 = add nuw nsw i128 %14, %17
201   %19 = trunc i128 %18 to i32
202   store i32 %19, i32* %15, align 4
203   ret void
206 define i64 @shiftadd(i64 %a, i64 %b, i64 %c, i64 %d) {
207 ; CHECK-LABEL: shiftadd:
208 ; CHECK:       # BB#0: # %entry
209 ; CHECK-NEXT:    addq %rsi, %rdi
210 ; CHECK-NEXT:    adcq %rcx, %rdx
211 ; CHECK-NEXT:    movq %rdx, %rax
212 ; CHECK-NEXT:    retq
213 entry:
214   %0 = zext i64 %a to i128
215   %1 = zext i64 %b to i128
216   %2 = add i128 %0, %1
217   %3 = lshr i128 %2, 64
218   %4 = trunc i128 %3 to i64
219   %5 = add i64 %c, %d
220   %6 = add i64 %4, %5
221   ret i64 %6
224 %S = type { [4 x i64] }
226 define %S @readd(%S* nocapture readonly %this, %S %arg.b) {
227 ; CHECK-LABEL: readd:
228 ; CHECK:       # BB#0: # %entry
229 ; CHECK-NEXT:    addq (%rsi), %rdx
230 ; CHECK-NEXT:    movq 8(%rsi), %r10
231 ; CHECK-NEXT:    adcq $0, %r10
232 ; CHECK-NEXT:    setb %al
233 ; CHECK-NEXT:    movzbl %al, %eax
234 ; CHECK-NEXT:    addq %rcx, %r10
235 ; CHECK-NEXT:    adcq 16(%rsi), %rax
236 ; CHECK-NEXT:    setb %cl
237 ; CHECK-NEXT:    movzbl %cl, %ecx
238 ; CHECK-NEXT:    addq %r8, %rax
239 ; CHECK-NEXT:    adcq 24(%rsi), %rcx
240 ; CHECK-NEXT:    addq %r9, %rcx
241 ; CHECK-NEXT:    movq %rdx, (%rdi)
242 ; CHECK-NEXT:    movq %r10, 8(%rdi)
243 ; CHECK-NEXT:    movq %rax, 16(%rdi)
244 ; CHECK-NEXT:    movq %rcx, 24(%rdi)
245 ; CHECK-NEXT:    movq %rdi, %rax
246 ; CHECK-NEXT:    retq
247 entry:
248   %0 = extractvalue %S %arg.b, 0
249   %.elt6 = extractvalue [4 x i64] %0, 1
250   %.elt8 = extractvalue [4 x i64] %0, 2
251   %.elt10 = extractvalue [4 x i64] %0, 3
252   %.elt = extractvalue [4 x i64] %0, 0
253   %1 = getelementptr inbounds %S, %S* %this, i64 0, i32 0, i64 0
254   %2 = load i64, i64* %1, align 8
255   %3 = zext i64 %2 to i128
256   %4 = zext i64 %.elt to i128
257   %5 = add nuw nsw i128 %3, %4
258   %6 = trunc i128 %5 to i64
259   %7 = lshr i128 %5, 64
260   %8 = getelementptr inbounds %S, %S* %this, i64 0, i32 0, i64 1
261   %9 = load i64, i64* %8, align 8
262   %10 = zext i64 %9 to i128
263   %11 = add nuw nsw i128 %7, %10
264   %12 = zext i64 %.elt6 to i128
265   %13 = add nuw nsw i128 %11, %12
266   %14 = trunc i128 %13 to i64
267   %15 = lshr i128 %13, 64
268   %16 = getelementptr inbounds %S, %S* %this, i64 0, i32 0, i64 2
269   %17 = load i64, i64* %16, align 8
270   %18 = zext i64 %17 to i128
271   %19 = add nuw nsw i128 %15, %18
272   %20 = zext i64 %.elt8 to i128
273   %21 = add nuw nsw i128 %19, %20
274   %22 = lshr i128 %21, 64
275   %23 = trunc i128 %21 to i64
276   %24 = getelementptr inbounds %S, %S* %this, i64 0,i32 0, i64 3
277   %25 = load i64, i64* %24, align 8
278   %26 = zext i64 %25 to i128
279   %27 = add nuw nsw i128 %22, %26
280   %28 = zext i64 %.elt10 to i128
281   %29 = add nuw nsw i128 %27, %28
282   %30 = trunc i128 %29 to i64
283   %31 = insertvalue [4 x i64] undef, i64 %6, 0
284   %32 = insertvalue [4 x i64] %31, i64 %14, 1
285   %33 = insertvalue [4 x i64] %32, i64 %23, 2
286   %34 = insertvalue [4 x i64] %33, i64 %30, 3
287   %35 = insertvalue %S undef, [4 x i64] %34, 0
288   ret %S %35