mirror of
https://github.com/RPCSX/llvm.git
synced 2025-01-08 13:00:43 +00:00
dc0c75dcb1
DMB instructions can be expensive, so it's best to avoid them if possible. In atomicrmw operations there will always be an attempted store so a release barrier is always needed, but in the cmpxchg case we can delay the DMB until we know we'll definitely try to perform a store (and so need release semantics). In the strong cmpxchg case this isn't quite free: we must duplicate the LDREX instructions to skip the barrier on subsequent iterations. The basic outline becomes: ldrex rOld, [rAddr] cmp rOld, rDesired bne Ldone dmb Lloop: strex rRes, rNew, [rAddr] cbz rRes Ldone ldrex rOld, [rAddr] cmp rOld, rDesired beq Lloop Ldone: So we'll skip this version for strong operations in "minsize" functions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261568 91177308-0d34-0410-b5e6-96231b3b80d8
58 lines
1.8 KiB
LLVM
58 lines
1.8 KiB
LLVM
; RUN: llc < %s -mtriple=armv7-apple-ios -verify-machineinstrs | FileCheck %s
|
|
|
|
define void @test_cmpxchg_weak(i32 *%addr, i32 %desired, i32 %new) {
|
|
; CHECK-LABEL: test_cmpxchg_weak:
|
|
|
|
%pair = cmpxchg weak i32* %addr, i32 %desired, i32 %new seq_cst monotonic
|
|
%oldval = extractvalue { i32, i1 } %pair, 0
|
|
; CHECK-NEXT: BB#0:
|
|
; CHECK-NEXT: ldrex [[LOADED:r[0-9]+]], [r0]
|
|
; CHECK-NEXT: cmp [[LOADED]], r1
|
|
; CHECK-NEXT: bne [[LDFAILBB:LBB[0-9]+_[0-9]+]]
|
|
; CHECK-NEXT: BB#1:
|
|
; CHECK-NEXT: dmb ish
|
|
; CHECK-NEXT: strex [[SUCCESS:r[0-9]+]], r2, [r0]
|
|
; CHECK-NEXT: cmp [[SUCCESS]], #0
|
|
; CHECK-NEXT: bne [[FAILBB:LBB[0-9]+_[0-9]+]]
|
|
; CHECK-NEXT: BB#2:
|
|
; CHECK-NEXT: dmb ish
|
|
; CHECK-NEXT: str r3, [r0]
|
|
; CHECK-NEXT: bx lr
|
|
; CHECK-NEXT: [[LDFAILBB]]:
|
|
; CHECK-NEXT: clrex
|
|
; CHECK-NEXT: [[FAILBB]]:
|
|
; CHECK-NEXT: str r3, [r0]
|
|
; CHECK-NEXT: bx lr
|
|
|
|
store i32 %oldval, i32* %addr
|
|
ret void
|
|
}
|
|
|
|
|
|
define i1 @test_cmpxchg_weak_to_bool(i32, i32 *%addr, i32 %desired, i32 %new) {
|
|
; CHECK-LABEL: test_cmpxchg_weak_to_bool:
|
|
|
|
%pair = cmpxchg weak i32* %addr, i32 %desired, i32 %new seq_cst monotonic
|
|
%success = extractvalue { i32, i1 } %pair, 1
|
|
|
|
; CHECK-NEXT: BB#0:
|
|
; CHECK-NEXT: ldrex [[LOADED:r[0-9]+]], [r1]
|
|
; CHECK-NEXT: cmp [[LOADED]], r2
|
|
; CHECK-NEXT: bne [[LDFAILBB:LBB[0-9]+_[0-9]+]]
|
|
; CHECK-NEXT: BB#1:
|
|
; CHECK-NEXT: dmb ish
|
|
; CHECK-NEXT: mov r0, #0
|
|
; CHECK-NEXT: strex [[SUCCESS:r[0-9]+]], r3, [r1]
|
|
; CHECK-NEXT: cmp [[SUCCESS]], #0
|
|
; CHECK-NEXT: bxne lr
|
|
; CHECK-NEXT: dmb ish
|
|
; CHECK-NEXT: mov r0, #1
|
|
; CHECK-NEXT: bx lr
|
|
; CHECK-NEXT: [[LDFAILBB]]:
|
|
; CHECK-NEXT: clrex
|
|
; CHECK-NEXT: mov r0, #0
|
|
; CHECK-NEXT: bx lr
|
|
|
|
ret i1 %success
|
|
}
|