blob: 78165bde156b138287c0d444f9b55aee2c0a8869 [file] [log] [blame]
Ulrich Weigand9e3577f2013-05-06 16:17:29 +00001; Test 32-bit atomic exchange.
2;
3; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
4
5; Check register exchange.
6define i32 @f1(i32 %dummy, i32 *%src, i32 %b) {
Stephen Lind24ab202013-07-14 06:24:09 +00007; CHECK-LABEL: f1:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +00008; CHECK: l %r2, 0(%r3)
9; CHECK: [[LABEL:\.[^:]*]]:
10; CHECK: cs %r2, %r4, 0(%r3)
Richard Sandiford3d768e32013-07-31 12:30:20 +000011; CHECK: jl [[LABEL]]
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000012; CHECK: br %r14
13 %res = atomicrmw xchg i32 *%src, i32 %b seq_cst
14 ret i32 %res
15}
16
17; Check the high end of the aligned CS range.
18define i32 @f2(i32 %dummy, i32 *%src, i32 %b) {
Stephen Lind24ab202013-07-14 06:24:09 +000019; CHECK-LABEL: f2:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000020; CHECK: l %r2, 4092(%r3)
21; CHECK: cs %r2, {{%r[0-9]+}}, 4092(%r3)
22; CHECK: br %r14
David Blaikie79e6c742015-02-27 19:29:02 +000023 %ptr = getelementptr i32, i32 *%src, i64 1023
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000024 %res = atomicrmw xchg i32 *%ptr, i32 %b seq_cst
25 ret i32 %res
26}
27
28; Check the next word up, which requires CSY.
29define i32 @f3(i32 %dummy, i32 *%src, i32 %b) {
Stephen Lind24ab202013-07-14 06:24:09 +000030; CHECK-LABEL: f3:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000031; CHECK: ly %r2, 4096(%r3)
32; CHECK: csy %r2, {{%r[0-9]+}}, 4096(%r3)
33; CHECK: br %r14
David Blaikie79e6c742015-02-27 19:29:02 +000034 %ptr = getelementptr i32, i32 *%src, i64 1024
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000035 %res = atomicrmw xchg i32 *%ptr, i32 %b seq_cst
36 ret i32 %res
37}
38
39; Check the high end of the aligned CSY range.
40define i32 @f4(i32 %dummy, i32 *%src, i32 %b) {
Stephen Lind24ab202013-07-14 06:24:09 +000041; CHECK-LABEL: f4:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000042; CHECK: ly %r2, 524284(%r3)
43; CHECK: csy %r2, {{%r[0-9]+}}, 524284(%r3)
44; CHECK: br %r14
David Blaikie79e6c742015-02-27 19:29:02 +000045 %ptr = getelementptr i32, i32 *%src, i64 131071
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000046 %res = atomicrmw xchg i32 *%ptr, i32 %b seq_cst
47 ret i32 %res
48}
49
50; Check the next word up, which needs separate address logic.
51define i32 @f5(i32 %dummy, i32 *%src, i32 %b) {
Stephen Lind24ab202013-07-14 06:24:09 +000052; CHECK-LABEL: f5:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000053; CHECK: agfi %r3, 524288
54; CHECK: l %r2, 0(%r3)
55; CHECK: cs %r2, {{%r[0-9]+}}, 0(%r3)
56; CHECK: br %r14
David Blaikie79e6c742015-02-27 19:29:02 +000057 %ptr = getelementptr i32, i32 *%src, i64 131072
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000058 %res = atomicrmw xchg i32 *%ptr, i32 %b seq_cst
59 ret i32 %res
60}
61
62; Check the high end of the negative aligned CSY range.
63define i32 @f6(i32 %dummy, i32 *%src, i32 %b) {
Stephen Lind24ab202013-07-14 06:24:09 +000064; CHECK-LABEL: f6:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000065; CHECK: ly %r2, -4(%r3)
66; CHECK: csy %r2, {{%r[0-9]+}}, -4(%r3)
67; CHECK: br %r14
David Blaikie79e6c742015-02-27 19:29:02 +000068 %ptr = getelementptr i32, i32 *%src, i64 -1
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000069 %res = atomicrmw xchg i32 *%ptr, i32 %b seq_cst
70 ret i32 %res
71}
72
73; Check the low end of the CSY range.
74define i32 @f7(i32 %dummy, i32 *%src, i32 %b) {
Stephen Lind24ab202013-07-14 06:24:09 +000075; CHECK-LABEL: f7:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000076; CHECK: ly %r2, -524288(%r3)
77; CHECK: csy %r2, {{%r[0-9]+}}, -524288(%r3)
78; CHECK: br %r14
David Blaikie79e6c742015-02-27 19:29:02 +000079 %ptr = getelementptr i32, i32 *%src, i64 -131072
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000080 %res = atomicrmw xchg i32 *%ptr, i32 %b seq_cst
81 ret i32 %res
82}
83
84; Check the next word down, which needs separate address logic.
85define i32 @f8(i32 %dummy, i32 *%src, i32 %b) {
Stephen Lind24ab202013-07-14 06:24:09 +000086; CHECK-LABEL: f8:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000087; CHECK: agfi %r3, -524292
88; CHECK: l %r2, 0(%r3)
89; CHECK: cs %r2, {{%r[0-9]+}}, 0(%r3)
90; CHECK: br %r14
David Blaikie79e6c742015-02-27 19:29:02 +000091 %ptr = getelementptr i32, i32 *%src, i64 -131073
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000092 %res = atomicrmw xchg i32 *%ptr, i32 %b seq_cst
93 ret i32 %res
94}
95
96; Check that indexed addresses are not allowed.
97define i32 @f9(i32 %dummy, i64 %base, i64 %index, i32 %b) {
Stephen Lind24ab202013-07-14 06:24:09 +000098; CHECK-LABEL: f9:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000099; CHECK: agr %r3, %r4
100; CHECK: l %r2, 0(%r3)
101; CHECK: cs %r2, {{%r[0-9]+}}, 0(%r3)
102; CHECK: br %r14
103 %add = add i64 %base, %index
104 %ptr = inttoptr i64 %add to i32 *
105 %res = atomicrmw xchg i32 *%ptr, i32 %b seq_cst
106 ret i32 %res
107}
108
109; Check exchange of a constant. We should force it into a register and
110; use the sequence above.
111define i32 @f10(i32 %dummy, i32 *%src) {
Stephen Lind24ab202013-07-14 06:24:09 +0000112; CHECK-LABEL: f10:
Jonas Paulssonc63ed222017-10-06 13:59:28 +0000113; CHECK-DAG: llill [[VALUE:%r[0-9+]]], 40000
114; CHECK-DAG: l %r2, 0(%r3)
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000115; CHECK: [[LABEL:\.[^:]*]]:
116; CHECK: cs %r2, [[VALUE]], 0(%r3)
Richard Sandiford3d768e32013-07-31 12:30:20 +0000117; CHECK: jl [[LABEL]]
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000118; CHECK: br %r14
119 %res = atomicrmw xchg i32 *%src, i32 40000 seq_cst
120 ret i32 %res
121}
122