1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown -mcpu=core-avx2 | FileCheck %s
4 define i1 @try_cmpxchg(ptr %addr, i128 %desired, i128 %new) {
5 ; CHECK-LABEL: try_cmpxchg:
7 ; CHECK-NEXT: pushq %rbx
8 ; CHECK-NEXT: .cfi_def_cfa_offset 16
9 ; CHECK-NEXT: .cfi_offset %rbx, -16
10 ; CHECK-NEXT: movq %rcx, %rbx
11 ; CHECK-NEXT: movq %rsi, %rax
12 ; CHECK-NEXT: movq %r8, %rcx
13 ; CHECK-NEXT: lock cmpxchg16b (%rdi)
14 ; CHECK-NEXT: sete %al
15 ; CHECK-NEXT: popq %rbx
16 ; CHECK-NEXT: .cfi_def_cfa_offset 8
18 %pair = cmpxchg ptr %addr, i128 %desired, i128 %new seq_cst seq_cst
19 %success = extractvalue { i128, i1 } %pair, 1
23 define void @cmpxchg_flow(ptr %addr, i128 %desired, i128 %new) {
24 ; CHECK-LABEL: cmpxchg_flow:
26 ; CHECK-NEXT: pushq %rbx
27 ; CHECK-NEXT: .cfi_def_cfa_offset 16
28 ; CHECK-NEXT: .cfi_offset %rbx, -16
29 ; CHECK-NEXT: movq %rcx, %rbx
30 ; CHECK-NEXT: movq %rsi, %rax
31 ; CHECK-NEXT: movq %r8, %rcx
32 ; CHECK-NEXT: lock cmpxchg16b (%rdi)
33 ; CHECK-NEXT: jne .LBB1_2
34 ; CHECK-NEXT: # %bb.1: # %true
35 ; CHECK-NEXT: callq foo@PLT
36 ; CHECK-NEXT: popq %rbx
37 ; CHECK-NEXT: .cfi_def_cfa_offset 8
39 ; CHECK-NEXT: .LBB1_2: # %false
40 ; CHECK-NEXT: .cfi_def_cfa_offset 16
41 ; CHECK-NEXT: callq bar@PLT
42 ; CHECK-NEXT: popq %rbx
43 ; CHECK-NEXT: .cfi_def_cfa_offset 8
45 %pair = cmpxchg ptr %addr, i128 %desired, i128 %new seq_cst seq_cst
46 %success = extractvalue { i128, i1 } %pair, 1
47 br i1 %success, label %true, label %false
58 ; Can't use the flags here because cmpxchg16b only sets ZF.
59 define i1 @cmpxchg_arithcmp(ptr %addr, i128 %desired, i128 %new) {
60 ; CHECK-LABEL: cmpxchg_arithcmp:
62 ; CHECK-NEXT: pushq %rbx
63 ; CHECK-NEXT: .cfi_def_cfa_offset 16
64 ; CHECK-NEXT: .cfi_offset %rbx, -16
65 ; CHECK-NEXT: movq %rcx, %rbx
66 ; CHECK-NEXT: movq %rdx, %r9
67 ; CHECK-NEXT: movq %rsi, %rax
68 ; CHECK-NEXT: movq %r8, %rcx
69 ; CHECK-NEXT: lock cmpxchg16b (%rdi)
70 ; CHECK-NEXT: cmpq %rsi, %rax
71 ; CHECK-NEXT: sbbq %r9, %rdx
72 ; CHECK-NEXT: setge %al
73 ; CHECK-NEXT: popq %rbx
74 ; CHECK-NEXT: .cfi_def_cfa_offset 8
76 %pair = cmpxchg ptr %addr, i128 %desired, i128 %new seq_cst seq_cst
77 %oldval = extractvalue { i128, i1 } %pair, 0
78 %success = icmp sge i128 %oldval, %desired
82 define i128 @cmpxchg_zext(ptr %addr, i128 %desired, i128 %new) {
83 ; CHECK-LABEL: cmpxchg_zext:
85 ; CHECK-NEXT: pushq %rbx
86 ; CHECK-NEXT: .cfi_def_cfa_offset 16
87 ; CHECK-NEXT: .cfi_offset %rbx, -16
88 ; CHECK-NEXT: movq %rcx, %rbx
89 ; CHECK-NEXT: movq %rsi, %rax
90 ; CHECK-NEXT: xorl %esi, %esi
91 ; CHECK-NEXT: movq %r8, %rcx
92 ; CHECK-NEXT: lock cmpxchg16b (%rdi)
93 ; CHECK-NEXT: sete %sil
94 ; CHECK-NEXT: movq %rsi, %rax
95 ; CHECK-NEXT: xorl %edx, %edx
96 ; CHECK-NEXT: popq %rbx
97 ; CHECK-NEXT: .cfi_def_cfa_offset 8
99 %pair = cmpxchg ptr %addr, i128 %desired, i128 %new seq_cst seq_cst
100 %success = extractvalue { i128, i1 } %pair, 1
101 %mask = zext i1 %success to i128
106 define i128 @cmpxchg_use_eflags_and_val(ptr %addr, i128 %offset) {
107 ; CHECK-LABEL: cmpxchg_use_eflags_and_val:
108 ; CHECK: # %bb.0: # %entry
109 ; CHECK-NEXT: pushq %rbx
110 ; CHECK-NEXT: .cfi_def_cfa_offset 16
111 ; CHECK-NEXT: .cfi_offset %rbx, -16
112 ; CHECK-NEXT: movq %rdx, %r8
113 ; CHECK-NEXT: vmovdqa (%rdi), %xmm0
114 ; CHECK-NEXT: vpextrq $1, %xmm0, %rdx
115 ; CHECK-NEXT: vmovq %xmm0, %rax
116 ; CHECK-NEXT: .p2align 4
117 ; CHECK-NEXT: .LBB4_1: # %loop
118 ; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
119 ; CHECK-NEXT: movq %rdx, %r9
120 ; CHECK-NEXT: movq %rax, %r10
121 ; CHECK-NEXT: movq %rax, %rbx
122 ; CHECK-NEXT: addq %rsi, %rbx
123 ; CHECK-NEXT: movq %rdx, %rcx
124 ; CHECK-NEXT: adcq %r8, %rcx
125 ; CHECK-NEXT: lock cmpxchg16b (%rdi)
126 ; CHECK-NEXT: jne .LBB4_1
127 ; CHECK-NEXT: # %bb.2: # %done
128 ; CHECK-NEXT: movq %r10, %rax
129 ; CHECK-NEXT: movq %r9, %rdx
130 ; CHECK-NEXT: popq %rbx
131 ; CHECK-NEXT: .cfi_def_cfa_offset 8
134 %init = load atomic i128, ptr %addr seq_cst, align 16
138 %old = phi i128 [%init, %entry], [%oldval, %loop]
139 %new = add i128 %old, %offset
141 %pair = cmpxchg ptr %addr, i128 %old, i128 %new seq_cst seq_cst
142 %oldval = extractvalue { i128, i1 } %pair, 0
143 %success = extractvalue { i128, i1 } %pair, 1
145 br i1 %success, label %done, label %loop