blob: dfba8ba1933151f3357c468e1dc59e5ec96d027c [file] [log] [blame]
Daniel Sanders0d972702016-06-24 12:23:17 +00001; RUN: llc -march=mipsel --disable-machine-licm -mcpu=mips32 -relocation-model=pic < %s | \
2; RUN: FileCheck %s -check-prefixes=ALL,MIPS32-ANY,NO-SEB-SEH,CHECK-EL,NOT-MICROMIPS
3; RUN: llc -march=mipsel --disable-machine-licm -mcpu=mips32r2 -relocation-model=pic -verify-machineinstrs < %s | \
4; RUN: FileCheck %s -check-prefixes=ALL,MIPS32-ANY,HAS-SEB-SEH,CHECK-EL,NOT-MICROMIPS
5; RUN: llc -march=mipsel --disable-machine-licm -mcpu=mips32r6 -relocation-model=pic -verify-machineinstrs < %s | \
6; RUN: FileCheck %s -check-prefixes=ALL,MIPS32-ANY,HAS-SEB-SEH,CHECK-EL,MIPSR6
7; RUN: llc -march=mips64el --disable-machine-licm -mcpu=mips4 -relocation-model=pic < %s | \
8; RUN: FileCheck %s -check-prefixes=ALL,MIPS64-ANY,NO-SEB-SEH,CHECK-EL,NOT-MICROMIPS
9; RUN: llc -march=mips64el --disable-machine-licm -mcpu=mips64 -relocation-model=pic < %s | \
10; RUN: FileCheck %s -check-prefixes=ALL,MIPS64-ANY,NO-SEB-SEH,CHECK-EL,NOT-MICROMIPS
11; RUN: llc -march=mips64el --disable-machine-licm -mcpu=mips64r2 -relocation-model=pic -verify-machineinstrs < %s | \
12; RUN: FileCheck %s -check-prefixes=ALL,MIPS64-ANY,HAS-SEB-SEH,CHECK-EL,NOT-MICROMIPS
13; RUN: llc -march=mips64el --disable-machine-licm -mcpu=mips64r6 -relocation-model=pic < %s | \
14; RUN: FileCheck %s -check-prefixes=ALL,MIPS64-ANY,HAS-SEB-SEH,CHECK-EL,MIPSR6
15; RUN: llc -march=mips64 -O0 -mcpu=mips64r6 -relocation-model=pic -verify-machineinstrs < %s | \
16; RUN: FileCheck %s -check-prefixes=ALL-LABEL,MIPS64-ANY,O0
17; RUN: llc -march=mipsel --disable-machine-licm -mcpu=mips32r2 -mattr=micromips -relocation-model=pic < %s | \
18; RUN: FileCheck %s -check-prefixes=ALL,MIPS32-ANY,HAS-SEB-SEH,CHECK-EL,MICROMIPS
Daniel Sanders6a803f62014-06-16 13:13:03 +000019
20; Keep one big-endian check so that we don't reduce testing, but don't add more
21; since endianness doesn't affect the body of the atomic operations.
Daniel Sanders0d972702016-06-24 12:23:17 +000022; RUN: llc -march=mips --disable-machine-licm -mcpu=mips32 -relocation-model=pic < %s | \
23; RUN: FileCheck %s -check-prefixes=ALL,MIPS32-ANY,NO-SEB-SEH,CHECK-EB,NOT-MICROMIPS
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +000024
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +000025@x = common global i32 0, align 4
26
Daniel Sandersc43cda82014-11-07 16:54:21 +000027define i32 @AtomicLoadAdd32(i32 signext %incr) nounwind {
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +000028entry:
Eli Friedmanc064f2c2011-09-26 20:27:49 +000029 %0 = atomicrmw add i32* @x, i32 %incr monotonic
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +000030 ret i32 %0
31
Daniel Sandersddb7aa62014-06-16 10:25:17 +000032; ALL-LABEL: AtomicLoadAdd32:
Akira Hatanaka2bf97332013-05-31 03:25:44 +000033
Daniel Sanders6a803f62014-06-16 13:13:03 +000034; MIPS32-ANY: lw $[[R0:[0-9]+]], %got(x)
35; MIPS64-ANY: ld $[[R0:[0-9]+]], %got_disp(x)(
36
Daniel Sanders6a738832016-07-19 10:49:03 +000037; O0: [[BB0:(\$|\.L)[A-Z_0-9]+]]:
Simon Dardisa2d8cc32016-04-28 16:26:43 +000038; O0: ld $[[R1:[0-9]+]]
39; O0-NEXT: ll $[[R2:[0-9]+]], 0($[[R1]])
40
Daniel Sanders6a738832016-07-19 10:49:03 +000041; ALL: [[BB0:(\$|\.L)[A-Z_0-9]+]]:
Simon Dardisa2d8cc32016-04-28 16:26:43 +000042; ALL: ll $[[R3:[0-9]+]], 0($[[R0]])
43; ALL: addu $[[R4:[0-9]+]], $[[R3]], $4
44; ALL: sc $[[R4]], 0($[[R0]])
Daniel Sanders6a738832016-07-19 10:49:03 +000045; NOT-MICROMIPS: beqz $[[R4]], [[BB0]]
46; MICROMIPS: beqzc $[[R4]], [[BB0]]
47; MIPSR6: beqzc $[[R4]], [[BB0]]
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +000048}
49
Daniel Sandersc43cda82014-11-07 16:54:21 +000050define i32 @AtomicLoadNand32(i32 signext %incr) nounwind {
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +000051entry:
Eli Friedmanc064f2c2011-09-26 20:27:49 +000052 %0 = atomicrmw nand i32* @x, i32 %incr monotonic
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +000053 ret i32 %0
54
Daniel Sandersddb7aa62014-06-16 10:25:17 +000055; ALL-LABEL: AtomicLoadNand32:
Akira Hatanaka2bf97332013-05-31 03:25:44 +000056
Daniel Sanders6a803f62014-06-16 13:13:03 +000057; MIPS32-ANY: lw $[[R0:[0-9]+]], %got(x)
58; MIPS64-ANY: ld $[[R0:[0-9]+]], %got_disp(x)(
59
Simon Dardisa2d8cc32016-04-28 16:26:43 +000060
61
Daniel Sanders6a738832016-07-19 10:49:03 +000062; ALL: [[BB0:(\$|\.L)[A-Z_0-9]+]]:
Daniel Sandersddb7aa62014-06-16 10:25:17 +000063; ALL: ll $[[R1:[0-9]+]], 0($[[R0]])
64; ALL: and $[[R3:[0-9]+]], $[[R1]], $4
65; ALL: nor $[[R2:[0-9]+]], $zero, $[[R3]]
66; ALL: sc $[[R2]], 0($[[R0]])
Daniel Sanders6a738832016-07-19 10:49:03 +000067; NOT-MICROMIPS: beqz $[[R2]], [[BB0]]
68; MICROMIPS: beqzc $[[R2]], [[BB0]]
69; MIPSR6: beqzc $[[R2]], [[BB0]]
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +000070}
71
Daniel Sandersc43cda82014-11-07 16:54:21 +000072define i32 @AtomicSwap32(i32 signext %newval) nounwind {
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +000073entry:
Akira Hatanaka27292632011-07-18 18:52:12 +000074 %newval.addr = alloca i32, align 4
75 store i32 %newval, i32* %newval.addr, align 4
David Blaikiea79ac142015-02-27 21:17:42 +000076 %tmp = load i32, i32* %newval.addr, align 4
Eli Friedmanc064f2c2011-09-26 20:27:49 +000077 %0 = atomicrmw xchg i32* @x, i32 %tmp monotonic
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +000078 ret i32 %0
79
Daniel Sandersddb7aa62014-06-16 10:25:17 +000080; ALL-LABEL: AtomicSwap32:
Akira Hatanaka2bf97332013-05-31 03:25:44 +000081
Daniel Sanders6a803f62014-06-16 13:13:03 +000082; MIPS32-ANY: lw $[[R0:[0-9]+]], %got(x)
83; MIPS64-ANY: ld $[[R0:[0-9]+]], %got_disp(x)
84
Daniel Sanders6a738832016-07-19 10:49:03 +000085; ALL: [[BB0:(\$|\.L)[A-Z_0-9]+]]:
Daniel Sandersddb7aa62014-06-16 10:25:17 +000086; ALL: ll ${{[0-9]+}}, 0($[[R0]])
87; ALL: sc $[[R2:[0-9]+]], 0($[[R0]])
Daniel Sanders6a738832016-07-19 10:49:03 +000088; NOT-MICROMIPS: beqz $[[R2]], [[BB0]]
89; MICROMIPS: beqzc $[[R2]], [[BB0]]
90; MIPSR6: beqzc $[[R2]], [[BB0]]
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +000091}
92
Daniel Sandersc43cda82014-11-07 16:54:21 +000093define i32 @AtomicCmpSwap32(i32 signext %oldval, i32 signext %newval) nounwind {
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +000094entry:
Akira Hatanaka27292632011-07-18 18:52:12 +000095 %newval.addr = alloca i32, align 4
96 store i32 %newval, i32* %newval.addr, align 4
David Blaikiea79ac142015-02-27 21:17:42 +000097 %tmp = load i32, i32* %newval.addr, align 4
Tim Northovere94a5182014-03-11 10:48:52 +000098 %0 = cmpxchg i32* @x, i32 %oldval, i32 %tmp monotonic monotonic
Tim Northover420a2162014-06-13 14:24:07 +000099 %1 = extractvalue { i32, i1 } %0, 0
100 ret i32 %1
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000101
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000102; ALL-LABEL: AtomicCmpSwap32:
Akira Hatanaka2bf97332013-05-31 03:25:44 +0000103
Daniel Sanders6a803f62014-06-16 13:13:03 +0000104; MIPS32-ANY: lw $[[R0:[0-9]+]], %got(x)
105; MIPS64-ANY: ld $[[R0:[0-9]+]], %got_disp(x)(
106
Daniel Sanders6a738832016-07-19 10:49:03 +0000107; ALL: [[BB0:(\$|\.L)[A-Z_0-9]+]]:
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000108; ALL: ll $2, 0($[[R0]])
Daniel Sanders6a738832016-07-19 10:49:03 +0000109; NOT-MICROMIPS: bne $2, $4, [[BB1:(\$|\.L)[A-Z_0-9]+]]
110; MICROMIPS: bne $2, $4, [[BB1:(\$|\.L)[A-Z_0-9]+]]
111; MIPSR6: bnec $2, $4, [[BB1:(\$|\.L)[A-Z_0-9]+]]
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000112; ALL: sc $[[R2:[0-9]+]], 0($[[R0]])
Daniel Sanders6a738832016-07-19 10:49:03 +0000113; NOT-MICROMIPS: beqz $[[R2]], [[BB0]]
114; MICROMIPS: beqzc $[[R2]], [[BB0]]
115; MIPSR6: beqzc $[[R2]], [[BB0]]
116; ALL: [[BB1]]:
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000117}
118
119
120
121@y = common global i8 0, align 1
122
123define signext i8 @AtomicLoadAdd8(i8 signext %incr) nounwind {
124entry:
Eli Friedmanc064f2c2011-09-26 20:27:49 +0000125 %0 = atomicrmw add i8* @y, i8 %incr monotonic
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000126 ret i8 %0
127
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000128; ALL-LABEL: AtomicLoadAdd8:
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000129
Daniel Sanders6a803f62014-06-16 13:13:03 +0000130; MIPS32-ANY: lw $[[R0:[0-9]+]], %got(y)
131; MIPS64-ANY: ld $[[R0:[0-9]+]], %got_disp(y)(
132
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000133; ALL: addiu $[[R1:[0-9]+]], $zero, -4
134; ALL: and $[[R2:[0-9]+]], $[[R0]], $[[R1]]
135; ALL: andi $[[R3:[0-9]+]], $[[R0]], 3
136; CHECK-EB: xori $[[R4:[0-9]+]], $[[R3]], 3
137; CHECK-EB: sll $[[R5:[0-9]+]], $[[R4]], 3
138; CHECK-EL: sll $[[R5:[0-9]+]], $[[R3]], 3
139; ALL: ori $[[R6:[0-9]+]], $zero, 255
140; ALL: sllv $[[R7:[0-9]+]], $[[R6]], $[[R5]]
141; ALL: nor $[[R8:[0-9]+]], $zero, $[[R7]]
142; ALL: sllv $[[R9:[0-9]+]], $4, $[[R5]]
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000143
Daniel Sanders6a738832016-07-19 10:49:03 +0000144; O0: [[BB0:(\$|\.L)[A-Z_0-9]+]]:
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000145; O0: ld $[[R10:[0-9]+]]
146; O0-NEXT: ll $[[R11:[0-9]+]], 0($[[R10]])
147
Daniel Sanders6a738832016-07-19 10:49:03 +0000148; ALL: [[BB0:(\$|\.L)[A-Z_0-9]+]]:
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000149; ALL: ll $[[R12:[0-9]+]], 0($[[R2]])
150; ALL: addu $[[R13:[0-9]+]], $[[R12]], $[[R9]]
151; ALL: and $[[R14:[0-9]+]], $[[R13]], $[[R7]]
152; ALL: and $[[R15:[0-9]+]], $[[R12]], $[[R8]]
153; ALL: or $[[R16:[0-9]+]], $[[R15]], $[[R14]]
154; ALL: sc $[[R16]], 0($[[R2]])
Daniel Sanders6a738832016-07-19 10:49:03 +0000155; NOT-MICROMIPS: beqz $[[R16]], [[BB0]]
156; MICROMIPS: beqzc $[[R16]], [[BB0]]
157; MIPSR6: beqzc $[[R16]], [[BB0]]
Akira Hatanaka2bf97332013-05-31 03:25:44 +0000158
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000159; ALL: and $[[R17:[0-9]+]], $[[R12]], $[[R7]]
160; ALL: srlv $[[R18:[0-9]+]], $[[R17]], $[[R5]]
Daniel Sanders6a803f62014-06-16 13:13:03 +0000161
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000162; NO-SEB-SEH: sll $[[R19:[0-9]+]], $[[R18]], 24
163; NO-SEB-SEH: sra $2, $[[R19]], 24
Daniel Sanders6a803f62014-06-16 13:13:03 +0000164
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000165; HAS-SEB-SEH: seb $2, $[[R18]]
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000166}
167
168define signext i8 @AtomicLoadSub8(i8 signext %incr) nounwind {
169entry:
Eli Friedmanc064f2c2011-09-26 20:27:49 +0000170 %0 = atomicrmw sub i8* @y, i8 %incr monotonic
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000171 ret i8 %0
172
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000173; ALL-LABEL: AtomicLoadSub8:
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000174
Daniel Sanders6a803f62014-06-16 13:13:03 +0000175; MIPS32-ANY: lw $[[R0:[0-9]+]], %got(y)
176; MIPS64-ANY: ld $[[R0:[0-9]+]], %got_disp(y)(
177
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000178; ALL: addiu $[[R1:[0-9]+]], $zero, -4
179; ALL: and $[[R2:[0-9]+]], $[[R0]], $[[R1]]
180; ALL: andi $[[R3:[0-9]+]], $[[R0]], 3
181; CHECK-EL: sll $[[R5:[0-9]+]], $[[R3]], 3
Akira Hatanaka2bf97332013-05-31 03:25:44 +0000182; CHECK-EB: xori $[[R4:[0-9]+]], $[[R3]], 3
183; CHECK-EB: sll $[[R5:[0-9]+]], $[[R4]], 3
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000184; ALL: ori $[[R6:[0-9]+]], $zero, 255
185; ALL: sllv $[[R7:[0-9]+]], $[[R6]], $[[R5]]
186; ALL: nor $[[R8:[0-9]+]], $zero, $[[R7]]
187; ALL: sllv $[[R9:[0-9]+]], $4, $[[R5]]
Akira Hatanaka2bf97332013-05-31 03:25:44 +0000188
Daniel Sanders6a738832016-07-19 10:49:03 +0000189; O0: [[BB0:(\$|\.L)[A-Z_0-9]+]]:
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000190; O0: ld $[[R10:[0-9]+]]
191; O0-NEXT: ll $[[R11:[0-9]+]], 0($[[R10]])
192
Daniel Sanders6a738832016-07-19 10:49:03 +0000193; ALL: [[BB0:(\$|\.L)[A-Z_0-9]+]]:
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000194; ALL: ll $[[R12:[0-9]+]], 0($[[R2]])
195; ALL: subu $[[R13:[0-9]+]], $[[R12]], $[[R9]]
196; ALL: and $[[R14:[0-9]+]], $[[R13]], $[[R7]]
197; ALL: and $[[R15:[0-9]+]], $[[R12]], $[[R8]]
198; ALL: or $[[R16:[0-9]+]], $[[R15]], $[[R14]]
199; ALL: sc $[[R16]], 0($[[R2]])
Daniel Sanders6a738832016-07-19 10:49:03 +0000200; NOT-MICROMIPS: beqz $[[R16]], [[BB0]]
201; MICROMIPS: beqzc $[[R16]], [[BB0]]
202; MIPSR6: beqzc $[[R16]], [[BB0]]
Akira Hatanaka2bf97332013-05-31 03:25:44 +0000203
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000204; ALL: and $[[R17:[0-9]+]], $[[R12]], $[[R7]]
205; ALL: srlv $[[R18:[0-9]+]], $[[R17]], $[[R5]]
Daniel Sanders6a803f62014-06-16 13:13:03 +0000206
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000207; NO-SEB-SEH: sll $[[R19:[0-9]+]], $[[R18]], 24
208; NO-SEB-SEH: sra $2, $[[R19]], 24
Daniel Sanders6a803f62014-06-16 13:13:03 +0000209
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000210; HAS-SEB-SEH:seb $2, $[[R18]]
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000211}
212
213define signext i8 @AtomicLoadNand8(i8 signext %incr) nounwind {
214entry:
Eli Friedmanc064f2c2011-09-26 20:27:49 +0000215 %0 = atomicrmw nand i8* @y, i8 %incr monotonic
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000216 ret i8 %0
217
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000218; ALL-LABEL: AtomicLoadNand8:
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000219
Daniel Sanders6a803f62014-06-16 13:13:03 +0000220; MIPS32-ANY: lw $[[R0:[0-9]+]], %got(y)
221; MIPS64-ANY: ld $[[R0:[0-9]+]], %got_disp(y)(
222
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000223; ALL: addiu $[[R1:[0-9]+]], $zero, -4
224; ALL: and $[[R2:[0-9]+]], $[[R0]], $[[R1]]
225; ALL: andi $[[R3:[0-9]+]], $[[R0]], 3
226; CHECK-EL: sll $[[R5:[0-9]+]], $[[R3]], 3
227; CHECK-EB: xori $[[R4:[0-9]+]], $[[R3]], 3
228; CHECK-EB: sll $[[R5:[0-9]+]], $[[R4]], 3
229; ALL: ori $[[R6:[0-9]+]], $zero, 255
230; ALL: sllv $[[R7:[0-9]+]], $[[R6]], $[[R5]]
231; ALL: nor $[[R8:[0-9]+]], $zero, $[[R7]]
232; ALL: sllv $[[R9:[0-9]+]], $4, $[[R5]]
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000233
Daniel Sanders6a738832016-07-19 10:49:03 +0000234; O0: [[BB0:(\$|\.L)[A-Z_0-9]+]]:
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000235; O0: ld $[[R10:[0-9]+]]
236; O0-NEXT: ll $[[R11:[0-9]+]], 0($[[R10]])
237
Daniel Sanders6a738832016-07-19 10:49:03 +0000238; ALL: [[BB0:(\$|\.L)[A-Z_0-9]+]]:
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000239; ALL: ll $[[R12:[0-9]+]], 0($[[R2]])
240; ALL: and $[[R13:[0-9]+]], $[[R12]], $[[R9]]
241; ALL: nor $[[R14:[0-9]+]], $zero, $[[R13]]
242; ALL: and $[[R15:[0-9]+]], $[[R14]], $[[R7]]
243; ALL: and $[[R16:[0-9]+]], $[[R12]], $[[R8]]
244; ALL: or $[[R17:[0-9]+]], $[[R16]], $[[R15]]
245; ALL: sc $[[R17]], 0($[[R2]])
Daniel Sanders6a738832016-07-19 10:49:03 +0000246; NOT-MICROMIPS: beqz $[[R17]], [[BB0]]
247; MICROMIPS: beqzc $[[R17]], [[BB0]]
248; MIPSR6: beqzc $[[R17]], [[BB0]]
Akira Hatanaka2bf97332013-05-31 03:25:44 +0000249
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000250; ALL: and $[[R18:[0-9]+]], $[[R12]], $[[R7]]
251; ALL: srlv $[[R19:[0-9]+]], $[[R18]], $[[R5]]
Daniel Sanders6a803f62014-06-16 13:13:03 +0000252
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000253; NO-SEB-SEH: sll $[[R20:[0-9]+]], $[[R19]], 24
254; NO-SEB-SEH: sra $2, $[[R20]], 24
Daniel Sanders6a803f62014-06-16 13:13:03 +0000255
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000256; HAS-SEB-SEH: seb $2, $[[R19]]
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000257}
258
Akira Hatanaka27292632011-07-18 18:52:12 +0000259define signext i8 @AtomicSwap8(i8 signext %newval) nounwind {
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000260entry:
Eli Friedmanc064f2c2011-09-26 20:27:49 +0000261 %0 = atomicrmw xchg i8* @y, i8 %newval monotonic
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000262 ret i8 %0
263
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000264; ALL-LABEL: AtomicSwap8:
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000265
Daniel Sanders6a803f62014-06-16 13:13:03 +0000266; MIPS32-ANY: lw $[[R0:[0-9]+]], %got(y)
267; MIPS64-ANY: ld $[[R0:[0-9]+]], %got_disp(y)(
268
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000269; ALL: addiu $[[R1:[0-9]+]], $zero, -4
270; ALL: and $[[R2:[0-9]+]], $[[R0]], $[[R1]]
271; ALL: andi $[[R3:[0-9]+]], $[[R0]], 3
272; CHECK-EL: sll $[[R5:[0-9]+]], $[[R3]], 3
273; CHECK-EB: xori $[[R4:[0-9]+]], $[[R3]], 3
274; CHECK-EB: sll $[[R5:[0-9]+]], $[[R4]], 3
275; ALL: ori $[[R6:[0-9]+]], $zero, 255
276; ALL: sllv $[[R7:[0-9]+]], $[[R6]], $[[R5]]
277; ALL: nor $[[R8:[0-9]+]], $zero, $[[R7]]
278; ALL: sllv $[[R9:[0-9]+]], $4, $[[R5]]
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000279
Daniel Sanders6a738832016-07-19 10:49:03 +0000280; ALL: [[BB0:(\$|\.L)[A-Z_0-9]+]]:
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000281; ALL: ll $[[R10:[0-9]+]], 0($[[R2]])
282; ALL: and $[[R18:[0-9]+]], $[[R9]], $[[R7]]
283; ALL: and $[[R13:[0-9]+]], $[[R10]], $[[R8]]
284; ALL: or $[[R14:[0-9]+]], $[[R13]], $[[R18]]
285; ALL: sc $[[R14]], 0($[[R2]])
Daniel Sanders6a738832016-07-19 10:49:03 +0000286; NOT-MICROMIPS: beqz $[[R14]], [[BB0]]
287; MICROMIPS: beqzc $[[R14]], [[BB0]]
288; MIPSR6: beqzc $[[R14]], [[BB0]]
Akira Hatanaka2bf97332013-05-31 03:25:44 +0000289
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000290; ALL: and $[[R15:[0-9]+]], $[[R10]], $[[R7]]
291; ALL: srlv $[[R16:[0-9]+]], $[[R15]], $[[R5]]
Daniel Sanders6a803f62014-06-16 13:13:03 +0000292
293; NO-SEB-SEH: sll $[[R17:[0-9]+]], $[[R16]], 24
294; NO-SEB-SEH: sra $2, $[[R17]], 24
295
296; HAS-SEB-SEH: seb $2, $[[R16]]
Logan Chien63bee2a2014-07-21 17:33:44 +0000297
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000298}
299
300define signext i8 @AtomicCmpSwap8(i8 signext %oldval, i8 signext %newval) nounwind {
301entry:
Tim Northover420a2162014-06-13 14:24:07 +0000302 %pair0 = cmpxchg i8* @y, i8 %oldval, i8 %newval monotonic monotonic
303 %0 = extractvalue { i8, i1 } %pair0, 0
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000304 ret i8 %0
305
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000306; ALL-LABEL: AtomicCmpSwap8:
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000307
Daniel Sanders6a803f62014-06-16 13:13:03 +0000308; MIPS32-ANY: lw $[[R0:[0-9]+]], %got(y)
309; MIPS64-ANY: ld $[[R0:[0-9]+]], %got_disp(y)(
310
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000311; ALL: addiu $[[R1:[0-9]+]], $zero, -4
312; ALL: and $[[R2:[0-9]+]], $[[R0]], $[[R1]]
313; ALL: andi $[[R3:[0-9]+]], $[[R0]], 3
314; CHECK-EL: sll $[[R5:[0-9]+]], $[[R3]], 3
315; CHECK-EB: xori $[[R4:[0-9]+]], $[[R3]], 3
316; CHECK-EB: sll $[[R5:[0-9]+]], $[[R4]], 3
317; ALL: ori $[[R6:[0-9]+]], $zero, 255
318; ALL: sllv $[[R7:[0-9]+]], $[[R6]], $[[R5]]
319; ALL: nor $[[R8:[0-9]+]], $zero, $[[R7]]
320; ALL: andi $[[R9:[0-9]+]], $4, 255
321; ALL: sllv $[[R10:[0-9]+]], $[[R9]], $[[R5]]
322; ALL: andi $[[R11:[0-9]+]], $5, 255
323; ALL: sllv $[[R12:[0-9]+]], $[[R11]], $[[R5]]
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000324
Daniel Sanders6a738832016-07-19 10:49:03 +0000325; ALL: [[BB0:(\$|\.L)[A-Z_0-9]+]]:
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000326; ALL: ll $[[R13:[0-9]+]], 0($[[R2]])
327; ALL: and $[[R14:[0-9]+]], $[[R13]], $[[R7]]
Daniel Sanders6a738832016-07-19 10:49:03 +0000328; NOT-MICROMIPS: bne $[[R14]], $[[R10]], [[BB1:(\$|\.L)[A-Z_0-9]+]]
329; MICROMIPS: bne $[[R14]], $[[R10]], [[BB1:(\$|\.L)[A-Z_0-9]+]]
330; MIPSR6: bnec $[[R14]], $[[R10]], [[BB1:(\$|\.L)[A-Z_0-9]+]]
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000331
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000332; ALL: and $[[R15:[0-9]+]], $[[R13]], $[[R8]]
333; ALL: or $[[R16:[0-9]+]], $[[R15]], $[[R12]]
334; ALL: sc $[[R16]], 0($[[R2]])
Daniel Sanders6a738832016-07-19 10:49:03 +0000335; NOT-MICROMIPS: beqz $[[R16]], [[BB0]]
336; MICROMIPS: beqzc $[[R16]], [[BB0]]
337; MIPSR6: beqzc $[[R16]], [[BB0]]
Akira Hatanaka2bf97332013-05-31 03:25:44 +0000338
Daniel Sanders6a738832016-07-19 10:49:03 +0000339; ALL: [[BB1]]:
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000340; ALL: srlv $[[R17:[0-9]+]], $[[R14]], $[[R5]]
Daniel Sanders6a803f62014-06-16 13:13:03 +0000341
342; NO-SEB-SEH: sll $[[R18:[0-9]+]], $[[R17]], 24
343; NO-SEB-SEH: sra $2, $[[R18]], 24
344
345; HAS-SEB-SEH: seb $2, $[[R17]]
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +0000346}
Akira Hatanakaa4c09bc2011-07-19 23:30:50 +0000347
Daniel Sandersc43cda82014-11-07 16:54:21 +0000348define i1 @AtomicCmpSwapRes8(i8* %ptr, i8 signext %oldval, i8 signext %newval) nounwind {
Logan Chien63bee2a2014-07-21 17:33:44 +0000349entry:
350 %0 = cmpxchg i8* %ptr, i8 %oldval, i8 %newval monotonic monotonic
351 %1 = extractvalue { i8, i1 } %0, 1
352 ret i1 %1
353; ALL-LABEL: AtomicCmpSwapRes8
354
355; ALL: addiu $[[R1:[0-9]+]], $zero, -4
356; ALL: and $[[R2:[0-9]+]], $4, $[[R1]]
357; ALL: andi $[[R3:[0-9]+]], $4, 3
358; CHECK-EL: sll $[[R5:[0-9]+]], $[[R3]], 3
359; CHECK-EB: xori $[[R4:[0-9]+]], $[[R3]], 3
360; CHECK-EB: sll $[[R5:[0-9]+]], $[[R4]], 3
361; ALL: ori $[[R6:[0-9]+]], $zero, 255
362; ALL: sllv $[[R7:[0-9]+]], $[[R6]], $[[R5]]
363; ALL: nor $[[R8:[0-9]+]], $zero, $[[R7]]
364; ALL: andi $[[R9:[0-9]+]], $5, 255
365; ALL: sllv $[[R10:[0-9]+]], $[[R9]], $[[R5]]
366; ALL: andi $[[R11:[0-9]+]], $6, 255
367; ALL: sllv $[[R12:[0-9]+]], $[[R11]], $[[R5]]
368
Daniel Sanders6a738832016-07-19 10:49:03 +0000369; ALL: [[BB0:(\$|\.L)[A-Z_0-9]+]]:
Logan Chien63bee2a2014-07-21 17:33:44 +0000370; ALL: ll $[[R13:[0-9]+]], 0($[[R2]])
371; ALL: and $[[R14:[0-9]+]], $[[R13]], $[[R7]]
Daniel Sanders6a738832016-07-19 10:49:03 +0000372; NOT-MICROMIPS: bne $[[R14]], $[[R10]], [[BB1:(\$|\.L)[A-Z_0-9]+]]
373; MICROMIPS: bne $[[R14]], $[[R10]], [[BB1:(\$|\.L)[A-Z_0-9]+]]
374; MIPSR6: bnec $[[R14]], $[[R10]], [[BB1:(\$|\.L)[A-Z_0-9]+]]
Logan Chien63bee2a2014-07-21 17:33:44 +0000375
376; ALL: and $[[R15:[0-9]+]], $[[R13]], $[[R8]]
377; ALL: or $[[R16:[0-9]+]], $[[R15]], $[[R12]]
378; ALL: sc $[[R16]], 0($[[R2]])
Daniel Sanders6a738832016-07-19 10:49:03 +0000379; NOT-MICROMIPS: beqz $[[R16]], [[BB0]]
380; MICROMIPS: beqzc $[[R16]], [[BB0]]
381; MIPSR6: beqzc $[[R16]], [[BB0]]
Logan Chien63bee2a2014-07-21 17:33:44 +0000382
Daniel Sanders6a738832016-07-19 10:49:03 +0000383; ALL: [[BB1]]:
Logan Chien63bee2a2014-07-21 17:33:44 +0000384; ALL: srlv $[[R17:[0-9]+]], $[[R14]], $[[R5]]
385
386; NO-SEB-SEH: sll $[[R18:[0-9]+]], $[[R17]], 24
387; NO-SEB-SEH: sra $[[R19:[0-9]+]], $[[R18]], 24
388
Tim Northover4498eff2016-03-24 15:38:38 +0000389; FIXME: -march=mips produces a redundant sign extension here...
390; NO-SEB-SEH: sll $[[R20:[0-9]+]], $5, 24
391; NO-SEB-SEH: sra $[[R20]], $[[R20]], 24
392
Logan Chien63bee2a2014-07-21 17:33:44 +0000393; HAS-SEB-SEH: seb $[[R19:[0-9]+]], $[[R17]]
394
Tim Northover4498eff2016-03-24 15:38:38 +0000395; FIXME: ...Leading to this split check.
396; NO-SEB-SEH: xor $[[R21:[0-9]+]], $[[R19]], $[[R20]]
397; HAS-SEB-SEH: xor $[[R21:[0-9]+]], $[[R19]], $5
398
399; ALL: sltiu $2, $[[R21]], 1
Logan Chien63bee2a2014-07-21 17:33:44 +0000400}
401
Daniel Sanders6a803f62014-06-16 13:13:03 +0000402; Check one i16 so that we cover the seh sign extend
403@z = common global i16 0, align 1
404
405define signext i16 @AtomicLoadAdd16(i16 signext %incr) nounwind {
406entry:
407 %0 = atomicrmw add i16* @z, i16 %incr monotonic
408 ret i16 %0
409
410; ALL-LABEL: AtomicLoadAdd16:
411
412; MIPS32-ANY: lw $[[R0:[0-9]+]], %got(z)
413; MIPS64-ANY: ld $[[R0:[0-9]+]], %got_disp(z)(
414
415; ALL: addiu $[[R1:[0-9]+]], $zero, -4
416; ALL: and $[[R2:[0-9]+]], $[[R0]], $[[R1]]
417; ALL: andi $[[R3:[0-9]+]], $[[R0]], 3
418; CHECK-EB: xori $[[R4:[0-9]+]], $[[R3]], 2
419; CHECK-EB: sll $[[R5:[0-9]+]], $[[R4]], 3
420; CHECK-EL: sll $[[R5:[0-9]+]], $[[R3]], 3
421; ALL: ori $[[R6:[0-9]+]], $zero, 65535
422; ALL: sllv $[[R7:[0-9]+]], $[[R6]], $[[R5]]
423; ALL: nor $[[R8:[0-9]+]], $zero, $[[R7]]
424; ALL: sllv $[[R9:[0-9]+]], $4, $[[R5]]
425
Daniel Sanders6a738832016-07-19 10:49:03 +0000426; O0: [[BB0:(\$|\.L)[A-Z_0-9]+]]:
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000427; O0: ld $[[R10:[0-9]+]]
428; O0-NEXT: ll $[[R11:[0-9]+]], 0($[[R10]])
429
Daniel Sanders6a738832016-07-19 10:49:03 +0000430; ALL: [[BB0:(\$|\.L)[A-Z_0-9]+]]:
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000431; ALL: ll $[[R12:[0-9]+]], 0($[[R2]])
432; ALL: addu $[[R13:[0-9]+]], $[[R12]], $[[R9]]
433; ALL: and $[[R14:[0-9]+]], $[[R13]], $[[R7]]
434; ALL: and $[[R15:[0-9]+]], $[[R12]], $[[R8]]
435; ALL: or $[[R16:[0-9]+]], $[[R15]], $[[R14]]
436; ALL: sc $[[R16]], 0($[[R2]])
Daniel Sanders6a738832016-07-19 10:49:03 +0000437; NOT-MICROMIPS: beqz $[[R16]], [[BB0]]
438; MICROMIPS: beqzc $[[R16]], [[BB0]]
439; MIPSR6: beqzc $[[R16]], [[BB0]]
Daniel Sanders6a803f62014-06-16 13:13:03 +0000440
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000441; ALL: and $[[R17:[0-9]+]], $[[R12]], $[[R7]]
442; ALL: srlv $[[R18:[0-9]+]], $[[R17]], $[[R5]]
Daniel Sanders6a803f62014-06-16 13:13:03 +0000443
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000444; NO-SEB-SEH: sll $[[R19:[0-9]+]], $[[R18]], 16
445; NO-SEB-SEH: sra $2, $[[R19]], 16
Daniel Sanders6a803f62014-06-16 13:13:03 +0000446
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000447; MIPS32R2: seh $2, $[[R18]]
Daniel Sanders6a803f62014-06-16 13:13:03 +0000448}
449
Tim Northover4498eff2016-03-24 15:38:38 +0000450; Test that the i16 return value from cmpxchg is recognised as signed,
451; so that setCC doesn't end up comparing an unsigned value to a signed
452; value.
453; The rest of the functions here are testing the atomic expansion, so
454; we just match the end of the function.
455define {i16, i1} @foo(i16* %addr, i16 %l, i16 %r, i16 %new) {
456 %desired = add i16 %l, %r
457 %res = cmpxchg i16* %addr, i16 %desired, i16 %new seq_cst seq_cst
458 ret {i16, i1} %res
459
460; ALL-LABEL: foo
461; MIPSR6: addu $[[R2:[0-9]+]], $[[R1:[0-9]+]], $[[R0:[0-9]+]]
462; NOT-MICROMIPS: addu $[[R2:[0-9]+]], $[[R1:[0-9]+]], $[[R0:[0-9]+]]
463; MICROMIPS: addu16 $[[R2:[0-9]+]], $[[R1:[0-9]+]], $[[R0:[0-9]+]]
464
465; ALL: sync
466
467; ALL: andi $[[R3:[0-9]+]], $[[R2]], 65535
Daniel Sanders6a738832016-07-19 10:49:03 +0000468; ALL: [[BB0:(\$|\.L)[A-Z_0-9]+]]:
Tim Northover4498eff2016-03-24 15:38:38 +0000469; ALL: ll $[[R4:[0-9]+]], 0($[[R5:[0-9]+]])
470; ALL: and $[[R6:[0-9]+]], $[[R4]], $
471; ALL: and $[[R7:[0-9]+]], $[[R4]], $
472; ALL: or $[[R8:[0-9]+]], $[[R7]], $
473; ALL: sc $[[R8]], 0($[[R5]])
Daniel Sanders6a738832016-07-19 10:49:03 +0000474; NOT-MICROMIPS: beqz $[[R8]], [[BB0]]
475; MICROMIPS: beqzc $[[R8]], [[BB0]]
476; MIPSR6: beqzc $[[R8]], [[BB0]]
Tim Northover4498eff2016-03-24 15:38:38 +0000477
478; ALL: srlv $[[R9:[0-9]+]], $[[R6]], $
479
480; NO-SEB-SEH: sll $[[R10:[0-9]+]], $[[R9]], 16
481; NO-SEB-SEH: sra $[[R11:[0-9]+]], $[[R10]], 16
482
483; NO-SEB-SEH: sll $[[R12:[0-9]+]], $[[R2]], 16
484; NO-SEB-SEH: sra $[[R13:[0-9]+]], $[[R12]], 16
485
486; HAS-SEB-SEH: seh $[[R11:[0-9]+]], $[[R9]]
487; HAS-SEB-SEH: seh $[[R13:[0-9]+]], $[[R2]]
488
489; ALL: xor $[[R12:[0-9]+]], $[[R11]], $[[R13]]
490; ALL: sltiu $3, $[[R12]], 1
491; ALL: sync
492}
Daniel Sanders6a803f62014-06-16 13:13:03 +0000493
Akira Hatanakaa4c09bc2011-07-19 23:30:50 +0000494@countsint = common global i32 0, align 4
495
Daniel Sandersc43cda82014-11-07 16:54:21 +0000496define i32 @CheckSync(i32 signext %v) nounwind noinline {
Akira Hatanakaa4c09bc2011-07-19 23:30:50 +0000497entry:
Eli Friedmanc064f2c2011-09-26 20:27:49 +0000498 %0 = atomicrmw add i32* @countsint, i32 %v seq_cst
Akira Hatanakaa4c09bc2011-07-19 23:30:50 +0000499 ret i32 %0
500
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000501; ALL-LABEL: CheckSync:
Akira Hatanaka2bf97332013-05-31 03:25:44 +0000502
Matheus Almeida784f7972014-06-18 17:10:30 +0000503; ALL: sync
Daniel Sandersddb7aa62014-06-16 10:25:17 +0000504; ALL: ll
505; ALL: sc
506; ALL: beq
Matheus Almeida784f7972014-06-18 17:10:30 +0000507; ALL: sync
Akira Hatanakaa4c09bc2011-07-19 23:30:50 +0000508}
509
Akira Hatanaka0661b812012-05-11 23:22:18 +0000510; make sure that this assertion in
511; TwoAddressInstructionPass::TryInstructionTransform does not fail:
512;
513; line 1203: assert(TargetRegisterInfo::isVirtualRegister(regB) &&
514;
515; it failed when MipsDAGToDAGISel::ReplaceUsesWithZeroReg replaced an
516; operand of an atomic instruction with register $zero.
517@a = external global i32
518
519define i32 @zeroreg() nounwind {
520entry:
Tim Northover420a2162014-06-13 14:24:07 +0000521 %pair0 = cmpxchg i32* @a, i32 1, i32 0 seq_cst seq_cst
522 %0 = extractvalue { i32, i1 } %pair0, 0
Akira Hatanaka0661b812012-05-11 23:22:18 +0000523 %1 = icmp eq i32 %0, 1
524 %conv = zext i1 %1 to i32
525 ret i32 %conv
526}
Daniel Sanders6a803f62014-06-16 13:13:03 +0000527
528; Check that MIPS32R6 has the correct offset range.
529; FIXME: At the moment, we don't seem to do addr+offset for any atomic load/store.
Daniel Sandersc43cda82014-11-07 16:54:21 +0000530define i32 @AtomicLoadAdd32_OffGt9Bit(i32 signext %incr) nounwind {
Daniel Sanders6a803f62014-06-16 13:13:03 +0000531entry:
David Blaikief72d05b2015-03-13 18:20:45 +0000532 %0 = atomicrmw add i32* getelementptr(i32, i32* @x, i32 256), i32 %incr monotonic
Daniel Sanders6a803f62014-06-16 13:13:03 +0000533 ret i32 %0
534
535; ALL-LABEL: AtomicLoadAdd32_OffGt9Bit:
536
537; MIPS32-ANY: lw $[[R0:[0-9]+]], %got(x)
538; MIPS64-ANY: ld $[[R0:[0-9]+]], %got_disp(x)(
539
540; ALL: addiu $[[PTR:[0-9]+]], $[[R0]], 1024
Daniel Sanders6a738832016-07-19 10:49:03 +0000541; ALL: [[BB0:(\$|\.L)[A-Z_0-9]+]]:
Daniel Sanders6a803f62014-06-16 13:13:03 +0000542; ALL: ll $[[R1:[0-9]+]], 0($[[PTR]])
543; ALL: addu $[[R2:[0-9]+]], $[[R1]], $4
544; ALL: sc $[[R2]], 0($[[PTR]])
Daniel Sanders6a738832016-07-19 10:49:03 +0000545; NOT-MICROMIPS: beqz $[[R2]], [[BB0]]
546; MICROMIPS: beqzc $[[R2]], [[BB0]]
547; MIPSR6: beqzc $[[R2]], [[BB0]]
Daniel Sanders6a803f62014-06-16 13:13:03 +0000548}