mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 04:02:41 +01:00
369e0e389f
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. llvm-svn: 261568
125 lines
2.9 KiB
LLVM
125 lines
2.9 KiB
LLVM
; RUN: llc -mtriple=thumbv7s-apple-ios7.0 -o - %s | FileCheck %s
|
|
|
|
define i32 @test_return(i32* %p, i32 %oldval, i32 %newval) {
|
|
; CHECK-LABEL: test_return:
|
|
|
|
; CHECK: ldrex [[LOADED:r[0-9]+]], [r0]
|
|
; CHECK: cmp [[LOADED]], r1
|
|
; CHECK: bne [[FAILED:LBB[0-9]+_[0-9]+]]
|
|
|
|
; CHECK: dmb ishst
|
|
|
|
; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]:
|
|
; CHECK: strex [[STATUS:r[0-9]+]], {{r[0-9]+}}, [r0]
|
|
; CHECK: cbz [[STATUS]], [[SUCCESS:LBB[0-9]+_[0-9]+]]
|
|
|
|
; CHECK: ldrex [[LOADED]], [r0]
|
|
; CHECK: cmp [[LOADED]], r1
|
|
; CHECK: beq [[LOOP]]
|
|
|
|
; CHECK: [[FAILED]]:
|
|
; CHECK-NOT: cmp {{r[0-9]+}}, {{r[0-9]+}}
|
|
; CHECK: clrex
|
|
; CHECK: dmb ish
|
|
; CHECK: movs r0, #0
|
|
; CHECK: bx lr
|
|
|
|
; CHECK: [[SUCCESS]]:
|
|
; CHECK-NOT: cmp {{r[0-9]+}}, {{r[0-9]+}}
|
|
; CHECK: dmb ish
|
|
; CHECK: movs r0, #1
|
|
; CHECK: bx lr
|
|
|
|
%pair = cmpxchg i32* %p, i32 %oldval, i32 %newval seq_cst seq_cst
|
|
%success = extractvalue { i32, i1 } %pair, 1
|
|
%conv = zext i1 %success to i32
|
|
ret i32 %conv
|
|
}
|
|
|
|
define i1 @test_return_bool(i8* %value, i8 %oldValue, i8 %newValue) {
|
|
; CHECK-LABEL: test_return_bool:
|
|
|
|
; CHECK: uxtb [[OLDBYTE:r[0-9]+]], r1
|
|
|
|
; CHECK: ldrexb [[LOADED:r[0-9]+]], [r0]
|
|
; CHECK: cmp [[LOADED]], [[OLDBYTE]]
|
|
; CHECK: bne [[FAIL:LBB[0-9]+_[0-9]+]]
|
|
|
|
; CHECK: dmb ishst
|
|
|
|
; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]:
|
|
; CHECK: strexb [[STATUS:r[0-9]+]], {{r[0-9]+}}, [r0]
|
|
; CHECK: cbz [[STATUS]], [[SUCCESS:LBB[0-9]+_[0-9]+]]
|
|
|
|
; CHECK: ldrexb [[LOADED]], [r0]
|
|
; CHECK: cmp [[LOADED]], [[OLDBYTE]]
|
|
; CHECK: beq [[LOOP]]
|
|
|
|
|
|
; FIXME: this eor is redundant. Need to teach DAG combine that.
|
|
; CHECK: [[FAIL]]:
|
|
; CHECK: clrex
|
|
; CHECK: movs [[TMP:r[0-9]+]], #0
|
|
; CHECK: eor r0, [[TMP]], #1
|
|
; CHECK: bx lr
|
|
|
|
; CHECK: [[SUCCESS]]:
|
|
; CHECK-NOT: cmp {{r[0-9]+}}, {{r[0-9]+}}
|
|
; CHECK: movs [[TMP:r[0-9]+]], #1
|
|
; CHECK: eor r0, [[TMP]], #1
|
|
; CHECK: bx lr
|
|
|
|
|
|
%pair = cmpxchg i8* %value, i8 %oldValue, i8 %newValue acq_rel monotonic
|
|
%success = extractvalue { i8, i1 } %pair, 1
|
|
%failure = xor i1 %success, 1
|
|
ret i1 %failure
|
|
}
|
|
|
|
define void @test_conditional(i32* %p, i32 %oldval, i32 %newval) {
|
|
; CHECK-LABEL: test_conditional:
|
|
|
|
; CHECK: ldrex [[LOADED:r[0-9]+]], [r0]
|
|
; CHECK: cmp [[LOADED]], r1
|
|
; CHECK: bne [[FAILED:LBB[0-9]+_[0-9]+]]
|
|
|
|
; CHECK: dmb ishst
|
|
|
|
; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]:
|
|
; CHECK: strex [[STATUS:r[0-9]+]], r2, [r0]
|
|
; CHECK: cbz [[STATUS]], [[SUCCESS:LBB[0-9]+_[0-9]+]]
|
|
|
|
; CHECK: ldrex [[LOADED]], [r0]
|
|
; CHECK: cmp [[LOADED]], r1
|
|
; CHECK: beq [[LOOP]]
|
|
|
|
; CHECK: [[FAILED]]:
|
|
; CHECK-NOT: cmp {{r[0-9]+}}, {{r[0-9]+}}
|
|
; CHECK: clrex
|
|
; CHECK: dmb ish
|
|
; CHECK: b.w _baz
|
|
|
|
; CHECK: [[SUCCESS]]:
|
|
; CHECK-NOT: cmp {{r[0-9]+}}, {{r[0-9]+}}
|
|
; CHECK: dmb ish
|
|
; CHECK: b.w _bar
|
|
|
|
%pair = cmpxchg i32* %p, i32 %oldval, i32 %newval seq_cst seq_cst
|
|
%success = extractvalue { i32, i1 } %pair, 1
|
|
br i1 %success, label %true, label %false
|
|
|
|
true:
|
|
tail call void @bar() #2
|
|
br label %end
|
|
|
|
false:
|
|
tail call void @baz() #2
|
|
br label %end
|
|
|
|
end:
|
|
ret void
|
|
}
|
|
|
|
declare void @bar()
|
|
declare void @baz()
|