1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=corei7 --show-mc-encoding | FileCheck %s --check-prefix=CHECK --check-prefix=NOADX
3 ; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=broadwell --show-mc-encoding | FileCheck %s --check-prefix=CHECK --check-prefix=ADX
5 define i8 @test_addcarry_32_load(i8 %c, i32* %aptr, i32 %b, i8* %ptr) {
6 ; CHECK-LABEL: test_addcarry_32_load:
8 ; CHECK-NEXT: addb $-1, %dil ## encoding: [0x40,0x80,0xc7,0xff]
9 ; CHECK-NEXT: adcl (%rsi), %edx ## encoding: [0x13,0x16]
10 ; CHECK-NEXT: setb %al ## encoding: [0x0f,0x92,0xc0]
11 ; CHECK-NEXT: movl %edx, (%rcx) ## encoding: [0x89,0x11]
12 ; CHECK-NEXT: retq ## encoding: [0xc3]
13 %a = load i32, i32* %aptr
14 %ret = call { i8, i32 } @llvm.x86.addcarry.32(i8 %c, i32 %a, i32 %b)
15 %1 = extractvalue { i8, i32 } %ret, 1
16 %2 = bitcast i8* %ptr to i32*
17 store i32 %1, i32* %2, align 1
18 %3 = extractvalue { i8, i32 } %ret, 0
22 define i8 @test_addcarry_32_load2(i8 %c, i32 %a, i32* %bptr, i8* %ptr) {
23 ; CHECK-LABEL: test_addcarry_32_load2:
25 ; CHECK-NEXT: addb $-1, %dil ## encoding: [0x40,0x80,0xc7,0xff]
26 ; CHECK-NEXT: adcl (%rdx), %esi ## encoding: [0x13,0x32]
27 ; CHECK-NEXT: setb %al ## encoding: [0x0f,0x92,0xc0]
28 ; CHECK-NEXT: movl %esi, (%rcx) ## encoding: [0x89,0x31]
29 ; CHECK-NEXT: retq ## encoding: [0xc3]
30 %b = load i32, i32* %bptr
31 %ret = call { i8, i32 } @llvm.x86.addcarry.32(i8 %c, i32 %a, i32 %b)
32 %1 = extractvalue { i8, i32 } %ret, 1
33 %2 = bitcast i8* %ptr to i32*
34 store i32 %1, i32* %2, align 1
35 %3 = extractvalue { i8, i32 } %ret, 0
39 declare { i8, i32 } @llvm.x86.addcarry.32(i8, i32, i32)
41 define i8 @test_addcarry_32(i8 %c, i32 %a, i32 %b, i8* %ptr) {
42 ; CHECK-LABEL: test_addcarry_32:
44 ; CHECK-NEXT: addb $-1, %dil ## encoding: [0x40,0x80,0xc7,0xff]
45 ; CHECK-NEXT: adcl %edx, %esi ## encoding: [0x11,0xd6]
46 ; CHECK-NEXT: setb %al ## encoding: [0x0f,0x92,0xc0]
47 ; CHECK-NEXT: movl %esi, (%rcx) ## encoding: [0x89,0x31]
48 ; CHECK-NEXT: retq ## encoding: [0xc3]
49 %ret = call { i8, i32 } @llvm.x86.addcarry.32(i8 %c, i32 %a, i32 %b)
50 %1 = extractvalue { i8, i32 } %ret, 1
51 %2 = bitcast i8* %ptr to i32*
52 store i32 %1, i32* %2, align 1
53 %3 = extractvalue { i8, i32 } %ret, 0
57 declare { i8, i64 } @llvm.x86.addcarry.64(i8, i64, i64)
59 define i8 @test_addcarry_64(i8 %c, i64 %a, i64 %b, i8* %ptr) {
60 ; CHECK-LABEL: test_addcarry_64:
62 ; CHECK-NEXT: addb $-1, %dil ## encoding: [0x40,0x80,0xc7,0xff]
63 ; CHECK-NEXT: adcq %rdx, %rsi ## encoding: [0x48,0x11,0xd6]
64 ; CHECK-NEXT: setb %al ## encoding: [0x0f,0x92,0xc0]
65 ; CHECK-NEXT: movq %rsi, (%rcx) ## encoding: [0x48,0x89,0x31]
66 ; CHECK-NEXT: retq ## encoding: [0xc3]
67 %ret = call { i8, i64 } @llvm.x86.addcarry.64(i8 %c, i64 %a, i64 %b)
68 %1 = extractvalue { i8, i64 } %ret, 1
69 %2 = bitcast i8* %ptr to i64*
70 store i64 %1, i64* %2, align 1
71 %3 = extractvalue { i8, i64 } %ret, 0
75 declare { i8, i32 } @llvm.x86.subborrow.32(i8, i32, i32)
77 define i8 @test_subborrow_32(i8 %c, i32 %a, i32 %b, i8* %ptr) {
78 ; CHECK-LABEL: test_subborrow_32:
80 ; CHECK-NEXT: addb $-1, %dil ## encoding: [0x40,0x80,0xc7,0xff]
81 ; CHECK-NEXT: sbbl %edx, %esi ## encoding: [0x19,0xd6]
82 ; CHECK-NEXT: setb %al ## encoding: [0x0f,0x92,0xc0]
83 ; CHECK-NEXT: movl %esi, (%rcx) ## encoding: [0x89,0x31]
84 ; CHECK-NEXT: retq ## encoding: [0xc3]
85 %ret = call { i8, i32 } @llvm.x86.subborrow.32(i8 %c, i32 %a, i32 %b)
86 %1 = extractvalue { i8, i32 } %ret, 1
87 %2 = bitcast i8* %ptr to i32*
88 store i32 %1, i32* %2, align 1
89 %3 = extractvalue { i8, i32 } %ret, 0
93 declare { i8, i64 } @llvm.x86.subborrow.64(i8, i64, i64)
95 define i8 @test_subborrow_64(i8 %c, i64 %a, i64 %b, i8* %ptr) {
96 ; CHECK-LABEL: test_subborrow_64:
98 ; CHECK-NEXT: addb $-1, %dil ## encoding: [0x40,0x80,0xc7,0xff]
99 ; CHECK-NEXT: sbbq %rdx, %rsi ## encoding: [0x48,0x19,0xd6]
100 ; CHECK-NEXT: setb %al ## encoding: [0x0f,0x92,0xc0]
101 ; CHECK-NEXT: movq %rsi, (%rcx) ## encoding: [0x48,0x89,0x31]
102 ; CHECK-NEXT: retq ## encoding: [0xc3]
103 %ret = call { i8, i64 } @llvm.x86.subborrow.64(i8 %c, i64 %a, i64 %b)
104 %1 = extractvalue { i8, i64 } %ret, 1
105 %2 = bitcast i8* %ptr to i64*
106 store i64 %1, i64* %2, align 1
107 %3 = extractvalue { i8, i64 } %ret, 0
111 ; Try a version with loads. Previously we crashed on this.
112 define i32 @load_crash(i64* nocapture readonly %a, i64* nocapture readonly %b, i64* %res) {
113 ; CHECK-LABEL: load_crash:
115 ; CHECK-NEXT: movq (%rdi), %rcx ## encoding: [0x48,0x8b,0x0f]
116 ; CHECK-NEXT: xorl %eax, %eax ## encoding: [0x31,0xc0]
117 ; CHECK-NEXT: addq (%rsi), %rcx ## encoding: [0x48,0x03,0x0e]
118 ; CHECK-NEXT: setb %al ## encoding: [0x0f,0x92,0xc0]
119 ; CHECK-NEXT: movq %rcx, (%rdx) ## encoding: [0x48,0x89,0x0a]
120 ; CHECK-NEXT: retq ## encoding: [0xc3]
121 %1 = load i64, i64* %a, align 8
122 %2 = load i64, i64* %b, align 8
123 %3 = bitcast i64* %res to i8*
124 %4 = call { i8, i64 } @llvm.x86.addcarry.64(i8 0, i64 %1, i64 %2)
125 %5 = extractvalue { i8, i64 } %4, 1
126 %6 = bitcast i8* %3 to i64*
127 store i64 %5, i64* %6, align 1
128 %7 = extractvalue { i8, i64 } %4, 0
129 %conv = zext i8 %7 to i32
133 ; Try a really simple all zero input case, which also used to crash
134 define void @allzeros() {
135 ; CHECK-LABEL: allzeros:
136 ; CHECK: ## %bb.0: ## %entry
137 ; CHECK-NEXT: movq $0, 0 ## encoding: [0x48,0xc7,0x04,0x25,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
138 ; CHECK-NEXT: retq ## encoding: [0xc3]
140 %0 = call { i8, i64 } @llvm.x86.addcarry.64(i8 0, i64 0, i64 0)
141 %1 = extractvalue { i8, i64 } %0, 1
142 store i64 %1, i64* null, align 1
143 %2 = extractvalue { i8, i64 } %0, 0