2a05944161110b256daa41f9e72a5b1caf1919c0
[oota-llvm.git] / test / CodeGen / Mips / atomic.ll
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
3
4 @x = common global i32 0, align 4
5
6 define i32 @AtomicLoadAdd32(i32 %incr) nounwind {
7 entry:
8   %0 = atomicrmw add i32* @x, i32 %incr monotonic
9   ret i32 %0
10
11 ; ALL-LABEL: AtomicLoadAdd32:
12
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]]
19 }
20
21 define i32 @AtomicLoadNand32(i32 %incr) nounwind {
22 entry:
23   %0 = atomicrmw nand i32* @x, i32 %incr monotonic
24   ret i32 %0
25
26 ; ALL-LABEL: AtomicLoadNand32:
27
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]]
35 }
36
37 define i32 @AtomicSwap32(i32 %newval) nounwind {
38 entry:
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
43   ret i32 %0
44
45 ; ALL-LABEL: AtomicSwap32:
46
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]]
52 }
53
54 define i32 @AtomicCmpSwap32(i32 %oldval, i32 %newval) nounwind {
55 entry:
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
61   ret i32 %1
62
63 ; ALL-LABEL: AtomicCmpSwap32:
64
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]]
71 ; ALL:       $[[BB1]]:
72 }
73
74
75
76 @y = common global i8 0, align 1
77
78 define signext i8 @AtomicLoadAdd8(i8 signext %incr) nounwind {
79 entry:
80   %0 = atomicrmw add i8* @y, i8 %incr monotonic
81   ret i8 %0
82
83 ; ALL-LABEL: AtomicLoadAdd8:
84
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]]
96
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]]
105
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
110 }
111
112 define signext i8 @AtomicLoadSub8(i8 signext %incr) nounwind {
113 entry:
114   %0 = atomicrmw sub i8* @y, i8 %incr monotonic
115   ret i8 %0
116
117 ; ALL-LABEL: AtomicLoadSub8:
118
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]]
130
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]]
139
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
144 }
145
146 define signext i8 @AtomicLoadNand8(i8 signext %incr) nounwind {
147 entry:
148   %0 = atomicrmw nand i8* @y, i8 %incr monotonic
149   ret i8 %0
150
151 ; ALL-LABEL: AtomicLoadNand8:
152
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]]
164
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]]
174
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
179 }
180
181 define signext i8 @AtomicSwap8(i8 signext %newval) nounwind {
182 entry:
183   %0 = atomicrmw xchg i8* @y, i8 %newval monotonic
184   ret i8 %0
185
186 ; ALL-LABEL: AtomicSwap8:
187
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]]
199
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]]
207
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
212 }
213
214 define signext i8 @AtomicCmpSwap8(i8 signext %oldval, i8 signext %newval) nounwind {
215 entry:
216   %pair0 = cmpxchg i8* @y, i8 %oldval, i8 %newval monotonic monotonic
217   %0 = extractvalue { i8, i1 } %pair0, 0
218   ret i8 %0
219
220 ; ALL-LABEL: AtomicCmpSwap8:
221
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]]
236
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]+]]
241
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]]
246
247 ; ALL:       $[[BB1]]:
248 ; ALL:           srlv    $[[R17:[0-9]+]], $[[R14]], $[[R5]]
249 ; ALL:           sll     $[[R18:[0-9]+]], $[[R17]], 24
250 ; ALL:           sra     $2, $[[R18]], 24
251 }
252
253 @countsint = common global i32 0, align 4
254
255 define i32 @CheckSync(i32 %v) nounwind noinline {
256 entry:
257   %0 = atomicrmw add i32* @countsint, i32 %v seq_cst
258   ret i32 %0 
259
260 ; ALL-LABEL: CheckSync:
261
262 ; ALL:           sync 0
263 ; ALL:           ll
264 ; ALL:           sc
265 ; ALL:           beq
266 ; ALL:           sync 0
267 }
268
269 ; make sure that this assertion in
270 ; TwoAddressInstructionPass::TryInstructionTransform does not fail:
271 ;
272 ; line 1203: assert(TargetRegisterInfo::isVirtualRegister(regB) &&
273 ;
274 ; it failed when MipsDAGToDAGISel::ReplaceUsesWithZeroReg replaced an
275 ; operand of an atomic instruction with register $zero. 
276 @a = external global i32
277
278 define i32 @zeroreg() nounwind {
279 entry:
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
284   ret i32 %conv
285 }