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 declare i8 @llvm.x86.addcarryx.u32(i8, i32, i32, i8*)
7 define i8 @test_addcarryx_u32(i8 %c, i32 %a, i32 %b, i8* %ptr) {
8 ; CHECK-LABEL: test_addcarryx_u32:
10 ; CHECK-NEXT: addb $-1, %dil ## encoding: [0x40,0x80,0xc7,0xff]
11 ; CHECK-NEXT: adcl %edx, %esi ## encoding: [0x11,0xd6]
12 ; CHECK-NEXT: setb %al ## encoding: [0x0f,0x92,0xc0]
13 ; CHECK-NEXT: movl %esi, (%rcx) ## encoding: [0x89,0x31]
14 ; CHECK-NEXT: retq ## encoding: [0xc3]
15 %ret = tail call i8 @llvm.x86.addcarryx.u32(i8 %c, i32 %a, i32 %b, i8* %ptr)
19 declare i8 @llvm.x86.addcarryx.u64(i8, i64, i64, i8*)
21 define i8 @test_addcarryx_u64(i8 %c, i64 %a, i64 %b, i8* %ptr) {
22 ; CHECK-LABEL: test_addcarryx_u64:
24 ; CHECK-NEXT: addb $-1, %dil ## encoding: [0x40,0x80,0xc7,0xff]
25 ; CHECK-NEXT: adcq %rdx, %rsi ## encoding: [0x48,0x11,0xd6]
26 ; CHECK-NEXT: setb %al ## encoding: [0x0f,0x92,0xc0]
27 ; CHECK-NEXT: movq %rsi, (%rcx) ## encoding: [0x48,0x89,0x31]
28 ; CHECK-NEXT: retq ## encoding: [0xc3]
29 %ret = tail call i8 @llvm.x86.addcarryx.u64(i8 %c, i64 %a, i64 %b, i8* %ptr)
33 declare i8 @llvm.x86.addcarry.u32(i8, i32, i32, i8*)
35 define i8 @test_addcarry_u32(i8 %c, i32 %a, i32 %b, i8* %ptr) {
36 ; CHECK-LABEL: test_addcarry_u32:
38 ; CHECK-NEXT: addb $-1, %dil ## encoding: [0x40,0x80,0xc7,0xff]
39 ; CHECK-NEXT: adcl %edx, %esi ## encoding: [0x11,0xd6]
40 ; CHECK-NEXT: setb %al ## encoding: [0x0f,0x92,0xc0]
41 ; CHECK-NEXT: movl %esi, (%rcx) ## encoding: [0x89,0x31]
42 ; CHECK-NEXT: retq ## encoding: [0xc3]
43 %ret = tail call i8 @llvm.x86.addcarry.u32(i8 %c, i32 %a, i32 %b, i8* %ptr)
47 declare i8 @llvm.x86.addcarry.u64(i8, i64, i64, i8*)
49 define i8 @test_addcarry_u64(i8 %c, i64 %a, i64 %b, i8* %ptr) {
50 ; CHECK-LABEL: test_addcarry_u64:
52 ; CHECK-NEXT: addb $-1, %dil ## encoding: [0x40,0x80,0xc7,0xff]
53 ; CHECK-NEXT: adcq %rdx, %rsi ## encoding: [0x48,0x11,0xd6]
54 ; CHECK-NEXT: setb %al ## encoding: [0x0f,0x92,0xc0]
55 ; CHECK-NEXT: movq %rsi, (%rcx) ## encoding: [0x48,0x89,0x31]
56 ; CHECK-NEXT: retq ## encoding: [0xc3]
57 %ret = tail call i8 @llvm.x86.addcarry.u64(i8 %c, i64 %a, i64 %b, i8* %ptr)
61 declare i8 @llvm.x86.subborrow.u32(i8, i32, i32, i8*)
63 define i8 @test_subborrow_u32(i8 %c, i32 %a, i32 %b, i8* %ptr) {
64 ; CHECK-LABEL: test_subborrow_u32:
66 ; CHECK-NEXT: addb $-1, %dil ## encoding: [0x40,0x80,0xc7,0xff]
67 ; CHECK-NEXT: sbbl %edx, %esi ## encoding: [0x19,0xd6]
68 ; CHECK-NEXT: setb %al ## encoding: [0x0f,0x92,0xc0]
69 ; CHECK-NEXT: movl %esi, (%rcx) ## encoding: [0x89,0x31]
70 ; CHECK-NEXT: retq ## encoding: [0xc3]
71 %ret = tail call i8 @llvm.x86.subborrow.u32(i8 %c, i32 %a, i32 %b, i8* %ptr)
75 declare i8 @llvm.x86.subborrow.u64(i8, i64, i64, i8*)
77 define i8 @test_subborrow_u64(i8 %c, i64 %a, i64 %b, i8* %ptr) {
78 ; CHECK-LABEL: test_subborrow_u64:
80 ; CHECK-NEXT: addb $-1, %dil ## encoding: [0x40,0x80,0xc7,0xff]
81 ; CHECK-NEXT: sbbq %rdx, %rsi ## encoding: [0x48,0x19,0xd6]
82 ; CHECK-NEXT: setb %al ## encoding: [0x0f,0x92,0xc0]
83 ; CHECK-NEXT: movq %rsi, (%rcx) ## encoding: [0x48,0x89,0x31]
84 ; CHECK-NEXT: retq ## encoding: [0xc3]
85 %ret = tail call i8 @llvm.x86.subborrow.u64(i8 %c, i64 %a, i64 %b, i8* %ptr)
89 ; Try a version with loads. Previously we crashed on this.
90 define i32 @load_crash(i64* nocapture readonly %a, i64* nocapture readonly %b, i64* %res) {
91 ; CHECK-LABEL: load_crash:
93 ; CHECK-NEXT: movq (%rdi), %rcx ## encoding: [0x48,0x8b,0x0f]
94 ; CHECK-NEXT: xorl %eax, %eax ## encoding: [0x31,0xc0]
95 ; CHECK-NEXT: addq (%rsi), %rcx ## encoding: [0x48,0x03,0x0e]
96 ; CHECK-NEXT: setb %al ## encoding: [0x0f,0x92,0xc0]
97 ; CHECK-NEXT: movq %rcx, (%rdx) ## encoding: [0x48,0x89,0x0a]
98 ; CHECK-NEXT: retq ## encoding: [0xc3]
99 %1 = load i64, i64* %a, align 8
100 %2 = load i64, i64* %b, align 8
101 %3 = bitcast i64* %res to i8*
102 %4 = tail call i8 @llvm.x86.addcarryx.u64(i8 0, i64 %1, i64 %2, i8* %3)
103 %conv = zext i8 %4 to i32
107 ; Try a really simple all zero input case, which also used to crash
108 define void @allzeros() {
109 ; CHECK-LABEL: allzeros:
110 ; CHECK: ## %bb.0: ## %entry
111 ; CHECK-NEXT: movq $0, 0 ## encoding: [0x48,0xc7,0x04,0x25,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
112 ; CHECK-NEXT: retq ## encoding: [0xc3]
114 %0 = tail call i8 @llvm.x86.addcarryx.u64(i8 0, i64 0, i64 0, i8* null)