OLD | NEW |
1 ; This tests each of the supported NaCl atomic instructions for every | 1 ; This tests each of the supported NaCl atomic instructions for every |
2 ; size allowed. | 2 ; size allowed. |
3 | 3 |
4 ; RUN: %p2i -i %s --filetype=obj --disassemble --args -O2 \ | 4 ; RUN: %p2i -i %s --filetype=obj --disassemble --args -O2 \ |
5 ; RUN: | FileCheck %s | 5 ; RUN: -allow-externally-defined-symbols | FileCheck %s |
6 ; RUN: %p2i -i %s --filetype=obj --disassemble --args -O2 \ | 6 ; RUN: %p2i -i %s --filetype=obj --disassemble --args -O2 \ |
7 ; RUN: | FileCheck --check-prefix=O2 %s | 7 ; RUN: -allow-externally-defined-symbols | FileCheck --check-prefix=O2 %s |
8 ; RUN: %p2i -i %s --filetype=obj --disassemble --args -Om1 \ | 8 ; RUN: %p2i -i %s --filetype=obj --disassemble --args -Om1 \ |
9 ; RUN: | FileCheck %s | 9 ; RUN: -allow-externally-defined-symbols | FileCheck %s |
10 | 10 |
11 declare i8 @llvm.nacl.atomic.load.i8(i8*, i32) | 11 declare i8 @llvm.nacl.atomic.load.i8(i8*, i32) |
12 declare i16 @llvm.nacl.atomic.load.i16(i16*, i32) | 12 declare i16 @llvm.nacl.atomic.load.i16(i16*, i32) |
13 declare i32 @llvm.nacl.atomic.load.i32(i32*, i32) | 13 declare i32 @llvm.nacl.atomic.load.i32(i32*, i32) |
14 declare i64 @llvm.nacl.atomic.load.i64(i64*, i32) | 14 declare i64 @llvm.nacl.atomic.load.i64(i64*, i32) |
15 declare void @llvm.nacl.atomic.store.i8(i8, i8*, i32) | 15 declare void @llvm.nacl.atomic.store.i8(i8, i8*, i32) |
16 declare void @llvm.nacl.atomic.store.i16(i16, i16*, i32) | 16 declare void @llvm.nacl.atomic.store.i16(i16, i16*, i32) |
17 declare void @llvm.nacl.atomic.store.i32(i32, i32*, i32) | 17 declare void @llvm.nacl.atomic.store.i32(i32, i32*, i32) |
18 declare void @llvm.nacl.atomic.store.i64(i64, i64*, i32) | 18 declare void @llvm.nacl.atomic.store.i64(i64, i64*, i32) |
19 declare i8 @llvm.nacl.atomic.rmw.i8(i32, i8*, i8, i32) | 19 declare i8 @llvm.nacl.atomic.rmw.i8(i32, i8*, i8, i32) |
(...skipping 16 matching lines...) Expand all Loading... |
36 ; NOTE: The LLC equivalent for 16-bit atomic operations are expanded | 36 ; NOTE: The LLC equivalent for 16-bit atomic operations are expanded |
37 ; as 32-bit operations. For Subzero, assume that real 16-bit operations | 37 ; as 32-bit operations. For Subzero, assume that real 16-bit operations |
38 ; will be usable (the validator will be fixed): | 38 ; will be usable (the validator will be fixed): |
39 ; https://code.google.com/p/nativeclient/issues/detail?id=2981 | 39 ; https://code.google.com/p/nativeclient/issues/detail?id=2981 |
40 | 40 |
41 ;;; Load | 41 ;;; Load |
42 | 42 |
43 ; x86 guarantees load/store to be atomic if naturally aligned. | 43 ; x86 guarantees load/store to be atomic if naturally aligned. |
44 ; The PNaCl IR requires all atomic accesses to be naturally aligned. | 44 ; The PNaCl IR requires all atomic accesses to be naturally aligned. |
45 | 45 |
46 define i32 @test_atomic_load_8(i32 %iptr) { | 46 define internal i32 @test_atomic_load_8(i32 %iptr) { |
47 entry: | 47 entry: |
48 %ptr = inttoptr i32 %iptr to i8* | 48 %ptr = inttoptr i32 %iptr to i8* |
49 ; parameter value "6" is for the sequential consistency memory order. | 49 ; parameter value "6" is for the sequential consistency memory order. |
50 %i = call i8 @llvm.nacl.atomic.load.i8(i8* %ptr, i32 6) | 50 %i = call i8 @llvm.nacl.atomic.load.i8(i8* %ptr, i32 6) |
51 %i2 = sub i8 %i, 0 | 51 %i2 = sub i8 %i, 0 |
52 %r = zext i8 %i2 to i32 | 52 %r = zext i8 %i2 to i32 |
53 ret i32 %r | 53 ret i32 %r |
54 } | 54 } |
55 ; CHECK-LABEL: test_atomic_load_8 | 55 ; CHECK-LABEL: test_atomic_load_8 |
56 ; CHECK: mov {{.*}},DWORD | 56 ; CHECK: mov {{.*}},DWORD |
57 ; CHECK: mov {{.*}},BYTE | 57 ; CHECK: mov {{.*}},BYTE |
58 | 58 |
59 define i32 @test_atomic_load_16(i32 %iptr) { | 59 define internal i32 @test_atomic_load_16(i32 %iptr) { |
60 entry: | 60 entry: |
61 %ptr = inttoptr i32 %iptr to i16* | 61 %ptr = inttoptr i32 %iptr to i16* |
62 %i = call i16 @llvm.nacl.atomic.load.i16(i16* %ptr, i32 6) | 62 %i = call i16 @llvm.nacl.atomic.load.i16(i16* %ptr, i32 6) |
63 %i2 = sub i16 %i, 0 | 63 %i2 = sub i16 %i, 0 |
64 %r = zext i16 %i2 to i32 | 64 %r = zext i16 %i2 to i32 |
65 ret i32 %r | 65 ret i32 %r |
66 } | 66 } |
67 ; CHECK-LABEL: test_atomic_load_16 | 67 ; CHECK-LABEL: test_atomic_load_16 |
68 ; CHECK: mov {{.*}},DWORD | 68 ; CHECK: mov {{.*}},DWORD |
69 ; CHECK: mov {{.*}},WORD | 69 ; CHECK: mov {{.*}},WORD |
70 | 70 |
71 define i32 @test_atomic_load_32(i32 %iptr) { | 71 define internal i32 @test_atomic_load_32(i32 %iptr) { |
72 entry: | 72 entry: |
73 %ptr = inttoptr i32 %iptr to i32* | 73 %ptr = inttoptr i32 %iptr to i32* |
74 %r = call i32 @llvm.nacl.atomic.load.i32(i32* %ptr, i32 6) | 74 %r = call i32 @llvm.nacl.atomic.load.i32(i32* %ptr, i32 6) |
75 ret i32 %r | 75 ret i32 %r |
76 } | 76 } |
77 ; CHECK-LABEL: test_atomic_load_32 | 77 ; CHECK-LABEL: test_atomic_load_32 |
78 ; CHECK: mov {{.*}},DWORD | 78 ; CHECK: mov {{.*}},DWORD |
79 ; CHECK: mov {{.*}},DWORD | 79 ; CHECK: mov {{.*}},DWORD |
80 | 80 |
81 define i64 @test_atomic_load_64(i32 %iptr) { | 81 define internal i64 @test_atomic_load_64(i32 %iptr) { |
82 entry: | 82 entry: |
83 %ptr = inttoptr i32 %iptr to i64* | 83 %ptr = inttoptr i32 %iptr to i64* |
84 %r = call i64 @llvm.nacl.atomic.load.i64(i64* %ptr, i32 6) | 84 %r = call i64 @llvm.nacl.atomic.load.i64(i64* %ptr, i32 6) |
85 ret i64 %r | 85 ret i64 %r |
86 } | 86 } |
87 ; CHECK-LABEL: test_atomic_load_64 | 87 ; CHECK-LABEL: test_atomic_load_64 |
88 ; CHECK: movq x{{.*}},QWORD | 88 ; CHECK: movq x{{.*}},QWORD |
89 ; CHECK: movq QWORD {{.*}},x{{.*}} | 89 ; CHECK: movq QWORD {{.*}},x{{.*}} |
90 | 90 |
91 define i32 @test_atomic_load_32_with_arith(i32 %iptr) { | 91 define internal i32 @test_atomic_load_32_with_arith(i32 %iptr) { |
92 entry: | 92 entry: |
93 br label %next | 93 br label %next |
94 | 94 |
95 next: | 95 next: |
96 %ptr = inttoptr i32 %iptr to i32* | 96 %ptr = inttoptr i32 %iptr to i32* |
97 %r = call i32 @llvm.nacl.atomic.load.i32(i32* %ptr, i32 6) | 97 %r = call i32 @llvm.nacl.atomic.load.i32(i32* %ptr, i32 6) |
98 %r2 = sub i32 32, %r | 98 %r2 = sub i32 32, %r |
99 ret i32 %r2 | 99 ret i32 %r2 |
100 } | 100 } |
101 ; CHECK-LABEL: test_atomic_load_32_with_arith | 101 ; CHECK-LABEL: test_atomic_load_32_with_arith |
102 ; CHECK: mov {{.*}},DWORD | 102 ; CHECK: mov {{.*}},DWORD |
103 ; The next instruction may be a separate load or folded into an add. | 103 ; The next instruction may be a separate load or folded into an add. |
104 ; | 104 ; |
105 ; In O2 mode, we know that the load and sub are going to be fused. | 105 ; In O2 mode, we know that the load and sub are going to be fused. |
106 ; O2-LABEL: test_atomic_load_32_with_arith | 106 ; O2-LABEL: test_atomic_load_32_with_arith |
107 ; O2: mov {{.*}},DWORD | 107 ; O2: mov {{.*}},DWORD |
108 ; O2: sub {{.*}},DWORD | 108 ; O2: sub {{.*}},DWORD |
109 | 109 |
110 define i32 @test_atomic_load_32_ignored(i32 %iptr) { | 110 define internal i32 @test_atomic_load_32_ignored(i32 %iptr) { |
111 entry: | 111 entry: |
112 %ptr = inttoptr i32 %iptr to i32* | 112 %ptr = inttoptr i32 %iptr to i32* |
113 %ignored = call i32 @llvm.nacl.atomic.load.i32(i32* %ptr, i32 6) | 113 %ignored = call i32 @llvm.nacl.atomic.load.i32(i32* %ptr, i32 6) |
114 ret i32 0 | 114 ret i32 0 |
115 } | 115 } |
116 ; CHECK-LABEL: test_atomic_load_32_ignored | 116 ; CHECK-LABEL: test_atomic_load_32_ignored |
117 ; CHECK: mov {{.*}},DWORD | 117 ; CHECK: mov {{.*}},DWORD |
118 ; CHECK: mov {{.*}},DWORD | 118 ; CHECK: mov {{.*}},DWORD |
119 ; O2-LABEL: test_atomic_load_32_ignored | 119 ; O2-LABEL: test_atomic_load_32_ignored |
120 ; O2: mov {{.*}},DWORD | 120 ; O2: mov {{.*}},DWORD |
121 ; O2: mov {{.*}},DWORD | 121 ; O2: mov {{.*}},DWORD |
122 | 122 |
123 define i64 @test_atomic_load_64_ignored(i32 %iptr) { | 123 define internal i64 @test_atomic_load_64_ignored(i32 %iptr) { |
124 entry: | 124 entry: |
125 %ptr = inttoptr i32 %iptr to i64* | 125 %ptr = inttoptr i32 %iptr to i64* |
126 %ignored = call i64 @llvm.nacl.atomic.load.i64(i64* %ptr, i32 6) | 126 %ignored = call i64 @llvm.nacl.atomic.load.i64(i64* %ptr, i32 6) |
127 ret i64 0 | 127 ret i64 0 |
128 } | 128 } |
129 ; CHECK-LABEL: test_atomic_load_64_ignored | 129 ; CHECK-LABEL: test_atomic_load_64_ignored |
130 ; CHECK: movq x{{.*}},QWORD | 130 ; CHECK: movq x{{.*}},QWORD |
131 ; CHECK: movq QWORD {{.*}},x{{.*}} | 131 ; CHECK: movq QWORD {{.*}},x{{.*}} |
132 | 132 |
133 ;;; Store | 133 ;;; Store |
134 | 134 |
135 define void @test_atomic_store_8(i32 %iptr, i32 %v) { | 135 define internal void @test_atomic_store_8(i32 %iptr, i32 %v) { |
136 entry: | 136 entry: |
137 %truncv = trunc i32 %v to i8 | 137 %truncv = trunc i32 %v to i8 |
138 %ptr = inttoptr i32 %iptr to i8* | 138 %ptr = inttoptr i32 %iptr to i8* |
139 call void @llvm.nacl.atomic.store.i8(i8 %truncv, i8* %ptr, i32 6) | 139 call void @llvm.nacl.atomic.store.i8(i8 %truncv, i8* %ptr, i32 6) |
140 ret void | 140 ret void |
141 } | 141 } |
142 ; CHECK-LABEL: test_atomic_store_8 | 142 ; CHECK-LABEL: test_atomic_store_8 |
143 ; CHECK: mov BYTE | 143 ; CHECK: mov BYTE |
144 ; CHECK: mfence | 144 ; CHECK: mfence |
145 | 145 |
146 define void @test_atomic_store_16(i32 %iptr, i32 %v) { | 146 define internal void @test_atomic_store_16(i32 %iptr, i32 %v) { |
147 entry: | 147 entry: |
148 %truncv = trunc i32 %v to i16 | 148 %truncv = trunc i32 %v to i16 |
149 %ptr = inttoptr i32 %iptr to i16* | 149 %ptr = inttoptr i32 %iptr to i16* |
150 call void @llvm.nacl.atomic.store.i16(i16 %truncv, i16* %ptr, i32 6) | 150 call void @llvm.nacl.atomic.store.i16(i16 %truncv, i16* %ptr, i32 6) |
151 ret void | 151 ret void |
152 } | 152 } |
153 ; CHECK-LABEL: test_atomic_store_16 | 153 ; CHECK-LABEL: test_atomic_store_16 |
154 ; CHECK: mov WORD | 154 ; CHECK: mov WORD |
155 ; CHECK: mfence | 155 ; CHECK: mfence |
156 | 156 |
157 define void @test_atomic_store_32(i32 %iptr, i32 %v) { | 157 define internal void @test_atomic_store_32(i32 %iptr, i32 %v) { |
158 entry: | 158 entry: |
159 %ptr = inttoptr i32 %iptr to i32* | 159 %ptr = inttoptr i32 %iptr to i32* |
160 call void @llvm.nacl.atomic.store.i32(i32 %v, i32* %ptr, i32 6) | 160 call void @llvm.nacl.atomic.store.i32(i32 %v, i32* %ptr, i32 6) |
161 ret void | 161 ret void |
162 } | 162 } |
163 ; CHECK-LABEL: test_atomic_store_32 | 163 ; CHECK-LABEL: test_atomic_store_32 |
164 ; CHECK: mov DWORD | 164 ; CHECK: mov DWORD |
165 ; CHECK: mfence | 165 ; CHECK: mfence |
166 | 166 |
167 define void @test_atomic_store_64(i32 %iptr, i64 %v) { | 167 define internal void @test_atomic_store_64(i32 %iptr, i64 %v) { |
168 entry: | 168 entry: |
169 %ptr = inttoptr i32 %iptr to i64* | 169 %ptr = inttoptr i32 %iptr to i64* |
170 call void @llvm.nacl.atomic.store.i64(i64 %v, i64* %ptr, i32 6) | 170 call void @llvm.nacl.atomic.store.i64(i64 %v, i64* %ptr, i32 6) |
171 ret void | 171 ret void |
172 } | 172 } |
173 ; CHECK-LABEL: test_atomic_store_64 | 173 ; CHECK-LABEL: test_atomic_store_64 |
174 ; CHECK: movq x{{.*}},QWORD | 174 ; CHECK: movq x{{.*}},QWORD |
175 ; CHECK: movq QWORD {{.*}},x{{.*}} | 175 ; CHECK: movq QWORD {{.*}},x{{.*}} |
176 ; CHECK: mfence | 176 ; CHECK: mfence |
177 | 177 |
178 define void @test_atomic_store_64_const(i32 %iptr) { | 178 define internal void @test_atomic_store_64_const(i32 %iptr) { |
179 entry: | 179 entry: |
180 %ptr = inttoptr i32 %iptr to i64* | 180 %ptr = inttoptr i32 %iptr to i64* |
181 call void @llvm.nacl.atomic.store.i64(i64 12345678901234, i64* %ptr, i32 6) | 181 call void @llvm.nacl.atomic.store.i64(i64 12345678901234, i64* %ptr, i32 6) |
182 ret void | 182 ret void |
183 } | 183 } |
184 ; CHECK-LABEL: test_atomic_store_64_const | 184 ; CHECK-LABEL: test_atomic_store_64_const |
185 ; CHECK: mov {{.*}},0x73ce2ff2 | 185 ; CHECK: mov {{.*}},0x73ce2ff2 |
186 ; CHECK: mov {{.*}},0xb3a | 186 ; CHECK: mov {{.*}},0xb3a |
187 ; CHECK: movq x{{.*}},QWORD | 187 ; CHECK: movq x{{.*}},QWORD |
188 ; CHECK: movq QWORD {{.*}},x{{.*}} | 188 ; CHECK: movq QWORD {{.*}},x{{.*}} |
189 ; CHECK: mfence | 189 ; CHECK: mfence |
190 | 190 |
191 | 191 |
192 ;;; RMW | 192 ;;; RMW |
193 | 193 |
194 ;; add | 194 ;; add |
195 | 195 |
196 define i32 @test_atomic_rmw_add_8(i32 %iptr, i32 %v) { | 196 define internal i32 @test_atomic_rmw_add_8(i32 %iptr, i32 %v) { |
197 entry: | 197 entry: |
198 %trunc = trunc i32 %v to i8 | 198 %trunc = trunc i32 %v to i8 |
199 %ptr = inttoptr i32 %iptr to i8* | 199 %ptr = inttoptr i32 %iptr to i8* |
200 ; "1" is an atomic add, and "6" is sequential consistency. | 200 ; "1" is an atomic add, and "6" is sequential consistency. |
201 %a = call i8 @llvm.nacl.atomic.rmw.i8(i32 1, i8* %ptr, i8 %trunc, i32 6) | 201 %a = call i8 @llvm.nacl.atomic.rmw.i8(i32 1, i8* %ptr, i8 %trunc, i32 6) |
202 %a_ext = zext i8 %a to i32 | 202 %a_ext = zext i8 %a to i32 |
203 ret i32 %a_ext | 203 ret i32 %a_ext |
204 } | 204 } |
205 ; CHECK-LABEL: test_atomic_rmw_add_8 | 205 ; CHECK-LABEL: test_atomic_rmw_add_8 |
206 ; CHECK: lock xadd BYTE {{.*}},[[REG:.*]] | 206 ; CHECK: lock xadd BYTE {{.*}},[[REG:.*]] |
207 ; CHECK: {{mov|movzx}} {{.*}},[[REG]] | 207 ; CHECK: {{mov|movzx}} {{.*}},[[REG]] |
208 | 208 |
209 define i32 @test_atomic_rmw_add_16(i32 %iptr, i32 %v) { | 209 define internal i32 @test_atomic_rmw_add_16(i32 %iptr, i32 %v) { |
210 entry: | 210 entry: |
211 %trunc = trunc i32 %v to i16 | 211 %trunc = trunc i32 %v to i16 |
212 %ptr = inttoptr i32 %iptr to i16* | 212 %ptr = inttoptr i32 %iptr to i16* |
213 %a = call i16 @llvm.nacl.atomic.rmw.i16(i32 1, i16* %ptr, i16 %trunc, i32 6) | 213 %a = call i16 @llvm.nacl.atomic.rmw.i16(i32 1, i16* %ptr, i16 %trunc, i32 6) |
214 %a_ext = zext i16 %a to i32 | 214 %a_ext = zext i16 %a to i32 |
215 ret i32 %a_ext | 215 ret i32 %a_ext |
216 } | 216 } |
217 ; CHECK-LABEL: test_atomic_rmw_add_16 | 217 ; CHECK-LABEL: test_atomic_rmw_add_16 |
218 ; CHECK: lock xadd WORD {{.*}},[[REG:.*]] | 218 ; CHECK: lock xadd WORD {{.*}},[[REG:.*]] |
219 ; CHECK: {{mov|movzx}} {{.*}},[[REG]] | 219 ; CHECK: {{mov|movzx}} {{.*}},[[REG]] |
220 | 220 |
221 define i32 @test_atomic_rmw_add_32(i32 %iptr, i32 %v) { | 221 define internal i32 @test_atomic_rmw_add_32(i32 %iptr, i32 %v) { |
222 entry: | 222 entry: |
223 %ptr = inttoptr i32 %iptr to i32* | 223 %ptr = inttoptr i32 %iptr to i32* |
224 %a = call i32 @llvm.nacl.atomic.rmw.i32(i32 1, i32* %ptr, i32 %v, i32 6) | 224 %a = call i32 @llvm.nacl.atomic.rmw.i32(i32 1, i32* %ptr, i32 %v, i32 6) |
225 ret i32 %a | 225 ret i32 %a |
226 } | 226 } |
227 ; CHECK-LABEL: test_atomic_rmw_add_32 | 227 ; CHECK-LABEL: test_atomic_rmw_add_32 |
228 ; CHECK: lock xadd DWORD {{.*}},[[REG:.*]] | 228 ; CHECK: lock xadd DWORD {{.*}},[[REG:.*]] |
229 ; CHECK: mov {{.*}},[[REG]] | 229 ; CHECK: mov {{.*}},[[REG]] |
230 | 230 |
231 define i64 @test_atomic_rmw_add_64(i32 %iptr, i64 %v) { | 231 define internal i64 @test_atomic_rmw_add_64(i32 %iptr, i64 %v) { |
232 entry: | 232 entry: |
233 %ptr = inttoptr i32 %iptr to i64* | 233 %ptr = inttoptr i32 %iptr to i64* |
234 %a = call i64 @llvm.nacl.atomic.rmw.i64(i32 1, i64* %ptr, i64 %v, i32 6) | 234 %a = call i64 @llvm.nacl.atomic.rmw.i64(i32 1, i64* %ptr, i64 %v, i32 6) |
235 ret i64 %a | 235 ret i64 %a |
236 } | 236 } |
237 ; CHECK-LABEL: test_atomic_rmw_add_64 | 237 ; CHECK-LABEL: test_atomic_rmw_add_64 |
238 ; CHECK: push ebx | 238 ; CHECK: push ebx |
239 ; CHECK: mov eax,DWORD PTR [{{.*}}] | 239 ; CHECK: mov eax,DWORD PTR [{{.*}}] |
240 ; CHECK: mov edx,DWORD PTR [{{.*}}+0x4] | 240 ; CHECK: mov edx,DWORD PTR [{{.*}}+0x4] |
241 ; CHECK: [[LABEL:[^ ]*]]: {{.*}} mov ebx,eax | 241 ; CHECK: [[LABEL:[^ ]*]]: {{.*}} mov ebx,eax |
242 ; RHS of add cannot be any of the e[abcd]x regs because they are | 242 ; RHS of add cannot be any of the e[abcd]x regs because they are |
243 ; clobbered in the loop, and the RHS needs to be remain live. | 243 ; clobbered in the loop, and the RHS needs to be remain live. |
244 ; CHECK: add ebx,{{.*e.[^x]}} | 244 ; CHECK: add ebx,{{.*e.[^x]}} |
245 ; CHECK: mov ecx,edx | 245 ; CHECK: mov ecx,edx |
246 ; CHECK: adc ecx,{{.*e.[^x]}} | 246 ; CHECK: adc ecx,{{.*e.[^x]}} |
247 ; Ptr cannot be eax, ebx, ecx, or edx (used up for the expected and desired). | 247 ; Ptr cannot be eax, ebx, ecx, or edx (used up for the expected and desired). |
248 ; It can be esi, edi, or ebp though, for example (so we need to be careful | 248 ; It can be esi, edi, or ebp though, for example (so we need to be careful |
249 ; about rejecting eb* and ed*.) | 249 ; about rejecting eb* and ed*.) |
250 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}} | 250 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}} |
251 ; CHECK: jne [[LABEL]] | 251 ; CHECK: jne [[LABEL]] |
252 | 252 |
253 ; Same test as above, but with a global address to test FakeUse issues. | 253 ; Same test as above, but with a global address to test FakeUse issues. |
254 define i64 @test_atomic_rmw_add_64_global(i64 %v) { | 254 define internal i64 @test_atomic_rmw_add_64_global(i64 %v) { |
255 entry: | 255 entry: |
256 %ptr = bitcast [8 x i8]* @Global64 to i64* | 256 %ptr = bitcast [8 x i8]* @Global64 to i64* |
257 %a = call i64 @llvm.nacl.atomic.rmw.i64(i32 1, i64* %ptr, i64 %v, i32 6) | 257 %a = call i64 @llvm.nacl.atomic.rmw.i64(i32 1, i64* %ptr, i64 %v, i32 6) |
258 ret i64 %a | 258 ret i64 %a |
259 } | 259 } |
260 ; CHECK-LABEL: test_atomic_rmw_add_64_global | 260 ; CHECK-LABEL: test_atomic_rmw_add_64_global |
261 | 261 |
262 ; Test with some more register pressure. When we have an alloca, ebp is | 262 ; Test with some more register pressure. When we have an alloca, ebp is |
263 ; used to manage the stack frame, so it cannot be used as a register either. | 263 ; used to manage the stack frame, so it cannot be used as a register either. |
264 declare void @use_ptr(i32 %iptr) | 264 declare void @use_ptr(i32 %iptr) |
265 | 265 |
266 define i64 @test_atomic_rmw_add_64_alloca(i32 %iptr, i64 %v) { | 266 define internal i64 @test_atomic_rmw_add_64_alloca(i32 %iptr, i64 %v) { |
267 entry: | 267 entry: |
268 br label %eblock ; Disable alloca optimization | 268 br label %eblock ; Disable alloca optimization |
269 eblock: | 269 eblock: |
270 %alloca_ptr = alloca i8, i32 16, align 16 | 270 %alloca_ptr = alloca i8, i32 16, align 16 |
271 %ptr = inttoptr i32 %iptr to i64* | 271 %ptr = inttoptr i32 %iptr to i64* |
272 %old = call i64 @llvm.nacl.atomic.rmw.i64(i32 1, i64* %ptr, i64 %v, i32 6) | 272 %old = call i64 @llvm.nacl.atomic.rmw.i64(i32 1, i64* %ptr, i64 %v, i32 6) |
273 store i8 0, i8* %alloca_ptr, align 1 | 273 store i8 0, i8* %alloca_ptr, align 1 |
274 store i8 1, i8* %alloca_ptr, align 1 | 274 store i8 1, i8* %alloca_ptr, align 1 |
275 store i8 2, i8* %alloca_ptr, align 1 | 275 store i8 2, i8* %alloca_ptr, align 1 |
276 store i8 3, i8* %alloca_ptr, align 1 | 276 store i8 3, i8* %alloca_ptr, align 1 |
277 %__5 = ptrtoint i8* %alloca_ptr to i32 | 277 %__5 = ptrtoint i8* %alloca_ptr to i32 |
278 call void @use_ptr(i32 %__5) | 278 call void @use_ptr(i32 %__5) |
279 ret i64 %old | 279 ret i64 %old |
280 } | 280 } |
281 ; CHECK-LABEL: test_atomic_rmw_add_64_alloca | 281 ; CHECK-LABEL: test_atomic_rmw_add_64_alloca |
282 ; CHECK: push ebx | 282 ; CHECK: push ebx |
283 ; CHECK-DAG: mov edx | 283 ; CHECK-DAG: mov edx |
284 ; CHECK-DAG: mov eax | 284 ; CHECK-DAG: mov eax |
285 ; CHECK-DAG: mov ecx | 285 ; CHECK-DAG: mov ecx |
286 ; CHECK-DAG: mov ebx | 286 ; CHECK-DAG: mov ebx |
287 ; Ptr cannot be eax, ebx, ecx, or edx (used up for the expected and desired). | 287 ; Ptr cannot be eax, ebx, ecx, or edx (used up for the expected and desired). |
288 ; It also cannot be ebp since we use that for alloca. Also make sure it's | 288 ; It also cannot be ebp since we use that for alloca. Also make sure it's |
289 ; not esp, since that's the stack pointer and mucking with it will break | 289 ; not esp, since that's the stack pointer and mucking with it will break |
290 ; the later use_ptr function call. | 290 ; the later use_ptr function call. |
291 ; That pretty much leaves esi, or edi as the only viable registers. | 291 ; That pretty much leaves esi, or edi as the only viable registers. |
292 ; CHECK: lock cmpxchg8b QWORD PTR [e{{[ds]}}i] | 292 ; CHECK: lock cmpxchg8b QWORD PTR [e{{[ds]}}i] |
293 ; CHECK: call {{.*}} R_{{.*}} use_ptr | 293 ; CHECK: call {{.*}} R_{{.*}} use_ptr |
294 | 294 |
295 define i32 @test_atomic_rmw_add_32_ignored(i32 %iptr, i32 %v) { | 295 define internal i32 @test_atomic_rmw_add_32_ignored(i32 %iptr, i32 %v) { |
296 entry: | 296 entry: |
297 %ptr = inttoptr i32 %iptr to i32* | 297 %ptr = inttoptr i32 %iptr to i32* |
298 %ignored = call i32 @llvm.nacl.atomic.rmw.i32(i32 1, i32* %ptr, i32 %v, i32 6) | 298 %ignored = call i32 @llvm.nacl.atomic.rmw.i32(i32 1, i32* %ptr, i32 %v, i32 6) |
299 ret i32 %v | 299 ret i32 %v |
300 } | 300 } |
301 ; Technically this could use "lock add" instead of "lock xadd", if liveness | 301 ; Technically this could use "lock add" instead of "lock xadd", if liveness |
302 ; tells us that the destination variable is dead. | 302 ; tells us that the destination variable is dead. |
303 ; CHECK-LABEL: test_atomic_rmw_add_32_ignored | 303 ; CHECK-LABEL: test_atomic_rmw_add_32_ignored |
304 ; CHECK: lock xadd DWORD {{.*}},[[REG:.*]] | 304 ; CHECK: lock xadd DWORD {{.*}},[[REG:.*]] |
305 | 305 |
306 ; Atomic RMW 64 needs to be expanded into its own loop. | 306 ; Atomic RMW 64 needs to be expanded into its own loop. |
307 ; Make sure that works w/ non-trivial function bodies. | 307 ; Make sure that works w/ non-trivial function bodies. |
308 define i64 @test_atomic_rmw_add_64_loop(i32 %iptr, i64 %v) { | 308 define internal i64 @test_atomic_rmw_add_64_loop(i32 %iptr, i64 %v) { |
309 entry: | 309 entry: |
310 %x = icmp ult i64 %v, 100 | 310 %x = icmp ult i64 %v, 100 |
311 br i1 %x, label %err, label %loop | 311 br i1 %x, label %err, label %loop |
312 | 312 |
313 loop: | 313 loop: |
314 %v_next = phi i64 [ %v, %entry ], [ %next, %loop ] | 314 %v_next = phi i64 [ %v, %entry ], [ %next, %loop ] |
315 %ptr = inttoptr i32 %iptr to i64* | 315 %ptr = inttoptr i32 %iptr to i64* |
316 %next = call i64 @llvm.nacl.atomic.rmw.i64(i32 1, i64* %ptr, i64 %v_next, i32
6) | 316 %next = call i64 @llvm.nacl.atomic.rmw.i64(i32 1, i64* %ptr, i64 %v_next, i32
6) |
317 %success = icmp eq i64 %next, 100 | 317 %success = icmp eq i64 %next, 100 |
318 br i1 %success, label %done, label %loop | 318 br i1 %success, label %done, label %loop |
(...skipping 10 matching lines...) Expand all Loading... |
329 ; CHECK: mov edx,DWORD PTR [{{.*}}+0x4] | 329 ; CHECK: mov edx,DWORD PTR [{{.*}}+0x4] |
330 ; CHECK: [[LABEL:[^ ]*]]: {{.*}} mov ebx,eax | 330 ; CHECK: [[LABEL:[^ ]*]]: {{.*}} mov ebx,eax |
331 ; CHECK: add ebx,{{.*e.[^x]}} | 331 ; CHECK: add ebx,{{.*e.[^x]}} |
332 ; CHECK: mov ecx,edx | 332 ; CHECK: mov ecx,edx |
333 ; CHECK: adc ecx,{{.*e.[^x]}} | 333 ; CHECK: adc ecx,{{.*e.[^x]}} |
334 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}}+0x0] | 334 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}}+0x0] |
335 ; CHECK: jne [[LABEL]] | 335 ; CHECK: jne [[LABEL]] |
336 | 336 |
337 ;; sub | 337 ;; sub |
338 | 338 |
339 define i32 @test_atomic_rmw_sub_8(i32 %iptr, i32 %v) { | 339 define internal i32 @test_atomic_rmw_sub_8(i32 %iptr, i32 %v) { |
340 entry: | 340 entry: |
341 %trunc = trunc i32 %v to i8 | 341 %trunc = trunc i32 %v to i8 |
342 %ptr = inttoptr i32 %iptr to i8* | 342 %ptr = inttoptr i32 %iptr to i8* |
343 %a = call i8 @llvm.nacl.atomic.rmw.i8(i32 2, i8* %ptr, i8 %trunc, i32 6) | 343 %a = call i8 @llvm.nacl.atomic.rmw.i8(i32 2, i8* %ptr, i8 %trunc, i32 6) |
344 %a_ext = zext i8 %a to i32 | 344 %a_ext = zext i8 %a to i32 |
345 ret i32 %a_ext | 345 ret i32 %a_ext |
346 } | 346 } |
347 ; CHECK-LABEL: test_atomic_rmw_sub_8 | 347 ; CHECK-LABEL: test_atomic_rmw_sub_8 |
348 ; CHECK: neg [[REG:.*]] | 348 ; CHECK: neg [[REG:.*]] |
349 ; CHECK: lock xadd BYTE {{.*}},[[REG]] | 349 ; CHECK: lock xadd BYTE {{.*}},[[REG]] |
350 ; CHECK: {{mov|movzx}} {{.*}},[[REG]] | 350 ; CHECK: {{mov|movzx}} {{.*}},[[REG]] |
351 | 351 |
352 define i32 @test_atomic_rmw_sub_16(i32 %iptr, i32 %v) { | 352 define internal i32 @test_atomic_rmw_sub_16(i32 %iptr, i32 %v) { |
353 entry: | 353 entry: |
354 %trunc = trunc i32 %v to i16 | 354 %trunc = trunc i32 %v to i16 |
355 %ptr = inttoptr i32 %iptr to i16* | 355 %ptr = inttoptr i32 %iptr to i16* |
356 %a = call i16 @llvm.nacl.atomic.rmw.i16(i32 2, i16* %ptr, i16 %trunc, i32 6) | 356 %a = call i16 @llvm.nacl.atomic.rmw.i16(i32 2, i16* %ptr, i16 %trunc, i32 6) |
357 %a_ext = zext i16 %a to i32 | 357 %a_ext = zext i16 %a to i32 |
358 ret i32 %a_ext | 358 ret i32 %a_ext |
359 } | 359 } |
360 ; CHECK-LABEL: test_atomic_rmw_sub_16 | 360 ; CHECK-LABEL: test_atomic_rmw_sub_16 |
361 ; CHECK: neg [[REG:.*]] | 361 ; CHECK: neg [[REG:.*]] |
362 ; CHECK: lock xadd WORD {{.*}},[[REG]] | 362 ; CHECK: lock xadd WORD {{.*}},[[REG]] |
363 ; CHECK: {{mov|movzx}} {{.*}},[[REG]] | 363 ; CHECK: {{mov|movzx}} {{.*}},[[REG]] |
364 | 364 |
365 define i32 @test_atomic_rmw_sub_32(i32 %iptr, i32 %v) { | 365 define internal i32 @test_atomic_rmw_sub_32(i32 %iptr, i32 %v) { |
366 entry: | 366 entry: |
367 %ptr = inttoptr i32 %iptr to i32* | 367 %ptr = inttoptr i32 %iptr to i32* |
368 %a = call i32 @llvm.nacl.atomic.rmw.i32(i32 2, i32* %ptr, i32 %v, i32 6) | 368 %a = call i32 @llvm.nacl.atomic.rmw.i32(i32 2, i32* %ptr, i32 %v, i32 6) |
369 ret i32 %a | 369 ret i32 %a |
370 } | 370 } |
371 ; CHECK-LABEL: test_atomic_rmw_sub_32 | 371 ; CHECK-LABEL: test_atomic_rmw_sub_32 |
372 ; CHECK: neg [[REG:.*]] | 372 ; CHECK: neg [[REG:.*]] |
373 ; CHECK: lock xadd DWORD {{.*}},[[REG]] | 373 ; CHECK: lock xadd DWORD {{.*}},[[REG]] |
374 ; CHECK: mov {{.*}},[[REG]] | 374 ; CHECK: mov {{.*}},[[REG]] |
375 | 375 |
376 define i64 @test_atomic_rmw_sub_64(i32 %iptr, i64 %v) { | 376 define internal i64 @test_atomic_rmw_sub_64(i32 %iptr, i64 %v) { |
377 entry: | 377 entry: |
378 %ptr = inttoptr i32 %iptr to i64* | 378 %ptr = inttoptr i32 %iptr to i64* |
379 %a = call i64 @llvm.nacl.atomic.rmw.i64(i32 2, i64* %ptr, i64 %v, i32 6) | 379 %a = call i64 @llvm.nacl.atomic.rmw.i64(i32 2, i64* %ptr, i64 %v, i32 6) |
380 ret i64 %a | 380 ret i64 %a |
381 } | 381 } |
382 ; CHECK-LABEL: test_atomic_rmw_sub_64 | 382 ; CHECK-LABEL: test_atomic_rmw_sub_64 |
383 ; CHECK: push ebx | 383 ; CHECK: push ebx |
384 ; CHECK: mov eax,DWORD PTR [{{.*}}] | 384 ; CHECK: mov eax,DWORD PTR [{{.*}}] |
385 ; CHECK: mov edx,DWORD PTR [{{.*}}+0x4] | 385 ; CHECK: mov edx,DWORD PTR [{{.*}}+0x4] |
386 ; CHECK: [[LABEL:[^ ]*]]: {{.*}} mov ebx,eax | 386 ; CHECK: [[LABEL:[^ ]*]]: {{.*}} mov ebx,eax |
387 ; CHECK: sub ebx,{{.*e.[^x]}} | 387 ; CHECK: sub ebx,{{.*e.[^x]}} |
388 ; CHECK: mov ecx,edx | 388 ; CHECK: mov ecx,edx |
389 ; CHECK: sbb ecx,{{.*e.[^x]}} | 389 ; CHECK: sbb ecx,{{.*e.[^x]}} |
390 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}} | 390 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}} |
391 ; CHECK: jne [[LABEL]] | 391 ; CHECK: jne [[LABEL]] |
392 | 392 |
393 | 393 |
394 define i32 @test_atomic_rmw_sub_32_ignored(i32 %iptr, i32 %v) { | 394 define internal i32 @test_atomic_rmw_sub_32_ignored(i32 %iptr, i32 %v) { |
395 entry: | 395 entry: |
396 %ptr = inttoptr i32 %iptr to i32* | 396 %ptr = inttoptr i32 %iptr to i32* |
397 %ignored = call i32 @llvm.nacl.atomic.rmw.i32(i32 2, i32* %ptr, i32 %v, i32 6) | 397 %ignored = call i32 @llvm.nacl.atomic.rmw.i32(i32 2, i32* %ptr, i32 %v, i32 6) |
398 ret i32 %v | 398 ret i32 %v |
399 } | 399 } |
400 ; Could use "lock sub" instead of "neg; lock xadd" | 400 ; Could use "lock sub" instead of "neg; lock xadd" |
401 ; CHECK-LABEL: test_atomic_rmw_sub_32_ignored | 401 ; CHECK-LABEL: test_atomic_rmw_sub_32_ignored |
402 ; CHECK: neg [[REG:.*]] | 402 ; CHECK: neg [[REG:.*]] |
403 ; CHECK: lock xadd DWORD {{.*}},[[REG]] | 403 ; CHECK: lock xadd DWORD {{.*}},[[REG]] |
404 | 404 |
405 ;; or | 405 ;; or |
406 | 406 |
407 define i32 @test_atomic_rmw_or_8(i32 %iptr, i32 %v) { | 407 define internal i32 @test_atomic_rmw_or_8(i32 %iptr, i32 %v) { |
408 entry: | 408 entry: |
409 %trunc = trunc i32 %v to i8 | 409 %trunc = trunc i32 %v to i8 |
410 %ptr = inttoptr i32 %iptr to i8* | 410 %ptr = inttoptr i32 %iptr to i8* |
411 %a = call i8 @llvm.nacl.atomic.rmw.i8(i32 3, i8* %ptr, i8 %trunc, i32 6) | 411 %a = call i8 @llvm.nacl.atomic.rmw.i8(i32 3, i8* %ptr, i8 %trunc, i32 6) |
412 %a_ext = zext i8 %a to i32 | 412 %a_ext = zext i8 %a to i32 |
413 ret i32 %a_ext | 413 ret i32 %a_ext |
414 } | 414 } |
415 ; CHECK-LABEL: test_atomic_rmw_or_8 | 415 ; CHECK-LABEL: test_atomic_rmw_or_8 |
416 ; CHECK: mov al,BYTE PTR | 416 ; CHECK: mov al,BYTE PTR |
417 ; Dest cannot be eax here, because eax is used for the old value. Also want | 417 ; Dest cannot be eax here, because eax is used for the old value. Also want |
418 ; to make sure that cmpxchg's source is the same register. | 418 ; to make sure that cmpxchg's source is the same register. |
419 ; CHECK: or [[REG:[^a].]] | 419 ; CHECK: or [[REG:[^a].]] |
420 ; CHECK: lock cmpxchg BYTE PTR [e{{[^a].}}],[[REG]] | 420 ; CHECK: lock cmpxchg BYTE PTR [e{{[^a].}}],[[REG]] |
421 ; CHECK: jne | 421 ; CHECK: jne |
422 | 422 |
423 ; Same test as above, but with a global address to test FakeUse issues. | 423 ; Same test as above, but with a global address to test FakeUse issues. |
424 define i32 @test_atomic_rmw_or_8_global(i32 %v) { | 424 define internal i32 @test_atomic_rmw_or_8_global(i32 %v) { |
425 entry: | 425 entry: |
426 %trunc = trunc i32 %v to i8 | 426 %trunc = trunc i32 %v to i8 |
427 %ptr = bitcast [1 x i8]* @Global8 to i8* | 427 %ptr = bitcast [1 x i8]* @Global8 to i8* |
428 %a = call i8 @llvm.nacl.atomic.rmw.i8(i32 3, i8* %ptr, i8 %trunc, i32 6) | 428 %a = call i8 @llvm.nacl.atomic.rmw.i8(i32 3, i8* %ptr, i8 %trunc, i32 6) |
429 %a_ext = zext i8 %a to i32 | 429 %a_ext = zext i8 %a to i32 |
430 ret i32 %a_ext | 430 ret i32 %a_ext |
431 } | 431 } |
432 ; CHECK-LABEL: test_atomic_rmw_or_8_global | 432 ; CHECK-LABEL: test_atomic_rmw_or_8_global |
433 | 433 |
434 define i32 @test_atomic_rmw_or_16(i32 %iptr, i32 %v) { | 434 define internal i32 @test_atomic_rmw_or_16(i32 %iptr, i32 %v) { |
435 entry: | 435 entry: |
436 %trunc = trunc i32 %v to i16 | 436 %trunc = trunc i32 %v to i16 |
437 %ptr = inttoptr i32 %iptr to i16* | 437 %ptr = inttoptr i32 %iptr to i16* |
438 %a = call i16 @llvm.nacl.atomic.rmw.i16(i32 3, i16* %ptr, i16 %trunc, i32 6) | 438 %a = call i16 @llvm.nacl.atomic.rmw.i16(i32 3, i16* %ptr, i16 %trunc, i32 6) |
439 %a_ext = zext i16 %a to i32 | 439 %a_ext = zext i16 %a to i32 |
440 ret i32 %a_ext | 440 ret i32 %a_ext |
441 } | 441 } |
442 ; CHECK-LABEL: test_atomic_rmw_or_16 | 442 ; CHECK-LABEL: test_atomic_rmw_or_16 |
443 ; CHECK: mov ax,WORD PTR | 443 ; CHECK: mov ax,WORD PTR |
444 ; CHECK: or [[REG:[^a].]] | 444 ; CHECK: or [[REG:[^a].]] |
445 ; CHECK: lock cmpxchg WORD PTR [e{{[^a].}}],[[REG]] | 445 ; CHECK: lock cmpxchg WORD PTR [e{{[^a].}}],[[REG]] |
446 ; CHECK: jne | 446 ; CHECK: jne |
447 | 447 |
448 ; Same test as above, but with a global address to test FakeUse issues. | 448 ; Same test as above, but with a global address to test FakeUse issues. |
449 define i32 @test_atomic_rmw_or_16_global(i32 %v) { | 449 define internal i32 @test_atomic_rmw_or_16_global(i32 %v) { |
450 entry: | 450 entry: |
451 %trunc = trunc i32 %v to i16 | 451 %trunc = trunc i32 %v to i16 |
452 %ptr = bitcast [2 x i8]* @Global16 to i16* | 452 %ptr = bitcast [2 x i8]* @Global16 to i16* |
453 %a = call i16 @llvm.nacl.atomic.rmw.i16(i32 3, i16* %ptr, i16 %trunc, i32 6) | 453 %a = call i16 @llvm.nacl.atomic.rmw.i16(i32 3, i16* %ptr, i16 %trunc, i32 6) |
454 %a_ext = zext i16 %a to i32 | 454 %a_ext = zext i16 %a to i32 |
455 ret i32 %a_ext | 455 ret i32 %a_ext |
456 } | 456 } |
457 ; CHECK-LABEL: test_atomic_rmw_or_16_global | 457 ; CHECK-LABEL: test_atomic_rmw_or_16_global |
458 | 458 |
459 define i32 @test_atomic_rmw_or_32(i32 %iptr, i32 %v) { | 459 define internal i32 @test_atomic_rmw_or_32(i32 %iptr, i32 %v) { |
460 entry: | 460 entry: |
461 %ptr = inttoptr i32 %iptr to i32* | 461 %ptr = inttoptr i32 %iptr to i32* |
462 %a = call i32 @llvm.nacl.atomic.rmw.i32(i32 3, i32* %ptr, i32 %v, i32 6) | 462 %a = call i32 @llvm.nacl.atomic.rmw.i32(i32 3, i32* %ptr, i32 %v, i32 6) |
463 ret i32 %a | 463 ret i32 %a |
464 } | 464 } |
465 ; CHECK-LABEL: test_atomic_rmw_or_32 | 465 ; CHECK-LABEL: test_atomic_rmw_or_32 |
466 ; CHECK: mov eax,DWORD PTR | 466 ; CHECK: mov eax,DWORD PTR |
467 ; CHECK: or [[REG:e[^a].]] | 467 ; CHECK: or [[REG:e[^a].]] |
468 ; CHECK: lock cmpxchg DWORD PTR [e{{[^a].}}],[[REG]] | 468 ; CHECK: lock cmpxchg DWORD PTR [e{{[^a].}}],[[REG]] |
469 ; CHECK: jne | 469 ; CHECK: jne |
470 | 470 |
471 ; Same test as above, but with a global address to test FakeUse issues. | 471 ; Same test as above, but with a global address to test FakeUse issues. |
472 define i32 @test_atomic_rmw_or_32_global(i32 %v) { | 472 define internal i32 @test_atomic_rmw_or_32_global(i32 %v) { |
473 entry: | 473 entry: |
474 %ptr = bitcast [4 x i8]* @Global32 to i32* | 474 %ptr = bitcast [4 x i8]* @Global32 to i32* |
475 %a = call i32 @llvm.nacl.atomic.rmw.i32(i32 3, i32* %ptr, i32 %v, i32 6) | 475 %a = call i32 @llvm.nacl.atomic.rmw.i32(i32 3, i32* %ptr, i32 %v, i32 6) |
476 ret i32 %a | 476 ret i32 %a |
477 } | 477 } |
478 ; CHECK-LABEL: test_atomic_rmw_or_32_global | 478 ; CHECK-LABEL: test_atomic_rmw_or_32_global |
479 | 479 |
480 define i64 @test_atomic_rmw_or_64(i32 %iptr, i64 %v) { | 480 define internal i64 @test_atomic_rmw_or_64(i32 %iptr, i64 %v) { |
481 entry: | 481 entry: |
482 %ptr = inttoptr i32 %iptr to i64* | 482 %ptr = inttoptr i32 %iptr to i64* |
483 %a = call i64 @llvm.nacl.atomic.rmw.i64(i32 3, i64* %ptr, i64 %v, i32 6) | 483 %a = call i64 @llvm.nacl.atomic.rmw.i64(i32 3, i64* %ptr, i64 %v, i32 6) |
484 ret i64 %a | 484 ret i64 %a |
485 } | 485 } |
486 ; CHECK-LABEL: test_atomic_rmw_or_64 | 486 ; CHECK-LABEL: test_atomic_rmw_or_64 |
487 ; CHECK: push ebx | 487 ; CHECK: push ebx |
488 ; CHECK: mov eax,DWORD PTR [{{.*}}] | 488 ; CHECK: mov eax,DWORD PTR [{{.*}}] |
489 ; CHECK: mov edx,DWORD PTR [{{.*}}+0x4] | 489 ; CHECK: mov edx,DWORD PTR [{{.*}}+0x4] |
490 ; CHECK: [[LABEL:[^ ]*]]: {{.*}} mov ebx,eax | 490 ; CHECK: [[LABEL:[^ ]*]]: {{.*}} mov ebx,eax |
491 ; CHECK: or ebx,{{.*e.[^x]}} | 491 ; CHECK: or ebx,{{.*e.[^x]}} |
492 ; CHECK: mov ecx,edx | 492 ; CHECK: mov ecx,edx |
493 ; CHECK: or ecx,{{.*e.[^x]}} | 493 ; CHECK: or ecx,{{.*e.[^x]}} |
494 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}} | 494 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}} |
495 ; CHECK: jne [[LABEL]] | 495 ; CHECK: jne [[LABEL]] |
496 | 496 |
497 define i32 @test_atomic_rmw_or_32_ignored(i32 %iptr, i32 %v) { | 497 define internal i32 @test_atomic_rmw_or_32_ignored(i32 %iptr, i32 %v) { |
498 entry: | 498 entry: |
499 %ptr = inttoptr i32 %iptr to i32* | 499 %ptr = inttoptr i32 %iptr to i32* |
500 %ignored = call i32 @llvm.nacl.atomic.rmw.i32(i32 3, i32* %ptr, i32 %v, i32 6) | 500 %ignored = call i32 @llvm.nacl.atomic.rmw.i32(i32 3, i32* %ptr, i32 %v, i32 6) |
501 ret i32 %v | 501 ret i32 %v |
502 } | 502 } |
503 ; CHECK-LABEL: test_atomic_rmw_or_32_ignored | 503 ; CHECK-LABEL: test_atomic_rmw_or_32_ignored |
504 ; Could just "lock or", if we inspect the liveness information first. | 504 ; Could just "lock or", if we inspect the liveness information first. |
505 ; Would also need a way to introduce "lock"'edness to binary | 505 ; Would also need a way to introduce "lock"'edness to binary |
506 ; operators without introducing overhead on the more common binary ops. | 506 ; operators without introducing overhead on the more common binary ops. |
507 ; CHECK: mov eax,DWORD PTR | 507 ; CHECK: mov eax,DWORD PTR |
508 ; CHECK: or [[REG:e[^a].]] | 508 ; CHECK: or [[REG:e[^a].]] |
509 ; CHECK: lock cmpxchg DWORD PTR [e{{[^a].}}],[[REG]] | 509 ; CHECK: lock cmpxchg DWORD PTR [e{{[^a].}}],[[REG]] |
510 ; CHECK: jne | 510 ; CHECK: jne |
511 | 511 |
512 ;; and | 512 ;; and |
513 | 513 |
514 define i32 @test_atomic_rmw_and_8(i32 %iptr, i32 %v) { | 514 define internal i32 @test_atomic_rmw_and_8(i32 %iptr, i32 %v) { |
515 entry: | 515 entry: |
516 %trunc = trunc i32 %v to i8 | 516 %trunc = trunc i32 %v to i8 |
517 %ptr = inttoptr i32 %iptr to i8* | 517 %ptr = inttoptr i32 %iptr to i8* |
518 %a = call i8 @llvm.nacl.atomic.rmw.i8(i32 4, i8* %ptr, i8 %trunc, i32 6) | 518 %a = call i8 @llvm.nacl.atomic.rmw.i8(i32 4, i8* %ptr, i8 %trunc, i32 6) |
519 %a_ext = zext i8 %a to i32 | 519 %a_ext = zext i8 %a to i32 |
520 ret i32 %a_ext | 520 ret i32 %a_ext |
521 } | 521 } |
522 ; CHECK-LABEL: test_atomic_rmw_and_8 | 522 ; CHECK-LABEL: test_atomic_rmw_and_8 |
523 ; CHECK: mov al,BYTE PTR | 523 ; CHECK: mov al,BYTE PTR |
524 ; CHECK: and [[REG:[^a].]] | 524 ; CHECK: and [[REG:[^a].]] |
525 ; CHECK: lock cmpxchg BYTE PTR [e{{[^a].}}],[[REG]] | 525 ; CHECK: lock cmpxchg BYTE PTR [e{{[^a].}}],[[REG]] |
526 ; CHECK: jne | 526 ; CHECK: jne |
527 | 527 |
528 define i32 @test_atomic_rmw_and_16(i32 %iptr, i32 %v) { | 528 define internal i32 @test_atomic_rmw_and_16(i32 %iptr, i32 %v) { |
529 entry: | 529 entry: |
530 %trunc = trunc i32 %v to i16 | 530 %trunc = trunc i32 %v to i16 |
531 %ptr = inttoptr i32 %iptr to i16* | 531 %ptr = inttoptr i32 %iptr to i16* |
532 %a = call i16 @llvm.nacl.atomic.rmw.i16(i32 4, i16* %ptr, i16 %trunc, i32 6) | 532 %a = call i16 @llvm.nacl.atomic.rmw.i16(i32 4, i16* %ptr, i16 %trunc, i32 6) |
533 %a_ext = zext i16 %a to i32 | 533 %a_ext = zext i16 %a to i32 |
534 ret i32 %a_ext | 534 ret i32 %a_ext |
535 } | 535 } |
536 ; CHECK-LABEL: test_atomic_rmw_and_16 | 536 ; CHECK-LABEL: test_atomic_rmw_and_16 |
537 ; CHECK: mov ax,WORD PTR | 537 ; CHECK: mov ax,WORD PTR |
538 ; CHECK: and | 538 ; CHECK: and |
539 ; CHECK: lock cmpxchg WORD PTR [e{{[^a].}}] | 539 ; CHECK: lock cmpxchg WORD PTR [e{{[^a].}}] |
540 ; CHECK: jne | 540 ; CHECK: jne |
541 | 541 |
542 define i32 @test_atomic_rmw_and_32(i32 %iptr, i32 %v) { | 542 define internal i32 @test_atomic_rmw_and_32(i32 %iptr, i32 %v) { |
543 entry: | 543 entry: |
544 %ptr = inttoptr i32 %iptr to i32* | 544 %ptr = inttoptr i32 %iptr to i32* |
545 %a = call i32 @llvm.nacl.atomic.rmw.i32(i32 4, i32* %ptr, i32 %v, i32 6) | 545 %a = call i32 @llvm.nacl.atomic.rmw.i32(i32 4, i32* %ptr, i32 %v, i32 6) |
546 ret i32 %a | 546 ret i32 %a |
547 } | 547 } |
548 ; CHECK-LABEL: test_atomic_rmw_and_32 | 548 ; CHECK-LABEL: test_atomic_rmw_and_32 |
549 ; CHECK: mov eax,DWORD PTR | 549 ; CHECK: mov eax,DWORD PTR |
550 ; CHECK: and | 550 ; CHECK: and |
551 ; CHECK: lock cmpxchg DWORD PTR [e{{[^a].}}] | 551 ; CHECK: lock cmpxchg DWORD PTR [e{{[^a].}}] |
552 ; CHECK: jne | 552 ; CHECK: jne |
553 | 553 |
554 define i64 @test_atomic_rmw_and_64(i32 %iptr, i64 %v) { | 554 define internal i64 @test_atomic_rmw_and_64(i32 %iptr, i64 %v) { |
555 entry: | 555 entry: |
556 %ptr = inttoptr i32 %iptr to i64* | 556 %ptr = inttoptr i32 %iptr to i64* |
557 %a = call i64 @llvm.nacl.atomic.rmw.i64(i32 4, i64* %ptr, i64 %v, i32 6) | 557 %a = call i64 @llvm.nacl.atomic.rmw.i64(i32 4, i64* %ptr, i64 %v, i32 6) |
558 ret i64 %a | 558 ret i64 %a |
559 } | 559 } |
560 ; CHECK-LABEL: test_atomic_rmw_and_64 | 560 ; CHECK-LABEL: test_atomic_rmw_and_64 |
561 ; CHECK: push ebx | 561 ; CHECK: push ebx |
562 ; CHECK: mov eax,DWORD PTR [{{.*}}] | 562 ; CHECK: mov eax,DWORD PTR [{{.*}}] |
563 ; CHECK: mov edx,DWORD PTR [{{.*}}+0x4] | 563 ; CHECK: mov edx,DWORD PTR [{{.*}}+0x4] |
564 ; CHECK: [[LABEL:[^ ]*]]: {{.*}} mov ebx,eax | 564 ; CHECK: [[LABEL:[^ ]*]]: {{.*}} mov ebx,eax |
565 ; CHECK: and ebx,{{.*e.[^x]}} | 565 ; CHECK: and ebx,{{.*e.[^x]}} |
566 ; CHECK: mov ecx,edx | 566 ; CHECK: mov ecx,edx |
567 ; CHECK: and ecx,{{.*e.[^x]}} | 567 ; CHECK: and ecx,{{.*e.[^x]}} |
568 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}} | 568 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}} |
569 ; CHECK: jne [[LABEL]] | 569 ; CHECK: jne [[LABEL]] |
570 | 570 |
571 define i32 @test_atomic_rmw_and_32_ignored(i32 %iptr, i32 %v) { | 571 define internal i32 @test_atomic_rmw_and_32_ignored(i32 %iptr, i32 %v) { |
572 entry: | 572 entry: |
573 %ptr = inttoptr i32 %iptr to i32* | 573 %ptr = inttoptr i32 %iptr to i32* |
574 %ignored = call i32 @llvm.nacl.atomic.rmw.i32(i32 4, i32* %ptr, i32 %v, i32 6) | 574 %ignored = call i32 @llvm.nacl.atomic.rmw.i32(i32 4, i32* %ptr, i32 %v, i32 6) |
575 ret i32 %v | 575 ret i32 %v |
576 } | 576 } |
577 ; CHECK-LABEL: test_atomic_rmw_and_32_ignored | 577 ; CHECK-LABEL: test_atomic_rmw_and_32_ignored |
578 ; Could just "lock and" | 578 ; Could just "lock and" |
579 ; CHECK: mov eax,DWORD PTR | 579 ; CHECK: mov eax,DWORD PTR |
580 ; CHECK: and | 580 ; CHECK: and |
581 ; CHECK: lock cmpxchg DWORD PTR [e{{[^a].}}] | 581 ; CHECK: lock cmpxchg DWORD PTR [e{{[^a].}}] |
582 ; CHECK: jne | 582 ; CHECK: jne |
583 | 583 |
584 ;; xor | 584 ;; xor |
585 | 585 |
586 define i32 @test_atomic_rmw_xor_8(i32 %iptr, i32 %v) { | 586 define internal i32 @test_atomic_rmw_xor_8(i32 %iptr, i32 %v) { |
587 entry: | 587 entry: |
588 %trunc = trunc i32 %v to i8 | 588 %trunc = trunc i32 %v to i8 |
589 %ptr = inttoptr i32 %iptr to i8* | 589 %ptr = inttoptr i32 %iptr to i8* |
590 %a = call i8 @llvm.nacl.atomic.rmw.i8(i32 5, i8* %ptr, i8 %trunc, i32 6) | 590 %a = call i8 @llvm.nacl.atomic.rmw.i8(i32 5, i8* %ptr, i8 %trunc, i32 6) |
591 %a_ext = zext i8 %a to i32 | 591 %a_ext = zext i8 %a to i32 |
592 ret i32 %a_ext | 592 ret i32 %a_ext |
593 } | 593 } |
594 ; CHECK-LABEL: test_atomic_rmw_xor_8 | 594 ; CHECK-LABEL: test_atomic_rmw_xor_8 |
595 ; CHECK: mov al,BYTE PTR | 595 ; CHECK: mov al,BYTE PTR |
596 ; CHECK: xor [[REG:[^a].]] | 596 ; CHECK: xor [[REG:[^a].]] |
597 ; CHECK: lock cmpxchg BYTE PTR [e{{[^a].}}],[[REG]] | 597 ; CHECK: lock cmpxchg BYTE PTR [e{{[^a].}}],[[REG]] |
598 ; CHECK: jne | 598 ; CHECK: jne |
599 | 599 |
600 define i32 @test_atomic_rmw_xor_16(i32 %iptr, i32 %v) { | 600 define internal i32 @test_atomic_rmw_xor_16(i32 %iptr, i32 %v) { |
601 entry: | 601 entry: |
602 %trunc = trunc i32 %v to i16 | 602 %trunc = trunc i32 %v to i16 |
603 %ptr = inttoptr i32 %iptr to i16* | 603 %ptr = inttoptr i32 %iptr to i16* |
604 %a = call i16 @llvm.nacl.atomic.rmw.i16(i32 5, i16* %ptr, i16 %trunc, i32 6) | 604 %a = call i16 @llvm.nacl.atomic.rmw.i16(i32 5, i16* %ptr, i16 %trunc, i32 6) |
605 %a_ext = zext i16 %a to i32 | 605 %a_ext = zext i16 %a to i32 |
606 ret i32 %a_ext | 606 ret i32 %a_ext |
607 } | 607 } |
608 ; CHECK-LABEL: test_atomic_rmw_xor_16 | 608 ; CHECK-LABEL: test_atomic_rmw_xor_16 |
609 ; CHECK: mov ax,WORD PTR | 609 ; CHECK: mov ax,WORD PTR |
610 ; CHECK: xor | 610 ; CHECK: xor |
611 ; CHECK: lock cmpxchg WORD PTR [e{{[^a].}}] | 611 ; CHECK: lock cmpxchg WORD PTR [e{{[^a].}}] |
612 ; CHECK: jne | 612 ; CHECK: jne |
613 | 613 |
614 | 614 |
615 define i32 @test_atomic_rmw_xor_32(i32 %iptr, i32 %v) { | 615 define internal i32 @test_atomic_rmw_xor_32(i32 %iptr, i32 %v) { |
616 entry: | 616 entry: |
617 %ptr = inttoptr i32 %iptr to i32* | 617 %ptr = inttoptr i32 %iptr to i32* |
618 %a = call i32 @llvm.nacl.atomic.rmw.i32(i32 5, i32* %ptr, i32 %v, i32 6) | 618 %a = call i32 @llvm.nacl.atomic.rmw.i32(i32 5, i32* %ptr, i32 %v, i32 6) |
619 ret i32 %a | 619 ret i32 %a |
620 } | 620 } |
621 ; CHECK-LABEL: test_atomic_rmw_xor_32 | 621 ; CHECK-LABEL: test_atomic_rmw_xor_32 |
622 ; CHECK: mov eax,DWORD PTR | 622 ; CHECK: mov eax,DWORD PTR |
623 ; CHECK: xor | 623 ; CHECK: xor |
624 ; CHECK: lock cmpxchg DWORD PTR [e{{[^a].}}] | 624 ; CHECK: lock cmpxchg DWORD PTR [e{{[^a].}}] |
625 ; CHECK: jne | 625 ; CHECK: jne |
626 | 626 |
627 define i64 @test_atomic_rmw_xor_64(i32 %iptr, i64 %v) { | 627 define internal i64 @test_atomic_rmw_xor_64(i32 %iptr, i64 %v) { |
628 entry: | 628 entry: |
629 %ptr = inttoptr i32 %iptr to i64* | 629 %ptr = inttoptr i32 %iptr to i64* |
630 %a = call i64 @llvm.nacl.atomic.rmw.i64(i32 5, i64* %ptr, i64 %v, i32 6) | 630 %a = call i64 @llvm.nacl.atomic.rmw.i64(i32 5, i64* %ptr, i64 %v, i32 6) |
631 ret i64 %a | 631 ret i64 %a |
632 } | 632 } |
633 ; CHECK-LABEL: test_atomic_rmw_xor_64 | 633 ; CHECK-LABEL: test_atomic_rmw_xor_64 |
634 ; CHECK: push ebx | 634 ; CHECK: push ebx |
635 ; CHECK: mov eax,DWORD PTR [{{.*}}] | 635 ; CHECK: mov eax,DWORD PTR [{{.*}}] |
636 ; CHECK: mov edx,DWORD PTR [{{.*}}+0x4] | 636 ; CHECK: mov edx,DWORD PTR [{{.*}}+0x4] |
637 ; CHECK: mov ebx,eax | 637 ; CHECK: mov ebx,eax |
638 ; CHECK: or ebx,{{.*e.[^x]}} | 638 ; CHECK: or ebx,{{.*e.[^x]}} |
639 ; CHECK: mov ecx,edx | 639 ; CHECK: mov ecx,edx |
640 ; CHECK: or ecx,{{.*e.[^x]}} | 640 ; CHECK: or ecx,{{.*e.[^x]}} |
641 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}} | 641 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}} |
642 ; CHECK: jne | 642 ; CHECK: jne |
643 | 643 |
644 define i32 @test_atomic_rmw_xor_32_ignored(i32 %iptr, i32 %v) { | 644 define internal i32 @test_atomic_rmw_xor_32_ignored(i32 %iptr, i32 %v) { |
645 entry: | 645 entry: |
646 %ptr = inttoptr i32 %iptr to i32* | 646 %ptr = inttoptr i32 %iptr to i32* |
647 %ignored = call i32 @llvm.nacl.atomic.rmw.i32(i32 5, i32* %ptr, i32 %v, i32 6) | 647 %ignored = call i32 @llvm.nacl.atomic.rmw.i32(i32 5, i32* %ptr, i32 %v, i32 6) |
648 ret i32 %v | 648 ret i32 %v |
649 } | 649 } |
650 ; CHECK-LABEL: test_atomic_rmw_xor_32_ignored | 650 ; CHECK-LABEL: test_atomic_rmw_xor_32_ignored |
651 ; CHECK: mov eax,DWORD PTR | 651 ; CHECK: mov eax,DWORD PTR |
652 ; CHECK: xor | 652 ; CHECK: xor |
653 ; CHECK: lock cmpxchg DWORD PTR [e{{[^a].}}] | 653 ; CHECK: lock cmpxchg DWORD PTR [e{{[^a].}}] |
654 ; CHECK: jne | 654 ; CHECK: jne |
655 | 655 |
656 ;; exchange | 656 ;; exchange |
657 | 657 |
658 define i32 @test_atomic_rmw_xchg_8(i32 %iptr, i32 %v) { | 658 define internal i32 @test_atomic_rmw_xchg_8(i32 %iptr, i32 %v) { |
659 entry: | 659 entry: |
660 %trunc = trunc i32 %v to i8 | 660 %trunc = trunc i32 %v to i8 |
661 %ptr = inttoptr i32 %iptr to i8* | 661 %ptr = inttoptr i32 %iptr to i8* |
662 %a = call i8 @llvm.nacl.atomic.rmw.i8(i32 6, i8* %ptr, i8 %trunc, i32 6) | 662 %a = call i8 @llvm.nacl.atomic.rmw.i8(i32 6, i8* %ptr, i8 %trunc, i32 6) |
663 %a_ext = zext i8 %a to i32 | 663 %a_ext = zext i8 %a to i32 |
664 ret i32 %a_ext | 664 ret i32 %a_ext |
665 } | 665 } |
666 ; CHECK-LABEL: test_atomic_rmw_xchg_8 | 666 ; CHECK-LABEL: test_atomic_rmw_xchg_8 |
667 ; CHECK: xchg BYTE PTR {{.*}},[[REG:.*]] | 667 ; CHECK: xchg BYTE PTR {{.*}},[[REG:.*]] |
668 | 668 |
669 define i32 @test_atomic_rmw_xchg_16(i32 %iptr, i32 %v) { | 669 define internal i32 @test_atomic_rmw_xchg_16(i32 %iptr, i32 %v) { |
670 entry: | 670 entry: |
671 %trunc = trunc i32 %v to i16 | 671 %trunc = trunc i32 %v to i16 |
672 %ptr = inttoptr i32 %iptr to i16* | 672 %ptr = inttoptr i32 %iptr to i16* |
673 %a = call i16 @llvm.nacl.atomic.rmw.i16(i32 6, i16* %ptr, i16 %trunc, i32 6) | 673 %a = call i16 @llvm.nacl.atomic.rmw.i16(i32 6, i16* %ptr, i16 %trunc, i32 6) |
674 %a_ext = zext i16 %a to i32 | 674 %a_ext = zext i16 %a to i32 |
675 ret i32 %a_ext | 675 ret i32 %a_ext |
676 } | 676 } |
677 ; CHECK-LABEL: test_atomic_rmw_xchg_16 | 677 ; CHECK-LABEL: test_atomic_rmw_xchg_16 |
678 ; CHECK: xchg WORD PTR {{.*}},[[REG:.*]] | 678 ; CHECK: xchg WORD PTR {{.*}},[[REG:.*]] |
679 | 679 |
680 define i32 @test_atomic_rmw_xchg_32(i32 %iptr, i32 %v) { | 680 define internal i32 @test_atomic_rmw_xchg_32(i32 %iptr, i32 %v) { |
681 entry: | 681 entry: |
682 %ptr = inttoptr i32 %iptr to i32* | 682 %ptr = inttoptr i32 %iptr to i32* |
683 %a = call i32 @llvm.nacl.atomic.rmw.i32(i32 6, i32* %ptr, i32 %v, i32 6) | 683 %a = call i32 @llvm.nacl.atomic.rmw.i32(i32 6, i32* %ptr, i32 %v, i32 6) |
684 ret i32 %a | 684 ret i32 %a |
685 } | 685 } |
686 ; CHECK-LABEL: test_atomic_rmw_xchg_32 | 686 ; CHECK-LABEL: test_atomic_rmw_xchg_32 |
687 ; CHECK: xchg DWORD PTR {{.*}},[[REG:.*]] | 687 ; CHECK: xchg DWORD PTR {{.*}},[[REG:.*]] |
688 | 688 |
689 define i64 @test_atomic_rmw_xchg_64(i32 %iptr, i64 %v) { | 689 define internal i64 @test_atomic_rmw_xchg_64(i32 %iptr, i64 %v) { |
690 entry: | 690 entry: |
691 %ptr = inttoptr i32 %iptr to i64* | 691 %ptr = inttoptr i32 %iptr to i64* |
692 %a = call i64 @llvm.nacl.atomic.rmw.i64(i32 6, i64* %ptr, i64 %v, i32 6) | 692 %a = call i64 @llvm.nacl.atomic.rmw.i64(i32 6, i64* %ptr, i64 %v, i32 6) |
693 ret i64 %a | 693 ret i64 %a |
694 } | 694 } |
695 ; CHECK-LABEL: test_atomic_rmw_xchg_64 | 695 ; CHECK-LABEL: test_atomic_rmw_xchg_64 |
696 ; CHECK: push ebx | 696 ; CHECK: push ebx |
697 ; CHECK-DAG: mov edx | 697 ; CHECK-DAG: mov edx |
698 ; CHECK-DAG: mov eax | 698 ; CHECK-DAG: mov eax |
699 ; CHECK-DAG: mov ecx | 699 ; CHECK-DAG: mov ecx |
700 ; CHECK-DAG: mov ebx | 700 ; CHECK-DAG: mov ebx |
701 ; CHECK: lock cmpxchg8b QWORD PTR [{{e.[^x]}} | 701 ; CHECK: lock cmpxchg8b QWORD PTR [{{e.[^x]}} |
702 ; CHECK: jne | 702 ; CHECK: jne |
703 | 703 |
704 define i32 @test_atomic_rmw_xchg_32_ignored(i32 %iptr, i32 %v) { | 704 define internal i32 @test_atomic_rmw_xchg_32_ignored(i32 %iptr, i32 %v) { |
705 entry: | 705 entry: |
706 %ptr = inttoptr i32 %iptr to i32* | 706 %ptr = inttoptr i32 %iptr to i32* |
707 %ignored = call i32 @llvm.nacl.atomic.rmw.i32(i32 6, i32* %ptr, i32 %v, i32 6) | 707 %ignored = call i32 @llvm.nacl.atomic.rmw.i32(i32 6, i32* %ptr, i32 %v, i32 6) |
708 ret i32 %v | 708 ret i32 %v |
709 } | 709 } |
710 ; In this case, ignoring the return value doesn't help. The xchg is | 710 ; In this case, ignoring the return value doesn't help. The xchg is |
711 ; used to do an atomic store. | 711 ; used to do an atomic store. |
712 ; CHECK-LABEL: test_atomic_rmw_xchg_32_ignored | 712 ; CHECK-LABEL: test_atomic_rmw_xchg_32_ignored |
713 ; CHECK: xchg DWORD PTR {{.*}},[[REG:.*]] | 713 ; CHECK: xchg DWORD PTR {{.*}},[[REG:.*]] |
714 | 714 |
715 ;;;; Cmpxchg | 715 ;;;; Cmpxchg |
716 | 716 |
717 define i32 @test_atomic_cmpxchg_8(i32 %iptr, i32 %expected, i32 %desired) { | 717 define internal i32 @test_atomic_cmpxchg_8(i32 %iptr, i32 %expected, |
| 718 i32 %desired) { |
718 entry: | 719 entry: |
719 %trunc_exp = trunc i32 %expected to i8 | 720 %trunc_exp = trunc i32 %expected to i8 |
720 %trunc_des = trunc i32 %desired to i8 | 721 %trunc_des = trunc i32 %desired to i8 |
721 %ptr = inttoptr i32 %iptr to i8* | 722 %ptr = inttoptr i32 %iptr to i8* |
722 %old = call i8 @llvm.nacl.atomic.cmpxchg.i8(i8* %ptr, i8 %trunc_exp, | 723 %old = call i8 @llvm.nacl.atomic.cmpxchg.i8(i8* %ptr, i8 %trunc_exp, |
723 i8 %trunc_des, i32 6, i32 6) | 724 i8 %trunc_des, i32 6, i32 6) |
724 %old_ext = zext i8 %old to i32 | 725 %old_ext = zext i8 %old to i32 |
725 ret i32 %old_ext | 726 ret i32 %old_ext |
726 } | 727 } |
727 ; CHECK-LABEL: test_atomic_cmpxchg_8 | 728 ; CHECK-LABEL: test_atomic_cmpxchg_8 |
728 ; CHECK: mov eax,{{.*}} | 729 ; CHECK: mov eax,{{.*}} |
729 ; Need to check that eax isn't used as the address register or the desired. | 730 ; Need to check that eax isn't used as the address register or the desired. |
730 ; since it is already used as the *expected* register. | 731 ; since it is already used as the *expected* register. |
731 ; CHECK: lock cmpxchg BYTE PTR [e{{[^a].}}],{{[^a]}}l | 732 ; CHECK: lock cmpxchg BYTE PTR [e{{[^a].}}],{{[^a]}}l |
732 | 733 |
733 define i32 @test_atomic_cmpxchg_16(i32 %iptr, i32 %expected, i32 %desired) { | 734 define internal i32 @test_atomic_cmpxchg_16(i32 %iptr, i32 %expected, |
| 735 i32 %desired) { |
734 entry: | 736 entry: |
735 %trunc_exp = trunc i32 %expected to i16 | 737 %trunc_exp = trunc i32 %expected to i16 |
736 %trunc_des = trunc i32 %desired to i16 | 738 %trunc_des = trunc i32 %desired to i16 |
737 %ptr = inttoptr i32 %iptr to i16* | 739 %ptr = inttoptr i32 %iptr to i16* |
738 %old = call i16 @llvm.nacl.atomic.cmpxchg.i16(i16* %ptr, i16 %trunc_exp, | 740 %old = call i16 @llvm.nacl.atomic.cmpxchg.i16(i16* %ptr, i16 %trunc_exp, |
739 i16 %trunc_des, i32 6, i32 6) | 741 i16 %trunc_des, i32 6, i32 6) |
740 %old_ext = zext i16 %old to i32 | 742 %old_ext = zext i16 %old to i32 |
741 ret i32 %old_ext | 743 ret i32 %old_ext |
742 } | 744 } |
743 ; CHECK-LABEL: test_atomic_cmpxchg_16 | 745 ; CHECK-LABEL: test_atomic_cmpxchg_16 |
744 ; CHECK: mov eax,{{.*}} | 746 ; CHECK: mov eax,{{.*}} |
745 ; CHECK: lock cmpxchg WORD PTR [e{{[^a].}}],{{[^a]}}x | 747 ; CHECK: lock cmpxchg WORD PTR [e{{[^a].}}],{{[^a]}}x |
746 | 748 |
747 define i32 @test_atomic_cmpxchg_32(i32 %iptr, i32 %expected, i32 %desired) { | 749 define internal i32 @test_atomic_cmpxchg_32(i32 %iptr, i32 %expected, |
| 750 i32 %desired) { |
748 entry: | 751 entry: |
749 %ptr = inttoptr i32 %iptr to i32* | 752 %ptr = inttoptr i32 %iptr to i32* |
750 %old = call i32 @llvm.nacl.atomic.cmpxchg.i32(i32* %ptr, i32 %expected, | 753 %old = call i32 @llvm.nacl.atomic.cmpxchg.i32(i32* %ptr, i32 %expected, |
751 i32 %desired, i32 6, i32 6) | 754 i32 %desired, i32 6, i32 6) |
752 ret i32 %old | 755 ret i32 %old |
753 } | 756 } |
754 ; CHECK-LABEL: test_atomic_cmpxchg_32 | 757 ; CHECK-LABEL: test_atomic_cmpxchg_32 |
755 ; CHECK: mov eax,{{.*}} | 758 ; CHECK: mov eax,{{.*}} |
756 ; CHECK: lock cmpxchg DWORD PTR [e{{[^a].}}],e{{[^a]}} | 759 ; CHECK: lock cmpxchg DWORD PTR [e{{[^a].}}],e{{[^a]}} |
757 | 760 |
758 define i64 @test_atomic_cmpxchg_64(i32 %iptr, i64 %expected, i64 %desired) { | 761 define internal i64 @test_atomic_cmpxchg_64(i32 %iptr, i64 %expected, |
| 762 i64 %desired) { |
759 entry: | 763 entry: |
760 %ptr = inttoptr i32 %iptr to i64* | 764 %ptr = inttoptr i32 %iptr to i64* |
761 %old = call i64 @llvm.nacl.atomic.cmpxchg.i64(i64* %ptr, i64 %expected, | 765 %old = call i64 @llvm.nacl.atomic.cmpxchg.i64(i64* %ptr, i64 %expected, |
762 i64 %desired, i32 6, i32 6) | 766 i64 %desired, i32 6, i32 6) |
763 ret i64 %old | 767 ret i64 %old |
764 } | 768 } |
765 ; CHECK-LABEL: test_atomic_cmpxchg_64 | 769 ; CHECK-LABEL: test_atomic_cmpxchg_64 |
766 ; CHECK: push ebx | 770 ; CHECK: push ebx |
767 ; CHECK-DAG: mov edx | 771 ; CHECK-DAG: mov edx |
768 ; CHECK-DAG: mov eax | 772 ; CHECK-DAG: mov eax |
769 ; CHECK-DAG: mov ecx | 773 ; CHECK-DAG: mov ecx |
770 ; CHECK-DAG: mov ebx | 774 ; CHECK-DAG: mov ebx |
771 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}}+0x0] | 775 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}}+0x0] |
772 ; edx and eax are already the return registers, so they don't actually | 776 ; edx and eax are already the return registers, so they don't actually |
773 ; need to be reshuffled via movs. The next test stores the result | 777 ; need to be reshuffled via movs. The next test stores the result |
774 ; somewhere, so in that case they do need to be mov'ed. | 778 ; somewhere, so in that case they do need to be mov'ed. |
775 | 779 |
776 define i64 @test_atomic_cmpxchg_64_undef(i32 %iptr, i64 %desired) { | 780 define internal i64 @test_atomic_cmpxchg_64_undef(i32 %iptr, i64 %desired) { |
777 entry: | 781 entry: |
778 %ptr = inttoptr i32 %iptr to i64* | 782 %ptr = inttoptr i32 %iptr to i64* |
779 %old = call i64 @llvm.nacl.atomic.cmpxchg.i64(i64* %ptr, i64 undef, | 783 %old = call i64 @llvm.nacl.atomic.cmpxchg.i64(i64* %ptr, i64 undef, |
780 i64 %desired, i32 6, i32 6) | 784 i64 %desired, i32 6, i32 6) |
781 ret i64 %old | 785 ret i64 %old |
782 } | 786 } |
783 ; CHECK-LABEL: test_atomic_cmpxchg_64_undef | 787 ; CHECK-LABEL: test_atomic_cmpxchg_64_undef |
784 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}}+0x0] | 788 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}}+0x0] |
785 | 789 |
786 ; Test a case where %old really does need to be copied out of edx:eax. | 790 ; Test a case where %old really does need to be copied out of edx:eax. |
787 define void @test_atomic_cmpxchg_64_store(i32 %ret_iptr, i32 %iptr, i64 %expecte
d, i64 %desired) { | 791 define internal void @test_atomic_cmpxchg_64_store( |
| 792 i32 %ret_iptr, i32 %iptr, i64 %expected, i64 %desired) { |
788 entry: | 793 entry: |
789 %ptr = inttoptr i32 %iptr to i64* | 794 %ptr = inttoptr i32 %iptr to i64* |
790 %old = call i64 @llvm.nacl.atomic.cmpxchg.i64(i64* %ptr, i64 %expected, | 795 %old = call i64 @llvm.nacl.atomic.cmpxchg.i64(i64* %ptr, i64 %expected, |
791 i64 %desired, i32 6, i32 6) | 796 i64 %desired, i32 6, i32 6) |
792 %__6 = inttoptr i32 %ret_iptr to i64* | 797 %__6 = inttoptr i32 %ret_iptr to i64* |
793 store i64 %old, i64* %__6, align 1 | 798 store i64 %old, i64* %__6, align 1 |
794 ret void | 799 ret void |
795 } | 800 } |
796 ; CHECK-LABEL: test_atomic_cmpxchg_64_store | 801 ; CHECK-LABEL: test_atomic_cmpxchg_64_store |
797 ; CHECK: push ebx | 802 ; CHECK: push ebx |
798 ; CHECK-DAG: mov edx | 803 ; CHECK-DAG: mov edx |
799 ; CHECK-DAG: mov eax | 804 ; CHECK-DAG: mov eax |
800 ; CHECK-DAG: mov ecx | 805 ; CHECK-DAG: mov ecx |
801 ; CHECK-DAG: mov ebx | 806 ; CHECK-DAG: mov ebx |
802 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}} | 807 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}} |
803 ; CHECK-DAG: mov {{.*}},edx | 808 ; CHECK-DAG: mov {{.*}},edx |
804 ; CHECK-DAG: mov {{.*}},eax | 809 ; CHECK-DAG: mov {{.*}},eax |
805 | 810 |
806 ; Test with some more register pressure. When we have an alloca, ebp is | 811 ; Test with some more register pressure. When we have an alloca, ebp is |
807 ; used to manage the stack frame, so it cannot be used as a register either. | 812 ; used to manage the stack frame, so it cannot be used as a register either. |
808 define i64 @test_atomic_cmpxchg_64_alloca(i32 %iptr, i64 %expected, i64 %desired
) { | 813 define internal i64 @test_atomic_cmpxchg_64_alloca(i32 %iptr, i64 %expected, |
| 814 i64 %desired) { |
809 entry: | 815 entry: |
810 br label %eblock ; Disable alloca optimization | 816 br label %eblock ; Disable alloca optimization |
811 eblock: | 817 eblock: |
812 %alloca_ptr = alloca i8, i32 16, align 16 | 818 %alloca_ptr = alloca i8, i32 16, align 16 |
813 %ptr = inttoptr i32 %iptr to i64* | 819 %ptr = inttoptr i32 %iptr to i64* |
814 %old = call i64 @llvm.nacl.atomic.cmpxchg.i64(i64* %ptr, i64 %expected, | 820 %old = call i64 @llvm.nacl.atomic.cmpxchg.i64(i64* %ptr, i64 %expected, |
815 i64 %desired, i32 6, i32 6) | 821 i64 %desired, i32 6, i32 6) |
816 store i8 0, i8* %alloca_ptr, align 1 | 822 store i8 0, i8* %alloca_ptr, align 1 |
817 store i8 1, i8* %alloca_ptr, align 1 | 823 store i8 1, i8* %alloca_ptr, align 1 |
818 store i8 2, i8* %alloca_ptr, align 1 | 824 store i8 2, i8* %alloca_ptr, align 1 |
819 store i8 3, i8* %alloca_ptr, align 1 | 825 store i8 3, i8* %alloca_ptr, align 1 |
820 %__6 = ptrtoint i8* %alloca_ptr to i32 | 826 %__6 = ptrtoint i8* %alloca_ptr to i32 |
821 call void @use_ptr(i32 %__6) | 827 call void @use_ptr(i32 %__6) |
822 ret i64 %old | 828 ret i64 %old |
823 } | 829 } |
824 ; CHECK-LABEL: test_atomic_cmpxchg_64_alloca | 830 ; CHECK-LABEL: test_atomic_cmpxchg_64_alloca |
825 ; CHECK: push ebx | 831 ; CHECK: push ebx |
826 ; CHECK-DAG: mov edx | 832 ; CHECK-DAG: mov edx |
827 ; CHECK-DAG: mov eax | 833 ; CHECK-DAG: mov eax |
828 ; CHECK-DAG: mov ecx | 834 ; CHECK-DAG: mov ecx |
829 ; CHECK-DAG: mov ebx | 835 ; CHECK-DAG: mov ebx |
830 ; Ptr cannot be eax, ebx, ecx, or edx (used up for the expected and desired). | 836 ; Ptr cannot be eax, ebx, ecx, or edx (used up for the expected and desired). |
831 ; It also cannot be ebp since we use that for alloca. Also make sure it's | 837 ; It also cannot be ebp since we use that for alloca. Also make sure it's |
832 ; not esp, since that's the stack pointer and mucking with it will break | 838 ; not esp, since that's the stack pointer and mucking with it will break |
833 ; the later use_ptr function call. | 839 ; the later use_ptr function call. |
834 ; That pretty much leaves esi, or edi as the only viable registers. | 840 ; That pretty much leaves esi, or edi as the only viable registers. |
835 ; CHECK: lock cmpxchg8b QWORD PTR [e{{[ds]}}i] | 841 ; CHECK: lock cmpxchg8b QWORD PTR [e{{[ds]}}i] |
836 ; CHECK: call {{.*}} R_{{.*}} use_ptr | 842 ; CHECK: call {{.*}} R_{{.*}} use_ptr |
837 | 843 |
838 define i32 @test_atomic_cmpxchg_32_ignored(i32 %iptr, i32 %expected, i32 %desire
d) { | 844 define internal i32 @test_atomic_cmpxchg_32_ignored(i32 %iptr, i32 %expected, |
| 845 i32 %desired) { |
839 entry: | 846 entry: |
840 %ptr = inttoptr i32 %iptr to i32* | 847 %ptr = inttoptr i32 %iptr to i32* |
841 %ignored = call i32 @llvm.nacl.atomic.cmpxchg.i32(i32* %ptr, i32 %expected, | 848 %ignored = call i32 @llvm.nacl.atomic.cmpxchg.i32(i32* %ptr, i32 %expected, |
842 i32 %desired, i32 6, i32 6) | 849 i32 %desired, i32 6, i32 6) |
843 ret i32 0 | 850 ret i32 0 |
844 } | 851 } |
845 ; CHECK-LABEL: test_atomic_cmpxchg_32_ignored | 852 ; CHECK-LABEL: test_atomic_cmpxchg_32_ignored |
846 ; CHECK: mov eax,{{.*}} | 853 ; CHECK: mov eax,{{.*}} |
847 ; CHECK: lock cmpxchg DWORD PTR [e{{[^a].}}] | 854 ; CHECK: lock cmpxchg DWORD PTR [e{{[^a].}}] |
848 | 855 |
849 define i64 @test_atomic_cmpxchg_64_ignored(i32 %iptr, i64 %expected, i64 %desire
d) { | 856 define internal i64 @test_atomic_cmpxchg_64_ignored(i32 %iptr, i64 %expected, |
| 857 i64 %desired) { |
850 entry: | 858 entry: |
851 %ptr = inttoptr i32 %iptr to i64* | 859 %ptr = inttoptr i32 %iptr to i64* |
852 %ignored = call i64 @llvm.nacl.atomic.cmpxchg.i64(i64* %ptr, i64 %expected, | 860 %ignored = call i64 @llvm.nacl.atomic.cmpxchg.i64(i64* %ptr, i64 %expected, |
853 i64 %desired, i32 6, i32 6) | 861 i64 %desired, i32 6, i32 6) |
854 ret i64 0 | 862 ret i64 0 |
855 } | 863 } |
856 ; CHECK-LABEL: test_atomic_cmpxchg_64_ignored | 864 ; CHECK-LABEL: test_atomic_cmpxchg_64_ignored |
857 ; CHECK: push ebx | 865 ; CHECK: push ebx |
858 ; CHECK-DAG: mov edx | 866 ; CHECK-DAG: mov edx |
859 ; CHECK-DAG: mov eax | 867 ; CHECK-DAG: mov eax |
860 ; CHECK-DAG: mov ecx | 868 ; CHECK-DAG: mov ecx |
861 ; CHECK-DAG: mov ebx | 869 ; CHECK-DAG: mov ebx |
862 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}}+0x0] | 870 ; CHECK: lock cmpxchg8b QWORD PTR [e{{.[^x]}}+0x0] |
863 | 871 |
864 ;;;; Fence and is-lock-free. | 872 ;;;; Fence and is-lock-free. |
865 | 873 |
866 define void @test_atomic_fence() { | 874 define internal void @test_atomic_fence() { |
867 entry: | 875 entry: |
868 call void @llvm.nacl.atomic.fence(i32 6) | 876 call void @llvm.nacl.atomic.fence(i32 6) |
869 ret void | 877 ret void |
870 } | 878 } |
871 ; CHECK-LABEL: test_atomic_fence | 879 ; CHECK-LABEL: test_atomic_fence |
872 ; CHECK: mfence | 880 ; CHECK: mfence |
873 | 881 |
874 define void @test_atomic_fence_all() { | 882 define internal void @test_atomic_fence_all() { |
875 entry: | 883 entry: |
876 call void @llvm.nacl.atomic.fence.all() | 884 call void @llvm.nacl.atomic.fence.all() |
877 ret void | 885 ret void |
878 } | 886 } |
879 ; CHECK-LABEL: test_atomic_fence_all | 887 ; CHECK-LABEL: test_atomic_fence_all |
880 ; CHECK: mfence | 888 ; CHECK: mfence |
881 | 889 |
882 define i32 @test_atomic_is_lock_free(i32 %iptr) { | 890 define internal i32 @test_atomic_is_lock_free(i32 %iptr) { |
883 entry: | 891 entry: |
884 %ptr = inttoptr i32 %iptr to i8* | 892 %ptr = inttoptr i32 %iptr to i8* |
885 %i = call i1 @llvm.nacl.atomic.is.lock.free(i32 4, i8* %ptr) | 893 %i = call i1 @llvm.nacl.atomic.is.lock.free(i32 4, i8* %ptr) |
886 %r = zext i1 %i to i32 | 894 %r = zext i1 %i to i32 |
887 ret i32 %r | 895 ret i32 %r |
888 } | 896 } |
889 ; CHECK-LABEL: test_atomic_is_lock_free | 897 ; CHECK-LABEL: test_atomic_is_lock_free |
890 ; CHECK: mov {{.*}},0x1 | 898 ; CHECK: mov {{.*}},0x1 |
891 | 899 |
892 define i32 @test_not_lock_free(i32 %iptr) { | 900 define internal i32 @test_not_lock_free(i32 %iptr) { |
893 entry: | 901 entry: |
894 %ptr = inttoptr i32 %iptr to i8* | 902 %ptr = inttoptr i32 %iptr to i8* |
895 %i = call i1 @llvm.nacl.atomic.is.lock.free(i32 7, i8* %ptr) | 903 %i = call i1 @llvm.nacl.atomic.is.lock.free(i32 7, i8* %ptr) |
896 %r = zext i1 %i to i32 | 904 %r = zext i1 %i to i32 |
897 ret i32 %r | 905 ret i32 %r |
898 } | 906 } |
899 ; CHECK-LABEL: test_not_lock_free | 907 ; CHECK-LABEL: test_not_lock_free |
900 ; CHECK: mov {{.*}},0x0 | 908 ; CHECK: mov {{.*}},0x0 |
901 | 909 |
902 define i32 @test_atomic_is_lock_free_ignored(i32 %iptr) { | 910 define internal i32 @test_atomic_is_lock_free_ignored(i32 %iptr) { |
903 entry: | 911 entry: |
904 %ptr = inttoptr i32 %iptr to i8* | 912 %ptr = inttoptr i32 %iptr to i8* |
905 %ignored = call i1 @llvm.nacl.atomic.is.lock.free(i32 4, i8* %ptr) | 913 %ignored = call i1 @llvm.nacl.atomic.is.lock.free(i32 4, i8* %ptr) |
906 ret i32 0 | 914 ret i32 0 |
907 } | 915 } |
908 ; CHECK-LABEL: test_atomic_is_lock_free_ignored | 916 ; CHECK-LABEL: test_atomic_is_lock_free_ignored |
909 ; CHECK: mov {{.*}},0x0 | 917 ; CHECK: mov {{.*}},0x0 |
910 ; This can get optimized out, because it's side-effect-free. | 918 ; This can get optimized out, because it's side-effect-free. |
911 ; O2-LABEL: test_atomic_is_lock_free_ignored | 919 ; O2-LABEL: test_atomic_is_lock_free_ignored |
912 ; O2-NOT: mov {{.*}}, 1 | 920 ; O2-NOT: mov {{.*}}, 1 |
913 ; O2: mov {{.*}},0x0 | 921 ; O2: mov {{.*}},0x0 |
914 | 922 |
915 ; TODO(jvoung): at some point we can take advantage of the | 923 ; TODO(jvoung): at some point we can take advantage of the |
916 ; fact that nacl.atomic.is.lock.free will resolve to a constant | 924 ; fact that nacl.atomic.is.lock.free will resolve to a constant |
917 ; (which adds DCE opportunities). Once we optimize, the test expectations | 925 ; (which adds DCE opportunities). Once we optimize, the test expectations |
918 ; for this case should change. | 926 ; for this case should change. |
919 define i32 @test_atomic_is_lock_free_can_dce(i32 %iptr, i32 %x, i32 %y) { | 927 define internal i32 @test_atomic_is_lock_free_can_dce(i32 %iptr, i32 %x, |
| 928 i32 %y) { |
920 entry: | 929 entry: |
921 %ptr = inttoptr i32 %iptr to i8* | 930 %ptr = inttoptr i32 %iptr to i8* |
922 %i = call i1 @llvm.nacl.atomic.is.lock.free(i32 4, i8* %ptr) | 931 %i = call i1 @llvm.nacl.atomic.is.lock.free(i32 4, i8* %ptr) |
923 %i_ext = zext i1 %i to i32 | 932 %i_ext = zext i1 %i to i32 |
924 %cmp = icmp eq i32 %i_ext, 1 | 933 %cmp = icmp eq i32 %i_ext, 1 |
925 br i1 %cmp, label %lock_free, label %not_lock_free | 934 br i1 %cmp, label %lock_free, label %not_lock_free |
926 lock_free: | 935 lock_free: |
927 ret i32 %i_ext | 936 ret i32 %i_ext |
928 | 937 |
929 not_lock_free: | 938 not_lock_free: |
930 %z = add i32 %x, %y | 939 %z = add i32 %x, %y |
931 ret i32 %z | 940 ret i32 %z |
932 } | 941 } |
933 ; CHECK-LABEL: test_atomic_is_lock_free_can_dce | 942 ; CHECK-LABEL: test_atomic_is_lock_free_can_dce |
934 ; CHECK: mov {{.*}},0x1 | 943 ; CHECK: mov {{.*}},0x1 |
935 ; CHECK: ret | 944 ; CHECK: ret |
936 ; CHECK: add | 945 ; CHECK: add |
937 ; CHECK: ret | 946 ; CHECK: ret |
938 | 947 |
939 ; Test the liveness / register allocation properties of the xadd instruction. | 948 ; Test the liveness / register allocation properties of the xadd instruction. |
940 ; Make sure we model that the Src register is modified and therefore it can't | 949 ; Make sure we model that the Src register is modified and therefore it can't |
941 ; share a register with an overlapping live range, even if the result of the | 950 ; share a register with an overlapping live range, even if the result of the |
942 ; xadd instruction is unused. | 951 ; xadd instruction is unused. |
943 define void @test_xadd_regalloc() { | 952 define internal void @test_xadd_regalloc() { |
944 entry: | 953 entry: |
945 br label %body | 954 br label %body |
946 body: | 955 body: |
947 %i = phi i32 [ 1, %entry ], [ %i_plus_1, %body ] | 956 %i = phi i32 [ 1, %entry ], [ %i_plus_1, %body ] |
948 %g = bitcast [4 x i8]* @Global32 to i32* | 957 %g = bitcast [4 x i8]* @Global32 to i32* |
949 %unused = call i32 @llvm.nacl.atomic.rmw.i32(i32 1, i32* %g, i32 %i, i32 6) | 958 %unused = call i32 @llvm.nacl.atomic.rmw.i32(i32 1, i32* %g, i32 %i, i32 6) |
950 %i_plus_1 = add i32 %i, 1 | 959 %i_plus_1 = add i32 %i, 1 |
951 %cmp = icmp eq i32 %i_plus_1, 1001 | 960 %cmp = icmp eq i32 %i_plus_1, 1001 |
952 br i1 %cmp, label %done, label %body | 961 br i1 %cmp, label %done, label %body |
953 done: | 962 done: |
954 ret void | 963 ret void |
955 } | 964 } |
956 ; O2-LABEL: test_xadd_regalloc | 965 ; O2-LABEL: test_xadd_regalloc |
957 ;;; Some register will be used in the xadd instruction. | 966 ;;; Some register will be used in the xadd instruction. |
958 ; O2: lock xadd DWORD PTR {{.*}},[[REG:e..]] | 967 ; O2: lock xadd DWORD PTR {{.*}},[[REG:e..]] |
959 ;;; Make sure that register isn't used again, e.g. as the induction variable. | 968 ;;; Make sure that register isn't used again, e.g. as the induction variable. |
960 ; O2-NOT: [[REG]] | 969 ; O2-NOT: [[REG]] |
961 ; O2: ret | 970 ; O2: ret |
962 | 971 |
963 ; Do the same test for the xchg instruction instead of xadd. | 972 ; Do the same test for the xchg instruction instead of xadd. |
964 define void @test_xchg_regalloc() { | 973 define internal void @test_xchg_regalloc() { |
965 entry: | 974 entry: |
966 br label %body | 975 br label %body |
967 body: | 976 body: |
968 %i = phi i32 [ 1, %entry ], [ %i_plus_1, %body ] | 977 %i = phi i32 [ 1, %entry ], [ %i_plus_1, %body ] |
969 %g = bitcast [4 x i8]* @Global32 to i32* | 978 %g = bitcast [4 x i8]* @Global32 to i32* |
970 %unused = call i32 @llvm.nacl.atomic.rmw.i32(i32 6, i32* %g, i32 %i, i32 6) | 979 %unused = call i32 @llvm.nacl.atomic.rmw.i32(i32 6, i32* %g, i32 %i, i32 6) |
971 %i_plus_1 = add i32 %i, 1 | 980 %i_plus_1 = add i32 %i, 1 |
972 %cmp = icmp eq i32 %i_plus_1, 1001 | 981 %cmp = icmp eq i32 %i_plus_1, 1001 |
973 br i1 %cmp, label %done, label %body | 982 br i1 %cmp, label %done, label %body |
974 done: | 983 done: |
975 ret void | 984 ret void |
976 } | 985 } |
977 ; O2-LABEL: test_xchg_regalloc | 986 ; O2-LABEL: test_xchg_regalloc |
978 ;;; Some register will be used in the xchg instruction. | 987 ;;; Some register will be used in the xchg instruction. |
979 ; O2: xchg DWORD PTR {{.*}},[[REG:e..]] | 988 ; O2: xchg DWORD PTR {{.*}},[[REG:e..]] |
980 ;;; Make sure that register isn't used again, e.g. as the induction variable. | 989 ;;; Make sure that register isn't used again, e.g. as the induction variable. |
981 ; O2-NOT: [[REG]] | 990 ; O2-NOT: [[REG]] |
982 ; O2: ret | 991 ; O2: ret |
983 | 992 |
984 ; Same test for cmpxchg. | 993 ; Same test for cmpxchg. |
985 define void @test_cmpxchg_regalloc() { | 994 define internal void @test_cmpxchg_regalloc() { |
986 entry: | 995 entry: |
987 br label %body | 996 br label %body |
988 body: | 997 body: |
989 %i = phi i32 [ 1, %entry ], [ %i_plus_1, %body ] | 998 %i = phi i32 [ 1, %entry ], [ %i_plus_1, %body ] |
990 %g = bitcast [4 x i8]* @Global32 to i32* | 999 %g = bitcast [4 x i8]* @Global32 to i32* |
991 %unused = call i32 @llvm.nacl.atomic.cmpxchg.i32(i32* %g, i32 %i, i32 %i, i32
6, i32 6) | 1000 %unused = call i32 @llvm.nacl.atomic.cmpxchg.i32(i32* %g, i32 %i, i32 %i, i32
6, i32 6) |
992 %i_plus_1 = add i32 %i, 1 | 1001 %i_plus_1 = add i32 %i, 1 |
993 %cmp = icmp eq i32 %i_plus_1, 1001 | 1002 %cmp = icmp eq i32 %i_plus_1, 1001 |
994 br i1 %cmp, label %done, label %body | 1003 br i1 %cmp, label %done, label %body |
995 done: | 1004 done: |
996 ret void | 1005 ret void |
997 } | 1006 } |
998 ; O2-LABEL: test_cmpxchg_regalloc | 1007 ; O2-LABEL: test_cmpxchg_regalloc |
999 ;;; eax and some other register will be used in the cmpxchg instruction. | 1008 ;;; eax and some other register will be used in the cmpxchg instruction. |
1000 ; O2: lock cmpxchg DWORD PTR {{.*}},[[REG:e..]] | 1009 ; O2: lock cmpxchg DWORD PTR {{.*}},[[REG:e..]] |
1001 ;;; Make sure eax isn't used again, e.g. as the induction variable. | 1010 ;;; Make sure eax isn't used again, e.g. as the induction variable. |
1002 ; O2-NOT: eax | 1011 ; O2-NOT: eax |
1003 ; O2: ret | 1012 ; O2: ret |
1004 | 1013 |
1005 ; Same test for cmpxchg8b. | 1014 ; Same test for cmpxchg8b. |
1006 define void @test_cmpxchg8b_regalloc() { | 1015 define internal void @test_cmpxchg8b_regalloc() { |
1007 entry: | 1016 entry: |
1008 br label %body | 1017 br label %body |
1009 body: | 1018 body: |
1010 %i = phi i32 [ 1, %entry ], [ %i_plus_1, %body ] | 1019 %i = phi i32 [ 1, %entry ], [ %i_plus_1, %body ] |
1011 %g = bitcast [8 x i8]* @Global64 to i64* | 1020 %g = bitcast [8 x i8]* @Global64 to i64* |
1012 %i_64 = zext i32 %i to i64 | 1021 %i_64 = zext i32 %i to i64 |
1013 %unused = call i64 @llvm.nacl.atomic.cmpxchg.i64(i64* %g, i64 %i_64, i64 %i_64
, i32 6, i32 6) | 1022 %unused = call i64 @llvm.nacl.atomic.cmpxchg.i64(i64* %g, i64 %i_64, i64 %i_64
, i32 6, i32 6) |
1014 %i_plus_1 = add i32 %i, 1 | 1023 %i_plus_1 = add i32 %i, 1 |
1015 %cmp = icmp eq i32 %i_plus_1, 1001 | 1024 %cmp = icmp eq i32 %i_plus_1, 1001 |
1016 br i1 %cmp, label %done, label %body | 1025 br i1 %cmp, label %done, label %body |
1017 done: | 1026 done: |
1018 ret void | 1027 ret void |
1019 } | 1028 } |
1020 ; O2-LABEL: test_cmpxchg8b_regalloc | 1029 ; O2-LABEL: test_cmpxchg8b_regalloc |
1021 ;;; eax and some other register will be used in the cmpxchg instruction. | 1030 ;;; eax and some other register will be used in the cmpxchg instruction. |
1022 ; O2: lock cmpxchg8b QWORD PTR | 1031 ; O2: lock cmpxchg8b QWORD PTR |
1023 ;;; Make sure eax/ecx/edx/ebx aren't used again, e.g. as the induction variable. | 1032 ;;; Make sure eax/ecx/edx/ebx aren't used again, e.g. as the induction variable. |
1024 ; O2-NOT: {{eax|ecx|edx|ebx}} | 1033 ; O2-NOT: {{eax|ecx|edx|ebx}} |
1025 ; O2: pop ebx | 1034 ; O2: pop ebx |
OLD | NEW |