2014-04-16 03:08:46 +08:00
|
|
|
; RUN: llc < %s -march=arm64 -mtriple=arm64-linux-gnu -verify-machineinstrs -mcpu=cyclone | FileCheck %s
|
2014-03-29 18:18:08 +08:00
|
|
|
|
|
|
|
@var = global i128 0
|
|
|
|
|
|
|
|
define i128 @val_compare_and_swap(i128* %p, i128 %oldval, i128 %newval) {
|
|
|
|
; CHECK-LABEL: val_compare_and_swap:
|
|
|
|
; CHECK: [[LABEL:.?LBB[0-9]+_[0-9]+]]:
|
2014-04-18 04:00:33 +08:00
|
|
|
; CHECK: ldaxp [[RESULTLO:x[0-9]+]], [[RESULTHI:x[0-9]+]], [x[[ADDR:[0-9]+]]]
|
|
|
|
; CHECK-DAG: eor [[MISMATCH_LO:x[0-9]+]], [[RESULTLO]], x2
|
|
|
|
; CHECK-DAG: eor [[MISMATCH_HI:x[0-9]+]], [[RESULTHI]], x3
|
|
|
|
; CHECK: orr [[MISMATCH:x[0-9]+]], [[MISMATCH_LO]], [[MISMATCH_HI]]
|
|
|
|
; CHECK: cbnz [[MISMATCH]], [[DONE:.LBB[0-9]+_[0-9]+]]
|
|
|
|
; CHECK: stxp [[SCRATCH_RES:w[0-9]+]], x4, x5, [x[[ADDR]]]
|
2014-03-29 18:18:08 +08:00
|
|
|
; CHECK: cbnz [[SCRATCH_RES]], [[LABEL]]
|
2014-04-18 04:00:33 +08:00
|
|
|
; CHECK: [[DONE]]:
|
IR: add "cmpxchg weak" variant to support permitted failure.
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
2014-06-13 22:24:07 +08:00
|
|
|
%pair = cmpxchg i128* %p, i128 %oldval, i128 %newval acquire acquire
|
|
|
|
%val = extractvalue { i128, i1 } %pair, 0
|
2014-03-29 18:18:08 +08:00
|
|
|
ret i128 %val
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @fetch_and_nand(i128* %p, i128 %bits) {
|
|
|
|
; CHECK-LABEL: fetch_and_nand:
|
|
|
|
; CHECK: [[LABEL:.?LBB[0-9]+_[0-9]+]]:
|
|
|
|
; CHECK: ldxp [[DEST_REGLO:x[0-9]+]], [[DEST_REGHI:x[0-9]+]], [x0]
|
2014-07-07 17:06:35 +08:00
|
|
|
; CHECK-DAG: and [[TMP_REGLO:x[0-9]+]], [[DEST_REGLO]], x2
|
|
|
|
; CHECK-DAG: and [[TMP_REGHI:x[0-9]+]], [[DEST_REGHI]], x3
|
|
|
|
; CHECK-DAG: mvn [[SCRATCH_REGLO:x[0-9]+]], [[TMP_REGLO]]
|
|
|
|
; CHECK-DAG: mvn [[SCRATCH_REGHI:x[0-9]+]], [[TMP_REGHI]]
|
2014-03-29 18:18:08 +08:00
|
|
|
; CHECK: stlxp [[SCRATCH_RES:w[0-9]+]], [[SCRATCH_REGLO]], [[SCRATCH_REGHI]], [x0]
|
|
|
|
; CHECK: cbnz [[SCRATCH_RES]], [[LABEL]]
|
|
|
|
|
2014-12-03 07:13:39 +08:00
|
|
|
; CHECK-DAG: stp [[DEST_REGLO]], [[DEST_REGHI]]
|
2014-03-29 18:18:08 +08:00
|
|
|
%val = atomicrmw nand i128* %p, i128 %bits release
|
|
|
|
store i128 %val, i128* @var, align 16
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @fetch_and_or(i128* %p, i128 %bits) {
|
|
|
|
; CHECK-LABEL: fetch_and_or:
|
|
|
|
; CHECK: [[LABEL:.?LBB[0-9]+_[0-9]+]]:
|
|
|
|
; CHECK: ldaxp [[DEST_REGLO:x[0-9]+]], [[DEST_REGHI:x[0-9]+]], [x0]
|
2014-04-18 04:00:33 +08:00
|
|
|
; CHECK-DAG: orr [[SCRATCH_REGLO:x[0-9]+]], [[DEST_REGLO]], x2
|
|
|
|
; CHECK-DAG: orr [[SCRATCH_REGHI:x[0-9]+]], [[DEST_REGHI]], x3
|
2014-03-29 18:18:08 +08:00
|
|
|
; CHECK: stlxp [[SCRATCH_RES:w[0-9]+]], [[SCRATCH_REGLO]], [[SCRATCH_REGHI]], [x0]
|
|
|
|
; CHECK: cbnz [[SCRATCH_RES]], [[LABEL]]
|
|
|
|
|
2014-12-03 07:13:39 +08:00
|
|
|
; CHECK-DAG: stp [[DEST_REGLO]], [[DEST_REGHI]]
|
2014-03-29 18:18:08 +08:00
|
|
|
%val = atomicrmw or i128* %p, i128 %bits seq_cst
|
|
|
|
store i128 %val, i128* @var, align 16
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @fetch_and_add(i128* %p, i128 %bits) {
|
|
|
|
; CHECK-LABEL: fetch_and_add:
|
|
|
|
; CHECK: [[LABEL:.?LBB[0-9]+_[0-9]+]]:
|
|
|
|
; CHECK: ldaxp [[DEST_REGLO:x[0-9]+]], [[DEST_REGHI:x[0-9]+]], [x0]
|
|
|
|
; CHECK: adds [[SCRATCH_REGLO:x[0-9]+]], [[DEST_REGLO]], x2
|
2014-04-18 04:00:33 +08:00
|
|
|
; CHECK: adcs [[SCRATCH_REGHI:x[0-9]+]], [[DEST_REGHI]], x3
|
2014-03-29 18:18:08 +08:00
|
|
|
; CHECK: stlxp [[SCRATCH_RES:w[0-9]+]], [[SCRATCH_REGLO]], [[SCRATCH_REGHI]], [x0]
|
|
|
|
; CHECK: cbnz [[SCRATCH_RES]], [[LABEL]]
|
|
|
|
|
2014-12-03 07:13:39 +08:00
|
|
|
; CHECK-DAG: stp [[DEST_REGLO]], [[DEST_REGHI]]
|
2014-03-29 18:18:08 +08:00
|
|
|
%val = atomicrmw add i128* %p, i128 %bits seq_cst
|
|
|
|
store i128 %val, i128* @var, align 16
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @fetch_and_sub(i128* %p, i128 %bits) {
|
|
|
|
; CHECK-LABEL: fetch_and_sub:
|
|
|
|
; CHECK: [[LABEL:.?LBB[0-9]+_[0-9]+]]:
|
|
|
|
; CHECK: ldaxp [[DEST_REGLO:x[0-9]+]], [[DEST_REGHI:x[0-9]+]], [x0]
|
|
|
|
; CHECK: subs [[SCRATCH_REGLO:x[0-9]+]], [[DEST_REGLO]], x2
|
2014-04-18 04:00:33 +08:00
|
|
|
; CHECK: sbcs [[SCRATCH_REGHI:x[0-9]+]], [[DEST_REGHI]], x3
|
2014-03-29 18:18:08 +08:00
|
|
|
; CHECK: stlxp [[SCRATCH_RES:w[0-9]+]], [[SCRATCH_REGLO]], [[SCRATCH_REGHI]], [x0]
|
|
|
|
; CHECK: cbnz [[SCRATCH_RES]], [[LABEL]]
|
|
|
|
|
2014-12-03 07:13:39 +08:00
|
|
|
; CHECK-DAG: stp [[DEST_REGLO]], [[DEST_REGHI]]
|
2014-03-29 18:18:08 +08:00
|
|
|
%val = atomicrmw sub i128* %p, i128 %bits seq_cst
|
|
|
|
store i128 %val, i128* @var, align 16
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @fetch_and_min(i128* %p, i128 %bits) {
|
|
|
|
; CHECK-LABEL: fetch_and_min:
|
|
|
|
; CHECK: [[LABEL:.?LBB[0-9]+_[0-9]+]]:
|
2014-04-18 04:00:33 +08:00
|
|
|
; CHECK: ldaxp [[DEST_REGLO:x[0-9]+]], [[DEST_REGHI:x[0-9]+]], [x0]
|
|
|
|
; CHECK: cmp [[DEST_REGLO]], x2
|
2014-05-13 02:04:06 +08:00
|
|
|
; CHECK: cset [[LOCMP:w[0-9]+]], ls
|
2014-04-18 04:00:33 +08:00
|
|
|
; CHECK: cmp [[DEST_REGHI:x[0-9]+]], x3
|
2014-05-13 02:04:06 +08:00
|
|
|
; CHECK: cset [[HICMP:w[0-9]+]], le
|
2014-04-18 04:00:33 +08:00
|
|
|
; CHECK: csel [[CMP:w[0-9]+]], [[LOCMP]], [[HICMP]], eq
|
|
|
|
; CHECK: cmp [[CMP]], #0
|
|
|
|
; CHECK-DAG: csel [[SCRATCH_REGHI:x[0-9]+]], [[DEST_REGHI]], x3, ne
|
|
|
|
; CHECK-DAG: csel [[SCRATCH_REGLO:x[0-9]+]], [[DEST_REGLO]], x2, ne
|
2014-03-29 18:18:08 +08:00
|
|
|
; CHECK: stlxp [[SCRATCH_RES:w[0-9]+]], [[SCRATCH_REGLO]], [[SCRATCH_REGHI]], [x0]
|
|
|
|
; CHECK: cbnz [[SCRATCH_RES]], [[LABEL]]
|
|
|
|
|
2014-12-03 07:13:39 +08:00
|
|
|
; CHECK-DAG: stp [[DEST_REGLO]], [[DEST_REGHI]]
|
2014-03-29 18:18:08 +08:00
|
|
|
%val = atomicrmw min i128* %p, i128 %bits seq_cst
|
|
|
|
store i128 %val, i128* @var, align 16
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @fetch_and_max(i128* %p, i128 %bits) {
|
|
|
|
; CHECK-LABEL: fetch_and_max:
|
|
|
|
; CHECK: [[LABEL:.?LBB[0-9]+_[0-9]+]]:
|
|
|
|
; CHECK: ldaxp [[DEST_REGLO:x[0-9]+]], [[DEST_REGHI:x[0-9]+]], [x0]
|
2014-04-18 04:00:33 +08:00
|
|
|
; CHECK: cmp [[DEST_REGLO]], x2
|
2014-05-13 02:04:06 +08:00
|
|
|
; CHECK: cset [[LOCMP:w[0-9]+]], hi
|
2014-04-18 04:00:33 +08:00
|
|
|
; CHECK: cmp [[DEST_REGHI:x[0-9]+]], x3
|
2014-05-13 02:04:06 +08:00
|
|
|
; CHECK: cset [[HICMP:w[0-9]+]], gt
|
2014-04-18 04:00:33 +08:00
|
|
|
; CHECK: csel [[CMP:w[0-9]+]], [[LOCMP]], [[HICMP]], eq
|
|
|
|
; CHECK: cmp [[CMP]], #0
|
|
|
|
; CHECK-DAG: csel [[SCRATCH_REGHI:x[0-9]+]], [[DEST_REGHI]], x3, ne
|
|
|
|
; CHECK-DAG: csel [[SCRATCH_REGLO:x[0-9]+]], [[DEST_REGLO]], x2, ne
|
2014-03-29 18:18:08 +08:00
|
|
|
; CHECK: stlxp [[SCRATCH_RES:w[0-9]+]], [[SCRATCH_REGLO]], [[SCRATCH_REGHI]], [x0]
|
|
|
|
; CHECK: cbnz [[SCRATCH_RES]], [[LABEL]]
|
|
|
|
|
2014-12-03 07:13:39 +08:00
|
|
|
; CHECK-DAG: stp [[DEST_REGLO]], [[DEST_REGHI]]
|
2014-03-29 18:18:08 +08:00
|
|
|
%val = atomicrmw max i128* %p, i128 %bits seq_cst
|
|
|
|
store i128 %val, i128* @var, align 16
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @fetch_and_umin(i128* %p, i128 %bits) {
|
|
|
|
; CHECK-LABEL: fetch_and_umin:
|
|
|
|
; CHECK: [[LABEL:.?LBB[0-9]+_[0-9]+]]:
|
|
|
|
; CHECK: ldaxp [[DEST_REGLO:x[0-9]+]], [[DEST_REGHI:x[0-9]+]], [x0]
|
2014-04-18 04:00:33 +08:00
|
|
|
; CHECK: cmp [[DEST_REGLO]], x2
|
2014-05-13 02:04:06 +08:00
|
|
|
; CHECK: cset [[LOCMP:w[0-9]+]], ls
|
2014-04-18 04:00:33 +08:00
|
|
|
; CHECK: cmp [[DEST_REGHI:x[0-9]+]], x3
|
2014-05-13 02:04:06 +08:00
|
|
|
; CHECK: cset [[HICMP:w[0-9]+]], ls
|
2014-04-18 04:00:33 +08:00
|
|
|
; CHECK: csel [[CMP:w[0-9]+]], [[LOCMP]], [[HICMP]], eq
|
|
|
|
; CHECK: cmp [[CMP]], #0
|
|
|
|
; CHECK-DAG: csel [[SCRATCH_REGHI:x[0-9]+]], [[DEST_REGHI]], x3, ne
|
|
|
|
; CHECK-DAG: csel [[SCRATCH_REGLO:x[0-9]+]], [[DEST_REGLO]], x2, ne
|
2014-03-29 18:18:08 +08:00
|
|
|
; CHECK: stlxp [[SCRATCH_RES:w[0-9]+]], [[SCRATCH_REGLO]], [[SCRATCH_REGHI]], [x0]
|
|
|
|
; CHECK: cbnz [[SCRATCH_RES]], [[LABEL]]
|
|
|
|
|
2014-12-03 07:13:39 +08:00
|
|
|
; CHECK-DAG: stp [[DEST_REGLO]], [[DEST_REGHI]]
|
2014-03-29 18:18:08 +08:00
|
|
|
%val = atomicrmw umin i128* %p, i128 %bits seq_cst
|
|
|
|
store i128 %val, i128* @var, align 16
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @fetch_and_umax(i128* %p, i128 %bits) {
|
|
|
|
; CHECK-LABEL: fetch_and_umax:
|
|
|
|
; CHECK: [[LABEL:.?LBB[0-9]+_[0-9]+]]:
|
|
|
|
; CHECK: ldaxp [[DEST_REGLO:x[0-9]+]], [[DEST_REGHI:x[0-9]+]], [x0]
|
2014-04-18 04:00:33 +08:00
|
|
|
; CHECK: cmp [[DEST_REGLO]], x2
|
2014-05-13 02:04:06 +08:00
|
|
|
; CHECK: cset [[LOCMP:w[0-9]+]], hi
|
2014-04-18 04:00:33 +08:00
|
|
|
; CHECK: cmp [[DEST_REGHI:x[0-9]+]], x3
|
2014-05-13 02:04:06 +08:00
|
|
|
; CHECK: cset [[HICMP:w[0-9]+]], hi
|
2014-04-18 04:00:33 +08:00
|
|
|
; CHECK: csel [[CMP:w[0-9]+]], [[LOCMP]], [[HICMP]], eq
|
|
|
|
; CHECK: cmp [[CMP]], #0
|
|
|
|
; CHECK-DAG: csel [[SCRATCH_REGHI:x[0-9]+]], [[DEST_REGHI]], x3, ne
|
|
|
|
; CHECK-DAG: csel [[SCRATCH_REGLO:x[0-9]+]], [[DEST_REGLO]], x2, ne
|
2014-03-29 18:18:08 +08:00
|
|
|
; CHECK: stlxp [[SCRATCH_RES:w[0-9]+]], [[SCRATCH_REGLO]], [[SCRATCH_REGHI]], [x0]
|
|
|
|
; CHECK: cbnz [[SCRATCH_RES]], [[LABEL]]
|
|
|
|
|
2014-12-03 07:13:39 +08:00
|
|
|
; CHECK-DAG: stp [[DEST_REGLO]], [[DEST_REGHI]]
|
2014-03-29 18:18:08 +08:00
|
|
|
%val = atomicrmw umax i128* %p, i128 %bits seq_cst
|
|
|
|
store i128 %val, i128* @var, align 16
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define i128 @atomic_load_seq_cst(i128* %p) {
|
|
|
|
; CHECK-LABEL: atomic_load_seq_cst:
|
|
|
|
; CHECK-NOT: dmb
|
|
|
|
; CHECK-LABEL: ldaxp
|
|
|
|
; CHECK-NOT: dmb
|
2015-02-28 05:17:42 +08:00
|
|
|
%r = load atomic i128, i128* %p seq_cst, align 16
|
2014-03-29 18:18:08 +08:00
|
|
|
ret i128 %r
|
|
|
|
}
|
|
|
|
|
2015-12-03 02:12:57 +08:00
|
|
|
define i128 @atomic_load_relaxed(i64, i64, i128* %p) {
|
2014-03-29 18:18:08 +08:00
|
|
|
; CHECK-LABEL: atomic_load_relaxed:
|
|
|
|
; CHECK-NOT: dmb
|
2015-12-03 02:12:57 +08:00
|
|
|
; CHECK: [[LABEL:.?LBB[0-9]+_[0-9]+]]:
|
|
|
|
; CHECK: ldxp [[LO:x[0-9]+]], [[HI:x[0-9]+]], [x2]
|
|
|
|
; CHECK-NEXT: stxp [[SUCCESS:w[0-9]+]], [[LO]], [[HI]], [x2]
|
|
|
|
; CHECK: cbnz [[SUCCESS]], [[LABEL]]
|
2014-03-29 18:18:08 +08:00
|
|
|
; CHECK-NOT: dmb
|
2015-02-28 05:17:42 +08:00
|
|
|
%r = load atomic i128, i128* %p monotonic, align 16
|
2014-03-29 18:18:08 +08:00
|
|
|
ret i128 %r
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
define void @atomic_store_seq_cst(i128 %in, i128* %p) {
|
|
|
|
; CHECK-LABEL: atomic_store_seq_cst:
|
|
|
|
; CHECK-NOT: dmb
|
|
|
|
; CHECK: [[LABEL:.?LBB[0-9]+_[0-9]+]]:
|
|
|
|
; CHECK: ldaxp xzr, xzr, [x2]
|
|
|
|
; CHECK: stlxp [[SUCCESS:w[0-9]+]], x0, x1, [x2]
|
|
|
|
; CHECK: cbnz [[SUCCESS]], [[LABEL]]
|
|
|
|
; CHECK-NOT: dmb
|
|
|
|
store atomic i128 %in, i128* %p seq_cst, align 16
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @atomic_store_release(i128 %in, i128* %p) {
|
|
|
|
; CHECK-LABEL: atomic_store_release:
|
|
|
|
; CHECK-NOT: dmb
|
|
|
|
; CHECK: [[LABEL:.?LBB[0-9]+_[0-9]+]]:
|
|
|
|
; CHECK: ldxp xzr, xzr, [x2]
|
|
|
|
; CHECK: stlxp [[SUCCESS:w[0-9]+]], x0, x1, [x2]
|
|
|
|
; CHECK: cbnz [[SUCCESS]], [[LABEL]]
|
|
|
|
; CHECK-NOT: dmb
|
|
|
|
store atomic i128 %in, i128* %p release, align 16
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @atomic_store_relaxed(i128 %in, i128* %p) {
|
|
|
|
; CHECK-LABEL: atomic_store_relaxed:
|
|
|
|
; CHECK-NOT: dmb
|
|
|
|
; CHECK: [[LABEL:.?LBB[0-9]+_[0-9]+]]:
|
|
|
|
; CHECK: ldxp xzr, xzr, [x2]
|
|
|
|
; CHECK: stxp [[SUCCESS:w[0-9]+]], x0, x1, [x2]
|
|
|
|
; CHECK: cbnz [[SUCCESS]], [[LABEL]]
|
|
|
|
; CHECK-NOT: dmb
|
|
|
|
store atomic i128 %in, i128* %p unordered, align 16
|
|
|
|
ret void
|
|
|
|
}
|