1 ; RUN: llc -march=mipsel --disable-machine-licm < %s | FileCheck %s -check-prefix=ALL -check-prefix=CHECK-EL
2 ; RUN: llc -march=mips --disable-machine-licm < %s | FileCheck %s -check-prefix=ALL -check-prefix=CHECK-EB
4 @x = common global i32 0, align 4
6 define i32 @AtomicLoadAdd32(i32 %incr) nounwind {
8 %0 = atomicrmw add i32* @x, i32 %incr monotonic
11 ; ALL-LABEL: AtomicLoadAdd32:
13 ; ALL: lw $[[R0:[0-9]+]], %got(x)
14 ; ALL: $[[BB0:[A-Z_0-9]+]]:
15 ; ALL: ll $[[R1:[0-9]+]], 0($[[R0]])
16 ; ALL: addu $[[R2:[0-9]+]], $[[R1]], $4
17 ; ALL: sc $[[R2]], 0($[[R0]])
18 ; ALL: beqz $[[R2]], $[[BB0]]
21 define i32 @AtomicLoadNand32(i32 %incr) nounwind {
23 %0 = atomicrmw nand i32* @x, i32 %incr monotonic
26 ; ALL-LABEL: AtomicLoadNand32:
28 ; ALL: lw $[[R0:[0-9]+]], %got(x)
29 ; ALL: $[[BB0:[A-Z_0-9]+]]:
30 ; ALL: ll $[[R1:[0-9]+]], 0($[[R0]])
31 ; ALL: and $[[R3:[0-9]+]], $[[R1]], $4
32 ; ALL: nor $[[R2:[0-9]+]], $zero, $[[R3]]
33 ; ALL: sc $[[R2]], 0($[[R0]])
34 ; ALL: beqz $[[R2]], $[[BB0]]
37 define i32 @AtomicSwap32(i32 %newval) nounwind {
39 %newval.addr = alloca i32, align 4
40 store i32 %newval, i32* %newval.addr, align 4
41 %tmp = load i32* %newval.addr, align 4
42 %0 = atomicrmw xchg i32* @x, i32 %tmp monotonic
45 ; ALL-LABEL: AtomicSwap32:
47 ; ALL: lw $[[R0:[0-9]+]], %got(x)
48 ; ALL: $[[BB0:[A-Z_0-9]+]]:
49 ; ALL: ll ${{[0-9]+}}, 0($[[R0]])
50 ; ALL: sc $[[R2:[0-9]+]], 0($[[R0]])
51 ; ALL: beqz $[[R2]], $[[BB0]]
54 define i32 @AtomicCmpSwap32(i32 %oldval, i32 %newval) nounwind {
56 %newval.addr = alloca i32, align 4
57 store i32 %newval, i32* %newval.addr, align 4
58 %tmp = load i32* %newval.addr, align 4
59 %0 = cmpxchg i32* @x, i32 %oldval, i32 %tmp monotonic monotonic
60 %1 = extractvalue { i32, i1 } %0, 0
63 ; ALL-LABEL: AtomicCmpSwap32:
65 ; ALL: lw $[[R0:[0-9]+]], %got(x)
66 ; ALL: $[[BB0:[A-Z_0-9]+]]:
67 ; ALL: ll $2, 0($[[R0]])
68 ; ALL: bne $2, $4, $[[BB1:[A-Z_0-9]+]]
69 ; ALL: sc $[[R2:[0-9]+]], 0($[[R0]])
70 ; ALL: beqz $[[R2]], $[[BB0]]
76 @y = common global i8 0, align 1
78 define signext i8 @AtomicLoadAdd8(i8 signext %incr) nounwind {
80 %0 = atomicrmw add i8* @y, i8 %incr monotonic
83 ; ALL-LABEL: AtomicLoadAdd8:
85 ; ALL: lw $[[R0:[0-9]+]], %got(y)
86 ; ALL: addiu $[[R1:[0-9]+]], $zero, -4
87 ; ALL: and $[[R2:[0-9]+]], $[[R0]], $[[R1]]
88 ; ALL: andi $[[R3:[0-9]+]], $[[R0]], 3
89 ; CHECK-EB: xori $[[R4:[0-9]+]], $[[R3]], 3
90 ; CHECK-EB: sll $[[R5:[0-9]+]], $[[R4]], 3
91 ; CHECK-EL: sll $[[R5:[0-9]+]], $[[R3]], 3
92 ; ALL: ori $[[R6:[0-9]+]], $zero, 255
93 ; ALL: sllv $[[R7:[0-9]+]], $[[R6]], $[[R5]]
94 ; ALL: nor $[[R8:[0-9]+]], $zero, $[[R7]]
95 ; ALL: sllv $[[R9:[0-9]+]], $4, $[[R5]]
97 ; ALL: $[[BB0:[A-Z_0-9]+]]:
98 ; ALL: ll $[[R10:[0-9]+]], 0($[[R2]])
99 ; ALL: addu $[[R11:[0-9]+]], $[[R10]], $[[R9]]
100 ; ALL: and $[[R12:[0-9]+]], $[[R11]], $[[R7]]
101 ; ALL: and $[[R13:[0-9]+]], $[[R10]], $[[R8]]
102 ; ALL: or $[[R14:[0-9]+]], $[[R13]], $[[R12]]
103 ; ALL: sc $[[R14]], 0($[[R2]])
104 ; ALL: beqz $[[R14]], $[[BB0]]
106 ; ALL: and $[[R15:[0-9]+]], $[[R10]], $[[R7]]
107 ; ALL: srlv $[[R16:[0-9]+]], $[[R15]], $[[R5]]
108 ; ALL: sll $[[R17:[0-9]+]], $[[R16]], 24
109 ; ALL: sra $2, $[[R17]], 24
112 define signext i8 @AtomicLoadSub8(i8 signext %incr) nounwind {
114 %0 = atomicrmw sub i8* @y, i8 %incr monotonic
117 ; ALL-LABEL: AtomicLoadSub8:
119 ; ALL: lw $[[R0:[0-9]+]], %got(y)
120 ; ALL: addiu $[[R1:[0-9]+]], $zero, -4
121 ; ALL: and $[[R2:[0-9]+]], $[[R0]], $[[R1]]
122 ; ALL: andi $[[R3:[0-9]+]], $[[R0]], 3
123 ; CHECK-EL: sll $[[R5:[0-9]+]], $[[R3]], 3
124 ; CHECK-EB: xori $[[R4:[0-9]+]], $[[R3]], 3
125 ; CHECK-EB: sll $[[R5:[0-9]+]], $[[R4]], 3
126 ; ALL: ori $[[R6:[0-9]+]], $zero, 255
127 ; ALL: sllv $[[R7:[0-9]+]], $[[R6]], $[[R5]]
128 ; ALL: nor $[[R8:[0-9]+]], $zero, $[[R7]]
129 ; ALL: sllv $[[R9:[0-9]+]], $4, $[[R5]]
131 ; ALL: $[[BB0:[A-Z_0-9]+]]:
132 ; ALL: ll $[[R10:[0-9]+]], 0($[[R2]])
133 ; ALL: subu $[[R11:[0-9]+]], $[[R10]], $[[R9]]
134 ; ALL: and $[[R12:[0-9]+]], $[[R11]], $[[R7]]
135 ; ALL: and $[[R13:[0-9]+]], $[[R10]], $[[R8]]
136 ; ALL: or $[[R14:[0-9]+]], $[[R13]], $[[R12]]
137 ; ALL: sc $[[R14]], 0($[[R2]])
138 ; ALL: beqz $[[R14]], $[[BB0]]
140 ; ALL: and $[[R15:[0-9]+]], $[[R10]], $[[R7]]
141 ; ALL: srlv $[[R16:[0-9]+]], $[[R15]], $[[R5]]
142 ; ALL: sll $[[R17:[0-9]+]], $[[R16]], 24
143 ; ALL: sra $2, $[[R17]], 24
146 define signext i8 @AtomicLoadNand8(i8 signext %incr) nounwind {
148 %0 = atomicrmw nand i8* @y, i8 %incr monotonic
151 ; ALL-LABEL: AtomicLoadNand8:
153 ; ALL: lw $[[R0:[0-9]+]], %got(y)
154 ; ALL: addiu $[[R1:[0-9]+]], $zero, -4
155 ; ALL: and $[[R2:[0-9]+]], $[[R0]], $[[R1]]
156 ; ALL: andi $[[R3:[0-9]+]], $[[R0]], 3
157 ; CHECK-EL: sll $[[R5:[0-9]+]], $[[R3]], 3
158 ; CHECK-EB: xori $[[R4:[0-9]+]], $[[R3]], 3
159 ; CHECK-EB: sll $[[R5:[0-9]+]], $[[R4]], 3
160 ; ALL: ori $[[R6:[0-9]+]], $zero, 255
161 ; ALL: sllv $[[R7:[0-9]+]], $[[R6]], $[[R5]]
162 ; ALL: nor $[[R8:[0-9]+]], $zero, $[[R7]]
163 ; ALL: sllv $[[R9:[0-9]+]], $4, $[[R5]]
165 ; ALL: $[[BB0:[A-Z_0-9]+]]:
166 ; ALL: ll $[[R10:[0-9]+]], 0($[[R2]])
167 ; ALL: and $[[R18:[0-9]+]], $[[R10]], $[[R9]]
168 ; ALL: nor $[[R11:[0-9]+]], $zero, $[[R18]]
169 ; ALL: and $[[R12:[0-9]+]], $[[R11]], $[[R7]]
170 ; ALL: and $[[R13:[0-9]+]], $[[R10]], $[[R8]]
171 ; ALL: or $[[R14:[0-9]+]], $[[R13]], $[[R12]]
172 ; ALL: sc $[[R14]], 0($[[R2]])
173 ; ALL: beqz $[[R14]], $[[BB0]]
175 ; ALL: and $[[R15:[0-9]+]], $[[R10]], $[[R7]]
176 ; ALL: srlv $[[R16:[0-9]+]], $[[R15]], $[[R5]]
177 ; ALL: sll $[[R17:[0-9]+]], $[[R16]], 24
178 ; ALL: sra $2, $[[R17]], 24
181 define signext i8 @AtomicSwap8(i8 signext %newval) nounwind {
183 %0 = atomicrmw xchg i8* @y, i8 %newval monotonic
186 ; ALL-LABEL: AtomicSwap8:
188 ; ALL: lw $[[R0:[0-9]+]], %got(y)
189 ; ALL: addiu $[[R1:[0-9]+]], $zero, -4
190 ; ALL: and $[[R2:[0-9]+]], $[[R0]], $[[R1]]
191 ; ALL: andi $[[R3:[0-9]+]], $[[R0]], 3
192 ; CHECK-EL: sll $[[R5:[0-9]+]], $[[R3]], 3
193 ; CHECK-EB: xori $[[R4:[0-9]+]], $[[R3]], 3
194 ; CHECK-EB: sll $[[R5:[0-9]+]], $[[R4]], 3
195 ; ALL: ori $[[R6:[0-9]+]], $zero, 255
196 ; ALL: sllv $[[R7:[0-9]+]], $[[R6]], $[[R5]]
197 ; ALL: nor $[[R8:[0-9]+]], $zero, $[[R7]]
198 ; ALL: sllv $[[R9:[0-9]+]], $4, $[[R5]]
200 ; ALL: $[[BB0:[A-Z_0-9]+]]:
201 ; ALL: ll $[[R10:[0-9]+]], 0($[[R2]])
202 ; ALL: and $[[R18:[0-9]+]], $[[R9]], $[[R7]]
203 ; ALL: and $[[R13:[0-9]+]], $[[R10]], $[[R8]]
204 ; ALL: or $[[R14:[0-9]+]], $[[R13]], $[[R18]]
205 ; ALL: sc $[[R14]], 0($[[R2]])
206 ; ALL: beqz $[[R14]], $[[BB0]]
208 ; ALL: and $[[R15:[0-9]+]], $[[R10]], $[[R7]]
209 ; ALL: srlv $[[R16:[0-9]+]], $[[R15]], $[[R5]]
210 ; ALL: sll $[[R17:[0-9]+]], $[[R16]], 24
211 ; ALL: sra $2, $[[R17]], 24
214 define signext i8 @AtomicCmpSwap8(i8 signext %oldval, i8 signext %newval) nounwind {
216 %pair0 = cmpxchg i8* @y, i8 %oldval, i8 %newval monotonic monotonic
217 %0 = extractvalue { i8, i1 } %pair0, 0
220 ; ALL-LABEL: AtomicCmpSwap8:
222 ; ALL: lw $[[R0:[0-9]+]], %got(y)
223 ; 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: andi $[[R9:[0-9]+]], $4, 255
233 ; ALL: sllv $[[R10:[0-9]+]], $[[R9]], $[[R5]]
234 ; ALL: andi $[[R11:[0-9]+]], $5, 255
235 ; ALL: sllv $[[R12:[0-9]+]], $[[R11]], $[[R5]]
237 ; ALL: $[[BB0:[A-Z_0-9]+]]:
238 ; ALL: ll $[[R13:[0-9]+]], 0($[[R2]])
239 ; ALL: and $[[R14:[0-9]+]], $[[R13]], $[[R7]]
240 ; ALL: bne $[[R14]], $[[R10]], $[[BB1:[A-Z_0-9]+]]
242 ; ALL: and $[[R15:[0-9]+]], $[[R13]], $[[R8]]
243 ; ALL: or $[[R16:[0-9]+]], $[[R15]], $[[R12]]
244 ; ALL: sc $[[R16]], 0($[[R2]])
245 ; ALL: beqz $[[R16]], $[[BB0]]
248 ; ALL: srlv $[[R17:[0-9]+]], $[[R14]], $[[R5]]
249 ; ALL: sll $[[R18:[0-9]+]], $[[R17]], 24
250 ; ALL: sra $2, $[[R18]], 24
253 @countsint = common global i32 0, align 4
255 define i32 @CheckSync(i32 %v) nounwind noinline {
257 %0 = atomicrmw add i32* @countsint, i32 %v seq_cst
260 ; ALL-LABEL: CheckSync:
269 ; make sure that this assertion in
270 ; TwoAddressInstructionPass::TryInstructionTransform does not fail:
272 ; line 1203: assert(TargetRegisterInfo::isVirtualRegister(regB) &&
274 ; it failed when MipsDAGToDAGISel::ReplaceUsesWithZeroReg replaced an
275 ; operand of an atomic instruction with register $zero.
276 @a = external global i32
278 define i32 @zeroreg() nounwind {
280 %pair0 = cmpxchg i32* @a, i32 1, i32 0 seq_cst seq_cst
281 %0 = extractvalue { i32, i1 } %pair0, 0
282 %1 = icmp eq i32 %0, 1
283 %conv = zext i1 %1 to i32