1 ; RUN: llc -mtriple=x86_64 -o - %s | FileCheck %s
3 define i1 @try_cmpxchg(ptr %addr, i32 %desired, i32 %new) {
4 ; CHECK-LABEL: try_cmpxchg:
9 %pair = cmpxchg ptr %addr, i32 %desired, i32 %new seq_cst seq_cst
10 %success = extractvalue { i32, i1 } %pair, 1
14 define void @cmpxchg_flow(ptr %addr, i64 %desired, i64 %new) {
15 ; CHECK-LABEL: cmpxchg_flow:
20 %pair = cmpxchg ptr %addr, i64 %desired, i64 %new seq_cst seq_cst
21 %success = extractvalue { i64, i1 } %pair, 1
22 br i1 %success, label %true, label %false
33 define i64 @cmpxchg_sext(ptr %addr, i32 %desired, i32 %new) {
34 ; CHECK-LABEL: cmpxchg_sext:
39 %pair = cmpxchg ptr %addr, i32 %desired, i32 %new seq_cst seq_cst
40 %success = extractvalue { i32, i1 } %pair, 1
41 %mask = sext i1 %success to i64
45 define i32 @cmpxchg_zext(ptr %addr, i32 %desired, i32 %new) {
46 ; CHECK-LABEL: cmpxchg_zext:
47 ; CHECK: xorl %e[[R:[a-z]]]x
51 %pair = cmpxchg ptr %addr, i32 %desired, i32 %new seq_cst seq_cst
52 %success = extractvalue { i32, i1 } %pair, 1
53 %mask = zext i1 %success to i32
58 define i32 @cmpxchg_use_eflags_and_val(ptr %addr, i32 %offset) {
59 ; CHECK-LABEL: cmpxchg_use_eflags_and_val:
60 ; CHECK: movl (%rdi), %e[[OLDVAL:[a-z0-9]+]]
62 ; CHECK: [[LOOPBB:.?LBB[0-9]+_[0-9]+]]:
63 ; CHECK: leal (%r[[OLDVAL]],%rsi), [[NEW:%[a-z0-9]+]]
64 ; CHECK: cmpxchgl [[NEW]], (%rdi)
66 ; CHECK: jne [[LOOPBB]]
68 ; Result already in %eax
71 %init = load atomic i32, ptr %addr seq_cst, align 4
75 %old = phi i32 [%init, %entry], [%oldval, %loop]
76 %new = add i32 %old, %offset
77 %pair = cmpxchg ptr %addr, i32 %old, i32 %new seq_cst seq_cst
78 %oldval = extractvalue { i32, i1 } %pair, 0
79 %success = extractvalue { i32, i1 } %pair, 1
80 br i1 %success, label %done, label %loop