xref: /minix3/external/bsd/llvm/dist/llvm/test/CodeGen/SystemZ/atomicrmw-add-02.ll (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc; Test 16-bit atomic additions.
2*f4a2713aSLionel Sambuc;
3*f4a2713aSLionel Sambuc; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s -check-prefix=CHECK
4*f4a2713aSLionel Sambuc; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s -check-prefix=CHECK-SHIFT1
5*f4a2713aSLionel Sambuc; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s -check-prefix=CHECK-SHIFT2
6*f4a2713aSLionel Sambuc
7*f4a2713aSLionel Sambuc; Check addition of a variable.
8*f4a2713aSLionel Sambuc; - CHECK is for the main loop.
9*f4a2713aSLionel Sambuc; - CHECK-SHIFT1 makes sure that the negated shift count used by the second
10*f4a2713aSLionel Sambuc;   RLL is set up correctly.  The negation is independent of the NILL and L
11*f4a2713aSLionel Sambuc;   tested in CHECK.
12*f4a2713aSLionel Sambuc; - CHECK-SHIFT2 makes sure that %b is shifted into the high part of the word
13*f4a2713aSLionel Sambuc;   before being used.  This shift is independent of the other loop prologue
14*f4a2713aSLionel Sambuc;   instructions.
15*f4a2713aSLionel Sambucdefine i16 @f1(i16 *%src, i16 %b) {
16*f4a2713aSLionel Sambuc; CHECK-LABEL: f1:
17*f4a2713aSLionel Sambuc; CHECK: sllg [[SHIFT:%r[1-9]+]], %r2, 3
18*f4a2713aSLionel Sambuc; CHECK: nill %r2, 65532
19*f4a2713aSLionel Sambuc; CHECK: l [[OLD:%r[0-9]+]], 0(%r2)
20*f4a2713aSLionel Sambuc; CHECK: [[LABEL:\.[^:]*]]:
21*f4a2713aSLionel Sambuc; CHECK: rll [[ROT:%r[0-9]+]], [[OLD]], 0([[SHIFT]])
22*f4a2713aSLionel Sambuc; CHECK: ar [[ROT]], %r3
23*f4a2713aSLionel Sambuc; CHECK: rll [[NEW:%r[0-9]+]], [[ROT]], 0({{%r[1-9]+}})
24*f4a2713aSLionel Sambuc; CHECK: cs [[OLD]], [[NEW]], 0(%r2)
25*f4a2713aSLionel Sambuc; CHECK: jl [[LABEL]]
26*f4a2713aSLionel Sambuc; CHECK: rll %r2, [[OLD]], 16([[SHIFT]])
27*f4a2713aSLionel Sambuc; CHECK: br %r14
28*f4a2713aSLionel Sambuc;
29*f4a2713aSLionel Sambuc; CHECK-SHIFT1-LABEL: f1:
30*f4a2713aSLionel Sambuc; CHECK-SHIFT1: sllg [[SHIFT:%r[1-9]+]], %r2, 3
31*f4a2713aSLionel Sambuc; CHECK-SHIFT1: lcr [[NEGSHIFT:%r[1-9]+]], [[SHIFT]]
32*f4a2713aSLionel Sambuc; CHECK-SHIFT1: rll
33*f4a2713aSLionel Sambuc; CHECK-SHIFT1: rll {{%r[0-9]+}}, {{%r[0-9]+}}, 0([[NEGSHIFT]])
34*f4a2713aSLionel Sambuc; CHECK-SHIFT1: rll
35*f4a2713aSLionel Sambuc; CHECK-SHIFT1: br %r14
36*f4a2713aSLionel Sambuc;
37*f4a2713aSLionel Sambuc; CHECK-SHIFT2-LABEL: f1:
38*f4a2713aSLionel Sambuc; CHECK-SHIFT2: sll %r3, 16
39*f4a2713aSLionel Sambuc; CHECK-SHIFT2: rll
40*f4a2713aSLionel Sambuc; CHECK-SHIFT2: ar {{%r[0-9]+}}, %r3
41*f4a2713aSLionel Sambuc; CHECK-SHIFT2: rll
42*f4a2713aSLionel Sambuc; CHECK-SHIFT2: rll
43*f4a2713aSLionel Sambuc; CHECK-SHIFT2: br %r14
44*f4a2713aSLionel Sambuc  %res = atomicrmw add i16 *%src, i16 %b seq_cst
45*f4a2713aSLionel Sambuc  ret i16 %res
46*f4a2713aSLionel Sambuc}
47*f4a2713aSLionel Sambuc
48*f4a2713aSLionel Sambuc; Check the minimum signed value.  We add 0x80000000 to the rotated word.
49*f4a2713aSLionel Sambucdefine i16 @f2(i16 *%src) {
50*f4a2713aSLionel Sambuc; CHECK-LABEL: f2:
51*f4a2713aSLionel Sambuc; CHECK: sllg [[SHIFT:%r[1-9]+]], %r2, 3
52*f4a2713aSLionel Sambuc; CHECK: nill %r2, 65532
53*f4a2713aSLionel Sambuc; CHECK: l [[OLD:%r[0-9]+]], 0(%r2)
54*f4a2713aSLionel Sambuc; CHECK: [[LABEL:\.[^:]*]]:
55*f4a2713aSLionel Sambuc; CHECK: rll [[ROT:%r[0-9]+]], [[OLD]], 0([[SHIFT]])
56*f4a2713aSLionel Sambuc; CHECK: afi [[ROT]], -2147483648
57*f4a2713aSLionel Sambuc; CHECK: rll [[NEW:%r[0-9]+]], [[ROT]], 0([[NEGSHIFT:%r[1-9]+]])
58*f4a2713aSLionel Sambuc; CHECK: cs [[OLD]], [[NEW]], 0(%r2)
59*f4a2713aSLionel Sambuc; CHECK: jl [[LABEL]]
60*f4a2713aSLionel Sambuc; CHECK: rll %r2, [[OLD]], 16([[SHIFT]])
61*f4a2713aSLionel Sambuc; CHECK: br %r14
62*f4a2713aSLionel Sambuc;
63*f4a2713aSLionel Sambuc; CHECK-SHIFT1-LABEL: f2:
64*f4a2713aSLionel Sambuc; CHECK-SHIFT1: sllg [[SHIFT:%r[1-9]+]], %r2, 3
65*f4a2713aSLionel Sambuc; CHECK-SHIFT1: lcr [[NEGSHIFT:%r[1-9]+]], [[SHIFT]]
66*f4a2713aSLionel Sambuc; CHECK-SHIFT1: rll
67*f4a2713aSLionel Sambuc; CHECK-SHIFT1: rll {{%r[0-9]+}}, {{%r[0-9]+}}, 0([[NEGSHIFT]])
68*f4a2713aSLionel Sambuc; CHECK-SHIFT1: rll
69*f4a2713aSLionel Sambuc; CHECK-SHIFT1: br %r14
70*f4a2713aSLionel Sambuc;
71*f4a2713aSLionel Sambuc; CHECK-SHIFT2-LABEL: f2:
72*f4a2713aSLionel Sambuc; CHECK-SHIFT2: br %r14
73*f4a2713aSLionel Sambuc  %res = atomicrmw add i16 *%src, i16 -32768 seq_cst
74*f4a2713aSLionel Sambuc  ret i16 %res
75*f4a2713aSLionel Sambuc}
76*f4a2713aSLionel Sambuc
77*f4a2713aSLionel Sambuc; Check addition of -1.  We add 0xffff0000 to the rotated word.
78*f4a2713aSLionel Sambucdefine i16 @f3(i16 *%src) {
79*f4a2713aSLionel Sambuc; CHECK-LABEL: f3:
80*f4a2713aSLionel Sambuc; CHECK: afi [[ROT]], -65536
81*f4a2713aSLionel Sambuc; CHECK: br %r14
82*f4a2713aSLionel Sambuc;
83*f4a2713aSLionel Sambuc; CHECK-SHIFT1-LABEL: f3:
84*f4a2713aSLionel Sambuc; CHECK-SHIFT1: br %r14
85*f4a2713aSLionel Sambuc; CHECK-SHIFT2-LABEL: f3:
86*f4a2713aSLionel Sambuc; CHECK-SHIFT2: br %r14
87*f4a2713aSLionel Sambuc  %res = atomicrmw add i16 *%src, i16 -1 seq_cst
88*f4a2713aSLionel Sambuc  ret i16 %res
89*f4a2713aSLionel Sambuc}
90*f4a2713aSLionel Sambuc
91*f4a2713aSLionel Sambuc; Check addition of 1.  We add 0x00010000 to the rotated word.
92*f4a2713aSLionel Sambucdefine i16 @f4(i16 *%src) {
93*f4a2713aSLionel Sambuc; CHECK-LABEL: f4:
94*f4a2713aSLionel Sambuc; CHECK: afi [[ROT]], 65536
95*f4a2713aSLionel Sambuc; CHECK: br %r14
96*f4a2713aSLionel Sambuc;
97*f4a2713aSLionel Sambuc; CHECK-SHIFT1-LABEL: f4:
98*f4a2713aSLionel Sambuc; CHECK-SHIFT1: br %r14
99*f4a2713aSLionel Sambuc; CHECK-SHIFT2-LABEL: f4:
100*f4a2713aSLionel Sambuc; CHECK-SHIFT2: br %r14
101*f4a2713aSLionel Sambuc  %res = atomicrmw add i16 *%src, i16 1 seq_cst
102*f4a2713aSLionel Sambuc  ret i16 %res
103*f4a2713aSLionel Sambuc}
104*f4a2713aSLionel Sambuc
105*f4a2713aSLionel Sambuc; Check the maximum signed value.  We add 0x7fff0000 to the rotated word.
106*f4a2713aSLionel Sambucdefine i16 @f5(i16 *%src) {
107*f4a2713aSLionel Sambuc; CHECK-LABEL: f5:
108*f4a2713aSLionel Sambuc; CHECK: afi [[ROT]], 2147418112
109*f4a2713aSLionel Sambuc; CHECK: br %r14
110*f4a2713aSLionel Sambuc;
111*f4a2713aSLionel Sambuc; CHECK-SHIFT1-LABEL: f5:
112*f4a2713aSLionel Sambuc; CHECK-SHIFT1: br %r14
113*f4a2713aSLionel Sambuc; CHECK-SHIFT2-LABEL: f5:
114*f4a2713aSLionel Sambuc; CHECK-SHIFT2: br %r14
115*f4a2713aSLionel Sambuc  %res = atomicrmw add i16 *%src, i16 32767 seq_cst
116*f4a2713aSLionel Sambuc  ret i16 %res
117*f4a2713aSLionel Sambuc}
118*f4a2713aSLionel Sambuc
119*f4a2713aSLionel Sambuc; Check addition of a large unsigned value.  We add 0xfffe0000 to the
120*f4a2713aSLionel Sambuc; rotated word, expressed as a negative AFI operand.
121*f4a2713aSLionel Sambucdefine i16 @f6(i16 *%src) {
122*f4a2713aSLionel Sambuc; CHECK-LABEL: f6:
123*f4a2713aSLionel Sambuc; CHECK: afi [[ROT]], -131072
124*f4a2713aSLionel Sambuc; CHECK: br %r14
125*f4a2713aSLionel Sambuc;
126*f4a2713aSLionel Sambuc; CHECK-SHIFT1-LABEL: f6:
127*f4a2713aSLionel Sambuc; CHECK-SHIFT1: br %r14
128*f4a2713aSLionel Sambuc; CHECK-SHIFT2-LABEL: f6:
129*f4a2713aSLionel Sambuc; CHECK-SHIFT2: br %r14
130*f4a2713aSLionel Sambuc  %res = atomicrmw add i16 *%src, i16 65534 seq_cst
131*f4a2713aSLionel Sambuc  ret i16 %res
132*f4a2713aSLionel Sambuc}
133