mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 03:33:20 +01:00
b9ec29d7c5
This commit adds a weak variant of the cmpxchg operation, as described in C++11. A cmpxchg instruction with this modifier is permitted to fail to store, even if the comparison indicated it should. As a result, cmpxchg instructions must return a flag indicating success in addition to their original iN value loaded. Thus, for uniformity *all* cmpxchg instructions now return "{ iN, i1 }". The second flag is 1 when the store succeeded. At the DAG level, a new ATOMIC_CMP_SWAP_WITH_SUCCESS node has been added as the natural representation for the new cmpxchg instructions. It is a strong cmpxchg. By default this gets Expanded to the existing ATOMIC_CMP_SWAP during Legalization, so existing backends should see no change in behaviour. If they wish to deal with the enhanced node instead, they can call setOperationAction on it. Beware: as a node with 2 results, it cannot be selected from TableGen. Currently, no use is made of the extra information provided in this patch. Test updates are almost entirely adapting the input IR to the new scheme. Summary for out of tree users: ------------------------------ + Legacy Bitcode files are upgraded during read. + Legacy assembly IR files will be invalid. + Front-ends must adapt to different type for "cmpxchg". + Backends should be unaffected by default. llvm-svn: 210903
108 lines
2.5 KiB
LLVM
108 lines
2.5 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: dmb ishst
|
|
|
|
; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]:
|
|
; CHECK: ldrex [[LOADED:r[0-9]+]], [r0]
|
|
; CHECK: cmp [[LOADED]], r1
|
|
; CHECK: bne [[FAILED:LBB[0-9]+_[0-9]+]]
|
|
|
|
; CHECK: strex [[STATUS:r[0-9]+]], {{r[0-9]+}}, [r0]
|
|
; CHECK: cmp [[STATUS]], #0
|
|
; CHECK: bne [[LOOP]]
|
|
|
|
; CHECK-NOT: cmp {{r[0-9]+}}, {{r[0-9]+}}
|
|
; CHECK: movs r0, #1
|
|
; CHECK: dmb ish
|
|
; CHECK: bx lr
|
|
|
|
; CHECK: [[FAILED]]:
|
|
; CHECK-NOT: cmp {{r[0-9]+}}, {{r[0-9]+}}
|
|
; CHECK: movs r0, #0
|
|
; CHECK: dmb ish
|
|
; 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: dmb ishst
|
|
|
|
; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]:
|
|
; CHECK: ldrexb [[LOADED:r[0-9]+]], [r0]
|
|
; CHECK: cmp [[LOADED]], [[OLDBYTE]]
|
|
; CHECK: bne [[FAIL:LBB[0-9]+_[0-9]+]]
|
|
|
|
; CHECK: strexb [[STATUS:r[0-9]+]], {{r[0-9]+}}, [r0]
|
|
; CHECK: cmp [[STATUS]], #0
|
|
; CHECK: bne [[LOOP]]
|
|
|
|
; FIXME: this eor is redundant. Need to teach DAG combine that.
|
|
; CHECK-NOT: cmp {{r[0-9]+}}, {{r[0-9]+}}
|
|
; CHECK: movs [[TMP:r[0-9]+]], #1
|
|
; CHECK: eor r0, [[TMP]], #1
|
|
; CHECK: bx lr
|
|
|
|
; CHECK: [[FAIL]]:
|
|
; CHECK: movs [[TMP:r[0-9]+]], #0
|
|
; 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: dmb ishst
|
|
|
|
; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]:
|
|
; CHECK: ldrex [[LOADED:r[0-9]+]], [r0]
|
|
; CHECK: cmp [[LOADED]], r1
|
|
; CHECK: bne [[FAILED:LBB[0-9]+_[0-9]+]]
|
|
|
|
; CHECK: strex [[STATUS:r[0-9]+]], r2, [r0]
|
|
; CHECK: cmp [[STATUS]], #0
|
|
; CHECK: bne [[LOOP]]
|
|
|
|
; CHECK-NOT: cmp {{r[0-9]+}}, {{r[0-9]+}}
|
|
; CHECK: dmb ish
|
|
; CHECK: b.w _bar
|
|
|
|
; CHECK: [[FAILED]]:
|
|
; CHECK-NOT: cmp {{r[0-9]+}}, {{r[0-9]+}}
|
|
; CHECK: dmb ish
|
|
; CHECK: b.w _baz
|
|
|
|
%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()
|