mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-22 07:32:48 +00:00
eee7a7a836
Lowering this new node allows us to fold the almost universal comparison for success before it's even formed. Instead we can create a copy from EFLAGS and an X86ISD::SETCC operation since all "cmpxchg" instructions set the zero-flag to the correct value. rdar://problem/13201607 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210923 91177308-0d34-0410-b5e6-96231b3b80d8
88 lines
2.2 KiB
LLVM
88 lines
2.2 KiB
LLVM
; RUN: llc -mtriple=x86_64 -o - %s | FileCheck %s
|
|
|
|
define i1 @try_cmpxchg(i32* %addr, i32 %desired, i32 %new) {
|
|
; CHECK-LABEL: try_cmpxchg:
|
|
; CHECK: cmpxchgl
|
|
; CHECK-NOT: cmp
|
|
; CHECK: sete %al
|
|
; CHECK: retq
|
|
%pair = cmpxchg i32* %addr, i32 %desired, i32 %new seq_cst seq_cst
|
|
%success = extractvalue { i32, i1 } %pair, 1
|
|
ret i1 %success
|
|
}
|
|
|
|
define void @cmpxchg_flow(i64* %addr, i64 %desired, i64 %new) {
|
|
; CHECK-LABEL: cmpxchg_flow:
|
|
; CHECK: cmpxchgq
|
|
; CHECK-NOT: cmp
|
|
; CHECK-NOT: set
|
|
; CHECK: {{jne|jeq}}
|
|
%pair = cmpxchg i64* %addr, i64 %desired, i64 %new seq_cst seq_cst
|
|
%success = extractvalue { i64, i1 } %pair, 1
|
|
br i1 %success, label %true, label %false
|
|
|
|
true:
|
|
call void @foo()
|
|
ret void
|
|
|
|
false:
|
|
call void @bar()
|
|
ret void
|
|
}
|
|
|
|
define i64 @cmpxchg_sext(i32* %addr, i32 %desired, i32 %new) {
|
|
; CHECK-LABEL: cmpxchg_sext:
|
|
; CHECK-DAG: cmpxchgl
|
|
; CHECK-NOT: cmpl
|
|
; CHECK: sete %al
|
|
; CHECK: retq
|
|
%pair = cmpxchg i32* %addr, i32 %desired, i32 %new seq_cst seq_cst
|
|
%success = extractvalue { i32, i1 } %pair, 1
|
|
%mask = sext i1 %success to i64
|
|
ret i64 %mask
|
|
}
|
|
|
|
define i32 @cmpxchg_zext(i32* %addr, i32 %desired, i32 %new) {
|
|
; CHECK-LABEL: cmpxchg_zext:
|
|
; CHECK: cmpxchgl
|
|
; CHECK-NOT: cmp
|
|
; CHECK: sete [[BYTE:%[a-z0-9]+]]
|
|
; CHECK: movzbl [[BYTE]], %eax
|
|
%pair = cmpxchg i32* %addr, i32 %desired, i32 %new seq_cst seq_cst
|
|
%success = extractvalue { i32, i1 } %pair, 1
|
|
%mask = zext i1 %success to i32
|
|
ret i32 %mask
|
|
}
|
|
|
|
|
|
define i32 @cmpxchg_use_eflags_and_val(i32* %addr, i32 %offset) {
|
|
; CHECK-LABEL: cmpxchg_use_eflags_and_val:
|
|
; CHECK: movl (%rdi), %e[[OLDVAL:[a-z0-9]+]]
|
|
|
|
; CHECK: [[LOOPBB:.?LBB[0-9]+_[0-9]+]]:
|
|
; CHECK: leal (%r[[OLDVAL]],%rsi), [[NEW:%[a-z0-9]+]]
|
|
; CHECK: cmpxchgl [[NEW]], (%rdi)
|
|
; CHECK-NOT: cmpl
|
|
; CHECK: jne [[LOOPBB]]
|
|
|
|
; Result already in %eax
|
|
; CHECK: retq
|
|
entry:
|
|
%init = load atomic i32* %addr seq_cst, align 4
|
|
br label %loop
|
|
|
|
loop:
|
|
%old = phi i32 [%init, %entry], [%oldval, %loop]
|
|
%new = add i32 %old, %offset
|
|
%pair = cmpxchg i32* %addr, i32 %old, i32 %new seq_cst seq_cst
|
|
%oldval = extractvalue { i32, i1 } %pair, 0
|
|
%success = extractvalue { i32, i1 } %pair, 1
|
|
br i1 %success, label %done, label %loop
|
|
|
|
done:
|
|
ret i32 %oldval
|
|
}
|
|
|
|
declare void @foo()
|
|
declare void @bar()
|