1 // WebAssemblyInstrAtomics.td-WebAssembly Atomic codegen support-*- tablegen -*-
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// WebAssembly Atomic operand code-gen constructs.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
16 //===----------------------------------------------------------------------===//
18 multiclass ATOMIC_I<dag oops_r, dag iops_r, dag oops_s, dag iops_s,
19 list<dag> pattern_r, string asmstr_r = "",
20 string asmstr_s = "", bits<32> inst = -1> {
21 defm "" : I<oops_r, iops_r, oops_s, iops_s, pattern_r, asmstr_r, asmstr_s,
23 Requires<[HasAtomics]>;
26 defm ATOMIC_LOAD_I32 : WebAssemblyLoad<I32, "i32.atomic.load", 0xfe10>;
27 defm ATOMIC_LOAD_I64 : WebAssemblyLoad<I64, "i64.atomic.load", 0xfe11>;
29 // Select loads with no constant offset.
30 let Predicates = [HasAtomics] in {
31 def : LoadPatNoOffset<i32, atomic_load_32, ATOMIC_LOAD_I32>;
32 def : LoadPatNoOffset<i64, atomic_load_64, ATOMIC_LOAD_I64>;
34 // Select loads with a constant offset.
36 // Pattern with address + immediate offset
37 def : LoadPatImmOff<i32, atomic_load_32, regPlusImm, ATOMIC_LOAD_I32>;
38 def : LoadPatImmOff<i64, atomic_load_64, regPlusImm, ATOMIC_LOAD_I64>;
39 def : LoadPatImmOff<i32, atomic_load_32, or_is_add, ATOMIC_LOAD_I32>;
40 def : LoadPatImmOff<i64, atomic_load_64, or_is_add, ATOMIC_LOAD_I64>;
42 def : LoadPatGlobalAddr<i32, atomic_load_32, ATOMIC_LOAD_I32>;
43 def : LoadPatGlobalAddr<i64, atomic_load_64, ATOMIC_LOAD_I64>;
45 def : LoadPatExternalSym<i32, atomic_load_32, ATOMIC_LOAD_I32>;
46 def : LoadPatExternalSym<i64, atomic_load_64, ATOMIC_LOAD_I64>;
48 // Select loads with just a constant offset.
49 def : LoadPatOffsetOnly<i32, atomic_load_32, ATOMIC_LOAD_I32>;
50 def : LoadPatOffsetOnly<i64, atomic_load_64, ATOMIC_LOAD_I64>;
52 def : LoadPatGlobalAddrOffOnly<i32, atomic_load_32, ATOMIC_LOAD_I32>;
53 def : LoadPatGlobalAddrOffOnly<i64, atomic_load_64, ATOMIC_LOAD_I64>;
55 def : LoadPatExternSymOffOnly<i32, atomic_load_32, ATOMIC_LOAD_I32>;
56 def : LoadPatExternSymOffOnly<i64, atomic_load_64, ATOMIC_LOAD_I64>;
58 } // Predicates = [HasAtomics]
60 // Extending loads. Note that there are only zero-extending atomic loads, no
61 // sign-extending loads.
62 defm ATOMIC_LOAD8_U_I32 : WebAssemblyLoad<I32, "i32.atomic.load8_u", 0xfe12>;
63 defm ATOMIC_LOAD16_U_I32 : WebAssemblyLoad<I32, "i32.atomic.load16_u", 0xfe13>;
64 defm ATOMIC_LOAD8_U_I64 : WebAssemblyLoad<I64, "i64.atomic.load8_u", 0xfe14>;
65 defm ATOMIC_LOAD16_U_I64 : WebAssemblyLoad<I64, "i64.atomic.load16_u", 0xfe15>;
66 defm ATOMIC_LOAD32_U_I64 : WebAssemblyLoad<I64, "i64.atomic.load32_u", 0xfe16>;
68 // Fragments for extending loads. These are different from regular loads because
69 // the SDNodes are derived from AtomicSDNode rather than LoadSDNode and
70 // therefore don't have the extension type field. So instead of matching that,
71 // we match the patterns that the type legalizer expands them to.
73 // We directly match zext patterns and select the zext atomic loads.
74 // i32 (zext (i8 (atomic_load_8))) gets legalized to
75 // i32 (and (i32 (atomic_load_8)), 255)
76 // These can be selected to a single zero-extending atomic load instruction.
78 PatFrag<(ops node:$addr), (and (i32 (atomic_load_8 node:$addr)), 255)>;
79 def zext_aload_16_32 :
80 PatFrag<(ops node:$addr), (and (i32 (atomic_load_16 node:$addr)), 65535)>;
81 // Unlike regular loads, extension to i64 is handled differently than i32.
82 // i64 (zext (i8 (atomic_load_8))) gets legalized to
83 // i64 (and (i64 (anyext (i32 (atomic_load_8)))), 255)
85 PatFrag<(ops node:$addr),
86 (and (i64 (anyext (i32 (atomic_load_8 node:$addr)))), 255)>;
87 def zext_aload_16_64 :
88 PatFrag<(ops node:$addr),
89 (and (i64 (anyext (i32 (atomic_load_16 node:$addr)))), 65535)>;
90 def zext_aload_32_64 :
91 PatFrag<(ops node:$addr),
92 (zext (i32 (atomic_load node:$addr)))>;
94 // We don't have single sext atomic load instructions. So for sext loads, we
95 // match bare subword loads (for 32-bit results) and anyext loads (for 64-bit
96 // results) and select a zext load; the next instruction will be sext_inreg
97 // which is selected by itself.
99 PatFrag<(ops node:$addr), (anyext (i32 (atomic_load_8 node:$addr)))>;
100 def sext_aload_16_64 :
101 PatFrag<(ops node:$addr), (anyext (i32 (atomic_load_16 node:$addr)))>;
103 let Predicates = [HasAtomics] in {
104 // Select zero-extending loads with no constant offset.
105 def : LoadPatNoOffset<i32, zext_aload_8_32, ATOMIC_LOAD8_U_I32>;
106 def : LoadPatNoOffset<i32, zext_aload_16_32, ATOMIC_LOAD16_U_I32>;
107 def : LoadPatNoOffset<i64, zext_aload_8_64, ATOMIC_LOAD8_U_I64>;
108 def : LoadPatNoOffset<i64, zext_aload_16_64, ATOMIC_LOAD16_U_I64>;
109 def : LoadPatNoOffset<i64, zext_aload_32_64, ATOMIC_LOAD32_U_I64>;
111 // Select sign-extending loads with no constant offset
112 def : LoadPatNoOffset<i32, atomic_load_8, ATOMIC_LOAD8_U_I32>;
113 def : LoadPatNoOffset<i32, atomic_load_16, ATOMIC_LOAD16_U_I32>;
114 def : LoadPatNoOffset<i64, sext_aload_8_64, ATOMIC_LOAD8_U_I64>;
115 def : LoadPatNoOffset<i64, sext_aload_16_64, ATOMIC_LOAD16_U_I64>;
116 // 32->64 sext load gets selected as i32.atomic.load, i64.extend_i32_s
118 // Zero-extending loads with constant offset
119 def : LoadPatImmOff<i32, zext_aload_8_32, regPlusImm, ATOMIC_LOAD8_U_I32>;
120 def : LoadPatImmOff<i32, zext_aload_16_32, regPlusImm, ATOMIC_LOAD16_U_I32>;
121 def : LoadPatImmOff<i32, zext_aload_8_32, or_is_add, ATOMIC_LOAD8_U_I32>;
122 def : LoadPatImmOff<i32, zext_aload_16_32, or_is_add, ATOMIC_LOAD16_U_I32>;
123 def : LoadPatImmOff<i64, zext_aload_8_64, regPlusImm, ATOMIC_LOAD8_U_I64>;
124 def : LoadPatImmOff<i64, zext_aload_16_64, regPlusImm, ATOMIC_LOAD16_U_I64>;
125 def : LoadPatImmOff<i64, zext_aload_32_64, regPlusImm, ATOMIC_LOAD32_U_I64>;
126 def : LoadPatImmOff<i64, zext_aload_8_64, or_is_add, ATOMIC_LOAD8_U_I64>;
127 def : LoadPatImmOff<i64, zext_aload_16_64, or_is_add, ATOMIC_LOAD16_U_I64>;
128 def : LoadPatImmOff<i64, zext_aload_32_64, or_is_add, ATOMIC_LOAD32_U_I64>;
130 // Sign-extending loads with constant offset
131 def : LoadPatImmOff<i32, atomic_load_8, regPlusImm, ATOMIC_LOAD8_U_I32>;
132 def : LoadPatImmOff<i32, atomic_load_16, regPlusImm, ATOMIC_LOAD16_U_I32>;
133 def : LoadPatImmOff<i32, atomic_load_8, or_is_add, ATOMIC_LOAD8_U_I32>;
134 def : LoadPatImmOff<i32, atomic_load_16, or_is_add, ATOMIC_LOAD16_U_I32>;
135 def : LoadPatImmOff<i64, sext_aload_8_64, regPlusImm, ATOMIC_LOAD8_U_I64>;
136 def : LoadPatImmOff<i64, sext_aload_16_64, regPlusImm, ATOMIC_LOAD16_U_I64>;
137 def : LoadPatImmOff<i64, sext_aload_8_64, or_is_add, ATOMIC_LOAD8_U_I64>;
138 def : LoadPatImmOff<i64, sext_aload_16_64, or_is_add, ATOMIC_LOAD16_U_I64>;
139 // No 32->64 patterns, just use i32.atomic.load and i64.extend_s/i64
141 def : LoadPatGlobalAddr<i32, zext_aload_8_32, ATOMIC_LOAD8_U_I32>;
142 def : LoadPatGlobalAddr<i32, zext_aload_16_32, ATOMIC_LOAD16_U_I32>;
143 def : LoadPatGlobalAddr<i64, zext_aload_8_64, ATOMIC_LOAD8_U_I64>;
144 def : LoadPatGlobalAddr<i64, zext_aload_16_64, ATOMIC_LOAD16_U_I64>;
145 def : LoadPatGlobalAddr<i64, zext_aload_32_64, ATOMIC_LOAD32_U_I64>;
146 def : LoadPatGlobalAddr<i32, atomic_load_8, ATOMIC_LOAD8_U_I32>;
147 def : LoadPatGlobalAddr<i32, atomic_load_16, ATOMIC_LOAD16_U_I32>;
148 def : LoadPatGlobalAddr<i64, sext_aload_8_64, ATOMIC_LOAD8_U_I64>;
149 def : LoadPatGlobalAddr<i64, sext_aload_16_64, ATOMIC_LOAD16_U_I64>;
151 def : LoadPatExternalSym<i32, zext_aload_8_32, ATOMIC_LOAD8_U_I32>;
152 def : LoadPatExternalSym<i32, zext_aload_16_32, ATOMIC_LOAD16_U_I32>;
153 def : LoadPatExternalSym<i64, zext_aload_8_64, ATOMIC_LOAD8_U_I64>;
154 def : LoadPatExternalSym<i64, zext_aload_16_64, ATOMIC_LOAD16_U_I64>;
155 def : LoadPatExternalSym<i64, zext_aload_32_64, ATOMIC_LOAD32_U_I64>;
156 def : LoadPatExternalSym<i32, atomic_load_8, ATOMIC_LOAD8_U_I32>;
157 def : LoadPatExternalSym<i32, atomic_load_16, ATOMIC_LOAD16_U_I32>;
158 def : LoadPatExternalSym<i64, sext_aload_8_64, ATOMIC_LOAD8_U_I64>;
159 def : LoadPatExternalSym<i64, sext_aload_16_64, ATOMIC_LOAD16_U_I64>;
161 // Extending loads with just a constant offset
162 def : LoadPatOffsetOnly<i32, zext_aload_8_32, ATOMIC_LOAD8_U_I32>;
163 def : LoadPatOffsetOnly<i32, zext_aload_16_32, ATOMIC_LOAD16_U_I32>;
164 def : LoadPatOffsetOnly<i64, zext_aload_8_64, ATOMIC_LOAD8_U_I64>;
165 def : LoadPatOffsetOnly<i64, zext_aload_16_64, ATOMIC_LOAD16_U_I64>;
166 def : LoadPatOffsetOnly<i64, zext_aload_32_64, ATOMIC_LOAD32_U_I64>;
167 def : LoadPatOffsetOnly<i32, atomic_load_8, ATOMIC_LOAD8_U_I32>;
168 def : LoadPatOffsetOnly<i32, atomic_load_16, ATOMIC_LOAD16_U_I32>;
169 def : LoadPatOffsetOnly<i64, sext_aload_8_64, ATOMIC_LOAD8_U_I64>;
170 def : LoadPatOffsetOnly<i64, sext_aload_16_64, ATOMIC_LOAD16_U_I64>;
172 def : LoadPatGlobalAddrOffOnly<i32, zext_aload_8_32, ATOMIC_LOAD8_U_I32>;
173 def : LoadPatGlobalAddrOffOnly<i32, zext_aload_16_32, ATOMIC_LOAD16_U_I32>;
174 def : LoadPatGlobalAddrOffOnly<i64, zext_aload_8_64, ATOMIC_LOAD8_U_I64>;
175 def : LoadPatGlobalAddrOffOnly<i64, zext_aload_16_64, ATOMIC_LOAD16_U_I64>;
176 def : LoadPatGlobalAddrOffOnly<i64, zext_aload_32_64, ATOMIC_LOAD32_U_I64>;
177 def : LoadPatGlobalAddrOffOnly<i32, atomic_load_8, ATOMIC_LOAD8_U_I32>;
178 def : LoadPatGlobalAddrOffOnly<i32, atomic_load_16, ATOMIC_LOAD16_U_I32>;
179 def : LoadPatGlobalAddrOffOnly<i64, sext_aload_8_64, ATOMIC_LOAD8_U_I64>;
180 def : LoadPatGlobalAddrOffOnly<i64, sext_aload_16_64, ATOMIC_LOAD16_U_I64>;
182 def : LoadPatExternSymOffOnly<i32, zext_aload_8_32, ATOMIC_LOAD8_U_I32>;
183 def : LoadPatExternSymOffOnly<i32, zext_aload_16_32, ATOMIC_LOAD16_U_I32>;
184 def : LoadPatExternSymOffOnly<i64, zext_aload_8_64, ATOMIC_LOAD8_U_I64>;
185 def : LoadPatExternSymOffOnly<i64, zext_aload_16_64, ATOMIC_LOAD16_U_I64>;
186 def : LoadPatExternSymOffOnly<i64, zext_aload_32_64, ATOMIC_LOAD32_U_I64>;
187 def : LoadPatExternSymOffOnly<i32, atomic_load_8, ATOMIC_LOAD8_U_I32>;
188 def : LoadPatExternSymOffOnly<i32, atomic_load_16, ATOMIC_LOAD16_U_I32>;
189 def : LoadPatExternSymOffOnly<i64, sext_aload_8_64, ATOMIC_LOAD8_U_I64>;
190 def : LoadPatExternSymOffOnly<i64, sext_aload_16_64, ATOMIC_LOAD16_U_I64>;
192 } // Predicates = [HasAtomics]
194 //===----------------------------------------------------------------------===//
196 //===----------------------------------------------------------------------===//
198 defm ATOMIC_STORE_I32 : WebAssemblyStore<I32, "i32.atomic.store", 0xfe17>;
199 defm ATOMIC_STORE_I64 : WebAssemblyStore<I64, "i64.atomic.store", 0xfe18>;
201 // We need an 'atomic' version of store patterns because store and atomic_store
202 // nodes have different operand orders:
203 // store: (store $val, $ptr)
204 // atomic_store: (store $ptr, $val)
206 let Predicates = [HasAtomics] in {
208 // Select stores with no constant offset.
209 class AStorePatNoOffset<ValueType ty, PatFrag kind, NI inst> :
210 Pat<(kind I32:$addr, ty:$val), (inst 0, 0, I32:$addr, ty:$val)>;
211 def : AStorePatNoOffset<i32, atomic_store_32, ATOMIC_STORE_I32>;
212 def : AStorePatNoOffset<i64, atomic_store_64, ATOMIC_STORE_I64>;
214 // Select stores with a constant offset.
216 // Pattern with address + immediate offset
217 class AStorePatImmOff<ValueType ty, PatFrag kind, PatFrag operand, NI inst> :
218 Pat<(kind (operand I32:$addr, imm:$off), ty:$val),
219 (inst 0, imm:$off, I32:$addr, ty:$val)>;
220 def : AStorePatImmOff<i32, atomic_store_32, regPlusImm, ATOMIC_STORE_I32>;
221 def : AStorePatImmOff<i64, atomic_store_64, regPlusImm, ATOMIC_STORE_I64>;
222 def : AStorePatImmOff<i32, atomic_store_32, or_is_add, ATOMIC_STORE_I32>;
223 def : AStorePatImmOff<i64, atomic_store_64, or_is_add, ATOMIC_STORE_I64>;
225 class AStorePatGlobalAddr<ValueType ty, PatFrag kind, NI inst> :
226 Pat<(kind (regPlusGA I32:$addr, (WebAssemblywrapper tglobaladdr:$off)),
228 (inst 0, tglobaladdr:$off, I32:$addr, ty:$val)>;
229 def : AStorePatGlobalAddr<i32, atomic_store_32, ATOMIC_STORE_I32>;
230 def : AStorePatGlobalAddr<i64, atomic_store_64, ATOMIC_STORE_I64>;
232 class AStorePatExternalSym<ValueType ty, PatFrag kind, NI inst> :
233 Pat<(kind (add I32:$addr, (WebAssemblywrapper texternalsym:$off)), ty:$val),
234 (inst 0, texternalsym:$off, I32:$addr, ty:$val)>;
235 def : AStorePatExternalSym<i32, atomic_store_32, ATOMIC_STORE_I32>;
236 def : AStorePatExternalSym<i64, atomic_store_64, ATOMIC_STORE_I64>;
238 // Select stores with just a constant offset.
239 class AStorePatOffsetOnly<ValueType ty, PatFrag kind, NI inst> :
240 Pat<(kind imm:$off, ty:$val), (inst 0, imm:$off, (CONST_I32 0), ty:$val)>;
241 def : AStorePatOffsetOnly<i32, atomic_store_32, ATOMIC_STORE_I32>;
242 def : AStorePatOffsetOnly<i64, atomic_store_64, ATOMIC_STORE_I64>;
244 class AStorePatGlobalAddrOffOnly<ValueType ty, PatFrag kind, NI inst> :
245 Pat<(kind (WebAssemblywrapper tglobaladdr:$off), ty:$val),
246 (inst 0, tglobaladdr:$off, (CONST_I32 0), ty:$val)>;
247 def : AStorePatGlobalAddrOffOnly<i32, atomic_store_32, ATOMIC_STORE_I32>;
248 def : AStorePatGlobalAddrOffOnly<i64, atomic_store_64, ATOMIC_STORE_I64>;
250 class AStorePatExternSymOffOnly<ValueType ty, PatFrag kind, NI inst> :
251 Pat<(kind (WebAssemblywrapper texternalsym:$off), ty:$val),
252 (inst 0, texternalsym:$off, (CONST_I32 0), ty:$val)>;
253 def : AStorePatExternSymOffOnly<i32, atomic_store_32, ATOMIC_STORE_I32>;
254 def : AStorePatExternSymOffOnly<i64, atomic_store_64, ATOMIC_STORE_I64>;
256 } // Predicates = [HasAtomics]
258 // Truncating stores.
259 defm ATOMIC_STORE8_I32 : WebAssemblyStore<I32, "i32.atomic.store8", 0xfe19>;
260 defm ATOMIC_STORE16_I32 : WebAssemblyStore<I32, "i32.atomic.store16", 0xfe1a>;
261 defm ATOMIC_STORE8_I64 : WebAssemblyStore<I64, "i64.atomic.store8", 0xfe1b>;
262 defm ATOMIC_STORE16_I64 : WebAssemblyStore<I64, "i64.atomic.store16", 0xfe1c>;
263 defm ATOMIC_STORE32_I64 : WebAssemblyStore<I64, "i64.atomic.store32", 0xfe1d>;
265 // Fragments for truncating stores.
267 // We don't have single truncating atomic store instructions. For 32-bit
268 // instructions, we just need to match bare atomic stores. On the other hand,
269 // truncating stores from i64 values are once truncated to i32 first.
270 class trunc_astore_64<PatFrag kind> :
271 PatFrag<(ops node:$addr, node:$val),
272 (kind node:$addr, (i32 (trunc (i64 node:$val))))>;
273 def trunc_astore_8_64 : trunc_astore_64<atomic_store_8>;
274 def trunc_astore_16_64 : trunc_astore_64<atomic_store_16>;
275 def trunc_astore_32_64 : trunc_astore_64<atomic_store_32>;
277 let Predicates = [HasAtomics] in {
279 // Truncating stores with no constant offset
280 def : AStorePatNoOffset<i32, atomic_store_8, ATOMIC_STORE8_I32>;
281 def : AStorePatNoOffset<i32, atomic_store_16, ATOMIC_STORE16_I32>;
282 def : AStorePatNoOffset<i64, trunc_astore_8_64, ATOMIC_STORE8_I64>;
283 def : AStorePatNoOffset<i64, trunc_astore_16_64, ATOMIC_STORE16_I64>;
284 def : AStorePatNoOffset<i64, trunc_astore_32_64, ATOMIC_STORE32_I64>;
286 // Truncating stores with a constant offset
287 def : AStorePatImmOff<i32, atomic_store_8, regPlusImm, ATOMIC_STORE8_I32>;
288 def : AStorePatImmOff<i32, atomic_store_16, regPlusImm, ATOMIC_STORE16_I32>;
289 def : AStorePatImmOff<i64, trunc_astore_8_64, regPlusImm, ATOMIC_STORE8_I64>;
290 def : AStorePatImmOff<i64, trunc_astore_16_64, regPlusImm, ATOMIC_STORE16_I64>;
291 def : AStorePatImmOff<i64, trunc_astore_32_64, regPlusImm, ATOMIC_STORE32_I64>;
292 def : AStorePatImmOff<i32, atomic_store_8, or_is_add, ATOMIC_STORE8_I32>;
293 def : AStorePatImmOff<i32, atomic_store_16, or_is_add, ATOMIC_STORE16_I32>;
294 def : AStorePatImmOff<i64, trunc_astore_8_64, or_is_add, ATOMIC_STORE8_I64>;
295 def : AStorePatImmOff<i64, trunc_astore_16_64, or_is_add, ATOMIC_STORE16_I64>;
296 def : AStorePatImmOff<i64, trunc_astore_32_64, or_is_add, ATOMIC_STORE32_I64>;
298 def : AStorePatGlobalAddr<i32, atomic_store_8, ATOMIC_STORE8_I32>;
299 def : AStorePatGlobalAddr<i32, atomic_store_16, ATOMIC_STORE16_I32>;
300 def : AStorePatGlobalAddr<i64, trunc_astore_8_64, ATOMIC_STORE8_I64>;
301 def : AStorePatGlobalAddr<i64, trunc_astore_16_64, ATOMIC_STORE16_I64>;
302 def : AStorePatGlobalAddr<i64, trunc_astore_32_64, ATOMIC_STORE32_I64>;
304 def : AStorePatExternalSym<i32, atomic_store_8, ATOMIC_STORE8_I32>;
305 def : AStorePatExternalSym<i32, atomic_store_16, ATOMIC_STORE16_I32>;
306 def : AStorePatExternalSym<i64, trunc_astore_8_64, ATOMIC_STORE8_I64>;
307 def : AStorePatExternalSym<i64, trunc_astore_16_64, ATOMIC_STORE16_I64>;
308 def : AStorePatExternalSym<i64, trunc_astore_32_64, ATOMIC_STORE32_I64>;
310 // Truncating stores with just a constant offset
311 def : AStorePatOffsetOnly<i32, atomic_store_8, ATOMIC_STORE8_I32>;
312 def : AStorePatOffsetOnly<i32, atomic_store_16, ATOMIC_STORE16_I32>;
313 def : AStorePatOffsetOnly<i64, trunc_astore_8_64, ATOMIC_STORE8_I64>;
314 def : AStorePatOffsetOnly<i64, trunc_astore_16_64, ATOMIC_STORE16_I64>;
315 def : AStorePatOffsetOnly<i64, trunc_astore_32_64, ATOMIC_STORE32_I64>;
317 def : AStorePatGlobalAddrOffOnly<i32, atomic_store_8, ATOMIC_STORE8_I32>;
318 def : AStorePatGlobalAddrOffOnly<i32, atomic_store_16, ATOMIC_STORE16_I32>;
319 def : AStorePatGlobalAddrOffOnly<i64, trunc_astore_8_64, ATOMIC_STORE8_I64>;
320 def : AStorePatGlobalAddrOffOnly<i64, trunc_astore_16_64, ATOMIC_STORE16_I64>;
321 def : AStorePatGlobalAddrOffOnly<i64, trunc_astore_32_64, ATOMIC_STORE32_I64>;
323 def : AStorePatExternSymOffOnly<i32, atomic_store_8, ATOMIC_STORE8_I32>;
324 def : AStorePatExternSymOffOnly<i32, atomic_store_16, ATOMIC_STORE16_I32>;
325 def : AStorePatExternSymOffOnly<i64, trunc_astore_8_64, ATOMIC_STORE8_I64>;
326 def : AStorePatExternSymOffOnly<i64, trunc_astore_16_64, ATOMIC_STORE16_I64>;
327 def : AStorePatExternSymOffOnly<i64, trunc_astore_32_64, ATOMIC_STORE32_I64>;
329 } // Predicates = [HasAtomics]
331 //===----------------------------------------------------------------------===//
332 // Atomic binary read-modify-writes
333 //===----------------------------------------------------------------------===//
335 multiclass WebAssemblyBinRMW<WebAssemblyRegClass rc, string Name, int Opcode> {
336 defm "" : I<(outs rc:$dst),
337 (ins P2Align:$p2align, offset32_op:$off, I32:$addr, rc:$val),
338 (outs), (ins P2Align:$p2align, offset32_op:$off), [],
339 !strconcat(Name, "\t$dst, ${off}(${addr})${p2align}, $val"),
340 !strconcat(Name, "\t${off}, ${p2align}"), Opcode>;
343 defm ATOMIC_RMW_ADD_I32 : WebAssemblyBinRMW<I32, "i32.atomic.rmw.add", 0xfe1e>;
344 defm ATOMIC_RMW_ADD_I64 : WebAssemblyBinRMW<I64, "i64.atomic.rmw.add", 0xfe1f>;
345 defm ATOMIC_RMW8_U_ADD_I32 :
346 WebAssemblyBinRMW<I32, "i32.atomic.rmw8.add_u", 0xfe20>;
347 defm ATOMIC_RMW16_U_ADD_I32 :
348 WebAssemblyBinRMW<I32, "i32.atomic.rmw16.add_u", 0xfe21>;
349 defm ATOMIC_RMW8_U_ADD_I64 :
350 WebAssemblyBinRMW<I64, "i64.atomic.rmw8.add_u", 0xfe22>;
351 defm ATOMIC_RMW16_U_ADD_I64 :
352 WebAssemblyBinRMW<I64, "i64.atomic.rmw16.add_u", 0xfe23>;
353 defm ATOMIC_RMW32_U_ADD_I64 :
354 WebAssemblyBinRMW<I64, "i64.atomic.rmw32.add_u", 0xfe24>;
356 defm ATOMIC_RMW_SUB_I32 : WebAssemblyBinRMW<I32, "i32.atomic.rmw.sub", 0xfe25>;
357 defm ATOMIC_RMW_SUB_I64 : WebAssemblyBinRMW<I64, "i64.atomic.rmw.sub", 0xfe26>;
358 defm ATOMIC_RMW8_U_SUB_I32 :
359 WebAssemblyBinRMW<I32, "i32.atomic.rmw8.sub_u", 0xfe27>;
360 defm ATOMIC_RMW16_U_SUB_I32 :
361 WebAssemblyBinRMW<I32, "i32.atomic.rmw16.sub_u", 0xfe28>;
362 defm ATOMIC_RMW8_U_SUB_I64 :
363 WebAssemblyBinRMW<I64, "i64.atomic.rmw8.sub_u", 0xfe29>;
364 defm ATOMIC_RMW16_U_SUB_I64 :
365 WebAssemblyBinRMW<I64, "i64.atomic.rmw16.sub_u", 0xfe2a>;
366 defm ATOMIC_RMW32_U_SUB_I64 :
367 WebAssemblyBinRMW<I64, "i64.atomic.rmw32.sub_u", 0xfe2b>;
369 defm ATOMIC_RMW_AND_I32 : WebAssemblyBinRMW<I32, "i32.atomic.rmw.and", 0xfe2c>;
370 defm ATOMIC_RMW_AND_I64 : WebAssemblyBinRMW<I64, "i64.atomic.rmw.and", 0xfe2d>;
371 defm ATOMIC_RMW8_U_AND_I32 :
372 WebAssemblyBinRMW<I32, "i32.atomic.rmw8.and_u", 0xfe2e>;
373 defm ATOMIC_RMW16_U_AND_I32 :
374 WebAssemblyBinRMW<I32, "i32.atomic.rmw16.and_u", 0xfe2f>;
375 defm ATOMIC_RMW8_U_AND_I64 :
376 WebAssemblyBinRMW<I64, "i64.atomic.rmw8.and_u", 0xfe30>;
377 defm ATOMIC_RMW16_U_AND_I64 :
378 WebAssemblyBinRMW<I64, "i64.atomic.rmw16.and_u", 0xfe31>;
379 defm ATOMIC_RMW32_U_AND_I64 :
380 WebAssemblyBinRMW<I64, "i64.atomic.rmw32.and_u", 0xfe32>;
382 defm ATOMIC_RMW_OR_I32 : WebAssemblyBinRMW<I32, "i32.atomic.rmw.or", 0xfe33>;
383 defm ATOMIC_RMW_OR_I64 : WebAssemblyBinRMW<I64, "i64.atomic.rmw.or", 0xfe34>;
384 defm ATOMIC_RMW8_U_OR_I32 :
385 WebAssemblyBinRMW<I32, "i32.atomic.rmw8.or_u", 0xfe35>;
386 defm ATOMIC_RMW16_U_OR_I32 :
387 WebAssemblyBinRMW<I32, "i32.atomic.rmw16.or_u", 0xfe36>;
388 defm ATOMIC_RMW8_U_OR_I64 :
389 WebAssemblyBinRMW<I64, "i64.atomic.rmw8.or_u", 0xfe37>;
390 defm ATOMIC_RMW16_U_OR_I64 :
391 WebAssemblyBinRMW<I64, "i64.atomic.rmw16.or_u", 0xfe38>;
392 defm ATOMIC_RMW32_U_OR_I64 :
393 WebAssemblyBinRMW<I64, "i64.atomic.rmw32.or_u", 0xfe39>;
395 defm ATOMIC_RMW_XOR_I32 : WebAssemblyBinRMW<I32, "i32.atomic.rmw.xor", 0xfe3a>;
396 defm ATOMIC_RMW_XOR_I64 : WebAssemblyBinRMW<I64, "i64.atomic.rmw.xor", 0xfe3b>;
397 defm ATOMIC_RMW8_U_XOR_I32 :
398 WebAssemblyBinRMW<I32, "i32.atomic.rmw8.xor_u", 0xfe3c>;
399 defm ATOMIC_RMW16_U_XOR_I32 :
400 WebAssemblyBinRMW<I32, "i32.atomic.rmw16.xor_u", 0xfe3d>;
401 defm ATOMIC_RMW8_U_XOR_I64 :
402 WebAssemblyBinRMW<I64, "i64.atomic.rmw8.xor_u", 0xfe3e>;
403 defm ATOMIC_RMW16_U_XOR_I64 :
404 WebAssemblyBinRMW<I64, "i64.atomic.rmw16.xor_u", 0xfe3f>;
405 defm ATOMIC_RMW32_U_XOR_I64 :
406 WebAssemblyBinRMW<I64, "i64.atomic.rmw32.xor_u", 0xfe40>;
408 defm ATOMIC_RMW_XCHG_I32 :
409 WebAssemblyBinRMW<I32, "i32.atomic.rmw.xchg", 0xfe41>;
410 defm ATOMIC_RMW_XCHG_I64 :
411 WebAssemblyBinRMW<I64, "i64.atomic.rmw.xchg", 0xfe42>;
412 defm ATOMIC_RMW8_U_XCHG_I32 :
413 WebAssemblyBinRMW<I32, "i32.atomic.rmw8.xchg_u", 0xfe43>;
414 defm ATOMIC_RMW16_U_XCHG_I32 :
415 WebAssemblyBinRMW<I32, "i32.atomic.rmw16.xchg_u", 0xfe44>;
416 defm ATOMIC_RMW8_U_XCHG_I64 :
417 WebAssemblyBinRMW<I64, "i64.atomic.rmw8.xchg_u", 0xfe45>;
418 defm ATOMIC_RMW16_U_XCHG_I64 :
419 WebAssemblyBinRMW<I64, "i64.atomic.rmw16.xchg_u", 0xfe46>;
420 defm ATOMIC_RMW32_U_XCHG_I64 :
421 WebAssemblyBinRMW<I64, "i64.atomic.rmw32.xchg_u", 0xfe47>;
423 // Select binary RMWs with no constant offset.
424 class BinRMWPatNoOffset<ValueType ty, PatFrag kind, NI inst> :
425 Pat<(ty (kind I32:$addr, ty:$val)), (inst 0, 0, I32:$addr, ty:$val)>;
427 // Select binary RMWs with a constant offset.
429 // Pattern with address + immediate offset
430 class BinRMWPatImmOff<ValueType ty, PatFrag kind, PatFrag operand, NI inst> :
431 Pat<(ty (kind (operand I32:$addr, imm:$off), ty:$val)),
432 (inst 0, imm:$off, I32:$addr, ty:$val)>;
434 class BinRMWPatGlobalAddr<ValueType ty, PatFrag kind, NI inst> :
435 Pat<(ty (kind (regPlusGA I32:$addr, (WebAssemblywrapper tglobaladdr:$off)),
437 (inst 0, tglobaladdr:$off, I32:$addr, ty:$val)>;
439 class BinRMWPatExternalSym<ValueType ty, PatFrag kind, NI inst> :
440 Pat<(ty (kind (add I32:$addr, (WebAssemblywrapper texternalsym:$off)),
442 (inst 0, texternalsym:$off, I32:$addr, ty:$val)>;
444 // Select binary RMWs with just a constant offset.
445 class BinRMWPatOffsetOnly<ValueType ty, PatFrag kind, NI inst> :
446 Pat<(ty (kind imm:$off, ty:$val)),
447 (inst 0, imm:$off, (CONST_I32 0), ty:$val)>;
449 class BinRMWPatGlobalAddrOffOnly<ValueType ty, PatFrag kind, NI inst> :
450 Pat<(ty (kind (WebAssemblywrapper tglobaladdr:$off), ty:$val)),
451 (inst 0, tglobaladdr:$off, (CONST_I32 0), ty:$val)>;
453 class BinRMWPatExternSymOffOnly<ValueType ty, PatFrag kind, NI inst> :
454 Pat<(ty (kind (WebAssemblywrapper texternalsym:$off), ty:$val)),
455 (inst 0, texternalsym:$off, (CONST_I32 0), ty:$val)>;
457 // Patterns for various addressing modes.
458 multiclass BinRMWPattern<PatFrag rmw_32, PatFrag rmw_64, NI inst_32,
460 def : BinRMWPatNoOffset<i32, rmw_32, inst_32>;
461 def : BinRMWPatNoOffset<i64, rmw_64, inst_64>;
463 def : BinRMWPatImmOff<i32, rmw_32, regPlusImm, inst_32>;
464 def : BinRMWPatImmOff<i64, rmw_64, regPlusImm, inst_64>;
465 def : BinRMWPatImmOff<i32, rmw_32, or_is_add, inst_32>;
466 def : BinRMWPatImmOff<i64, rmw_64, or_is_add, inst_64>;
468 def : BinRMWPatGlobalAddr<i32, rmw_32, inst_32>;
469 def : BinRMWPatGlobalAddr<i64, rmw_64, inst_64>;
471 def : BinRMWPatExternalSym<i32, rmw_32, inst_32>;
472 def : BinRMWPatExternalSym<i64, rmw_64, inst_64>;
474 def : BinRMWPatOffsetOnly<i32, rmw_32, inst_32>;
475 def : BinRMWPatOffsetOnly<i64, rmw_64, inst_64>;
477 def : BinRMWPatGlobalAddrOffOnly<i32, rmw_32, inst_32>;
478 def : BinRMWPatGlobalAddrOffOnly<i64, rmw_64, inst_64>;
480 def : BinRMWPatExternSymOffOnly<i32, rmw_32, inst_32>;
481 def : BinRMWPatExternSymOffOnly<i64, rmw_64, inst_64>;
484 let Predicates = [HasAtomics] in {
485 defm : BinRMWPattern<atomic_load_add_32, atomic_load_add_64, ATOMIC_RMW_ADD_I32,
487 defm : BinRMWPattern<atomic_load_sub_32, atomic_load_sub_64, ATOMIC_RMW_SUB_I32,
489 defm : BinRMWPattern<atomic_load_and_32, atomic_load_and_64, ATOMIC_RMW_AND_I32,
491 defm : BinRMWPattern<atomic_load_or_32, atomic_load_or_64, ATOMIC_RMW_OR_I32,
493 defm : BinRMWPattern<atomic_load_xor_32, atomic_load_xor_64, ATOMIC_RMW_XOR_I32,
495 defm : BinRMWPattern<atomic_swap_32, atomic_swap_64, ATOMIC_RMW_XCHG_I32,
496 ATOMIC_RMW_XCHG_I64>;
497 } // Predicates = [HasAtomics]
499 // Truncating & zero-extending binary RMW patterns.
500 // These are combined patterns of truncating store patterns and zero-extending
501 // load patterns above.
502 class zext_bin_rmw_8_32<PatFrag kind> :
503 PatFrag<(ops node:$addr, node:$val),
504 (and (i32 (kind node:$addr, node:$val)), 255)>;
505 class zext_bin_rmw_16_32<PatFrag kind> :
506 PatFrag<(ops node:$addr, node:$val),
507 (and (i32 (kind node:$addr, node:$val)), 65535)>;
508 class zext_bin_rmw_8_64<PatFrag kind> :
509 PatFrag<(ops node:$addr, node:$val),
510 (and (i64 (anyext (i32 (kind node:$addr,
511 (i32 (trunc (i64 node:$val))))))), 255)>;
512 class zext_bin_rmw_16_64<PatFrag kind> :
513 PatFrag<(ops node:$addr, node:$val),
514 (and (i64 (anyext (i32 (kind node:$addr,
515 (i32 (trunc (i64 node:$val))))))), 65535)>;
516 class zext_bin_rmw_32_64<PatFrag kind> :
517 PatFrag<(ops node:$addr, node:$val),
518 (zext (i32 (kind node:$addr, (i32 (trunc (i64 node:$val))))))>;
520 // Truncating & sign-extending binary RMW patterns.
521 // These are combined patterns of truncating store patterns and sign-extending
522 // load patterns above. We match subword RMWs (for 32-bit) and anyext RMWs (for
523 // 64-bit) and select a zext RMW; the next instruction will be sext_inreg which
524 // is selected by itself.
525 class sext_bin_rmw_8_32<PatFrag kind> :
526 PatFrag<(ops node:$addr, node:$val), (kind node:$addr, node:$val)>;
527 class sext_bin_rmw_16_32<PatFrag kind> : sext_bin_rmw_8_32<kind>;
528 class sext_bin_rmw_8_64<PatFrag kind> :
529 PatFrag<(ops node:$addr, node:$val),
530 (anyext (i32 (kind node:$addr, (i32 (trunc (i64 node:$val))))))>;
531 class sext_bin_rmw_16_64<PatFrag kind> : sext_bin_rmw_8_64<kind>;
532 // 32->64 sext RMW gets selected as i32.atomic.rmw.***, i64.extend_i32_s
534 // Patterns for various addressing modes for truncating-extending binary RMWs.
535 multiclass BinRMWTruncExtPattern<
536 PatFrag rmw_8, PatFrag rmw_16, PatFrag rmw_32, PatFrag rmw_64,
537 NI inst8_32, NI inst16_32, NI inst8_64, NI inst16_64, NI inst32_64> {
538 // Truncating-extending binary RMWs with no constant offset
539 def : BinRMWPatNoOffset<i32, zext_bin_rmw_8_32<rmw_8>, inst8_32>;
540 def : BinRMWPatNoOffset<i32, zext_bin_rmw_16_32<rmw_16>, inst16_32>;
541 def : BinRMWPatNoOffset<i64, zext_bin_rmw_8_64<rmw_8>, inst8_64>;
542 def : BinRMWPatNoOffset<i64, zext_bin_rmw_16_64<rmw_16>, inst16_64>;
543 def : BinRMWPatNoOffset<i64, zext_bin_rmw_32_64<rmw_32>, inst32_64>;
545 def : BinRMWPatNoOffset<i32, sext_bin_rmw_8_32<rmw_8>, inst8_32>;
546 def : BinRMWPatNoOffset<i32, sext_bin_rmw_16_32<rmw_16>, inst16_32>;
547 def : BinRMWPatNoOffset<i64, sext_bin_rmw_8_64<rmw_8>, inst8_64>;
548 def : BinRMWPatNoOffset<i64, sext_bin_rmw_16_64<rmw_16>, inst16_64>;
550 // Truncating-extending binary RMWs with a constant offset
551 def : BinRMWPatImmOff<i32, zext_bin_rmw_8_32<rmw_8>, regPlusImm, inst8_32>;
552 def : BinRMWPatImmOff<i32, zext_bin_rmw_16_32<rmw_16>, regPlusImm, inst16_32>;
553 def : BinRMWPatImmOff<i64, zext_bin_rmw_8_64<rmw_8>, regPlusImm, inst8_64>;
554 def : BinRMWPatImmOff<i64, zext_bin_rmw_16_64<rmw_16>, regPlusImm, inst16_64>;
555 def : BinRMWPatImmOff<i64, zext_bin_rmw_32_64<rmw_32>, regPlusImm, inst32_64>;
556 def : BinRMWPatImmOff<i32, zext_bin_rmw_8_32<rmw_8>, or_is_add, inst8_32>;
557 def : BinRMWPatImmOff<i32, zext_bin_rmw_16_32<rmw_16>, or_is_add, inst16_32>;
558 def : BinRMWPatImmOff<i64, zext_bin_rmw_8_64<rmw_8>, or_is_add, inst8_64>;
559 def : BinRMWPatImmOff<i64, zext_bin_rmw_16_64<rmw_16>, or_is_add, inst16_64>;
560 def : BinRMWPatImmOff<i64, zext_bin_rmw_32_64<rmw_32>, or_is_add, inst32_64>;
562 def : BinRMWPatImmOff<i32, sext_bin_rmw_8_32<rmw_8>, regPlusImm, inst8_32>;
563 def : BinRMWPatImmOff<i32, sext_bin_rmw_16_32<rmw_16>, regPlusImm, inst16_32>;
564 def : BinRMWPatImmOff<i64, sext_bin_rmw_8_64<rmw_8>, regPlusImm, inst8_64>;
565 def : BinRMWPatImmOff<i64, sext_bin_rmw_16_64<rmw_16>, regPlusImm, inst16_64>;
566 def : BinRMWPatImmOff<i32, sext_bin_rmw_8_32<rmw_8>, or_is_add, inst8_32>;
567 def : BinRMWPatImmOff<i32, sext_bin_rmw_16_32<rmw_16>, or_is_add, inst16_32>;
568 def : BinRMWPatImmOff<i64, sext_bin_rmw_8_64<rmw_8>, or_is_add, inst8_64>;
569 def : BinRMWPatImmOff<i64, sext_bin_rmw_16_64<rmw_16>, or_is_add, inst16_64>;
571 def : BinRMWPatGlobalAddr<i32, zext_bin_rmw_8_32<rmw_8>, inst8_32>;
572 def : BinRMWPatGlobalAddr<i32, zext_bin_rmw_16_32<rmw_16>, inst16_32>;
573 def : BinRMWPatGlobalAddr<i64, zext_bin_rmw_8_64<rmw_8>, inst8_64>;
574 def : BinRMWPatGlobalAddr<i64, zext_bin_rmw_16_64<rmw_16>, inst16_64>;
575 def : BinRMWPatGlobalAddr<i64, zext_bin_rmw_32_64<rmw_32>, inst32_64>;
577 def : BinRMWPatGlobalAddr<i32, sext_bin_rmw_8_32<rmw_8>, inst8_32>;
578 def : BinRMWPatGlobalAddr<i32, sext_bin_rmw_16_32<rmw_16>, inst16_32>;
579 def : BinRMWPatGlobalAddr<i64, sext_bin_rmw_8_64<rmw_8>, inst8_64>;
580 def : BinRMWPatGlobalAddr<i64, sext_bin_rmw_16_64<rmw_16>, inst16_64>;
582 def : BinRMWPatExternalSym<i32, zext_bin_rmw_8_32<rmw_8>, inst8_32>;
583 def : BinRMWPatExternalSym<i32, zext_bin_rmw_16_32<rmw_16>, inst16_32>;
584 def : BinRMWPatExternalSym<i64, zext_bin_rmw_8_64<rmw_8>, inst8_64>;
585 def : BinRMWPatExternalSym<i64, zext_bin_rmw_16_64<rmw_16>, inst16_64>;
586 def : BinRMWPatExternalSym<i64, zext_bin_rmw_32_64<rmw_32>, inst32_64>;
588 def : BinRMWPatExternalSym<i32, sext_bin_rmw_8_32<rmw_8>, inst8_32>;
589 def : BinRMWPatExternalSym<i32, sext_bin_rmw_16_32<rmw_16>, inst16_32>;
590 def : BinRMWPatExternalSym<i64, sext_bin_rmw_8_64<rmw_8>, inst8_64>;
591 def : BinRMWPatExternalSym<i64, sext_bin_rmw_16_64<rmw_16>, inst16_64>;
593 // Truncating-extending binary RMWs with just a constant offset
594 def : BinRMWPatOffsetOnly<i32, zext_bin_rmw_8_32<rmw_8>, inst8_32>;
595 def : BinRMWPatOffsetOnly<i32, zext_bin_rmw_16_32<rmw_16>, inst16_32>;
596 def : BinRMWPatOffsetOnly<i64, zext_bin_rmw_8_64<rmw_8>, inst8_64>;
597 def : BinRMWPatOffsetOnly<i64, zext_bin_rmw_16_64<rmw_16>, inst16_64>;
598 def : BinRMWPatOffsetOnly<i64, zext_bin_rmw_32_64<rmw_32>, inst32_64>;
600 def : BinRMWPatOffsetOnly<i32, sext_bin_rmw_8_32<rmw_8>, inst8_32>;
601 def : BinRMWPatOffsetOnly<i32, sext_bin_rmw_16_32<rmw_16>, inst16_32>;
602 def : BinRMWPatOffsetOnly<i64, sext_bin_rmw_8_64<rmw_8>, inst8_64>;
603 def : BinRMWPatOffsetOnly<i64, sext_bin_rmw_16_64<rmw_16>, inst16_64>;
605 def : BinRMWPatGlobalAddrOffOnly<i32, zext_bin_rmw_8_32<rmw_8>, inst8_32>;
606 def : BinRMWPatGlobalAddrOffOnly<i32, zext_bin_rmw_16_32<rmw_16>, inst16_32>;
607 def : BinRMWPatGlobalAddrOffOnly<i64, zext_bin_rmw_8_64<rmw_8>, inst8_64>;
608 def : BinRMWPatGlobalAddrOffOnly<i64, zext_bin_rmw_16_64<rmw_16>, inst16_64>;
609 def : BinRMWPatGlobalAddrOffOnly<i64, zext_bin_rmw_32_64<rmw_32>, inst32_64>;
611 def : BinRMWPatGlobalAddrOffOnly<i32, sext_bin_rmw_8_32<rmw_8>, inst8_32>;
612 def : BinRMWPatGlobalAddrOffOnly<i32, sext_bin_rmw_16_32<rmw_16>, inst16_32>;
613 def : BinRMWPatGlobalAddrOffOnly<i64, sext_bin_rmw_8_64<rmw_8>, inst8_64>;
614 def : BinRMWPatGlobalAddrOffOnly<i64, sext_bin_rmw_16_64<rmw_16>, inst16_64>;
616 def : BinRMWPatExternSymOffOnly<i32, zext_bin_rmw_8_32<rmw_8>, inst8_32>;
617 def : BinRMWPatExternSymOffOnly<i32, zext_bin_rmw_16_32<rmw_16>, inst16_32>;
618 def : BinRMWPatExternSymOffOnly<i64, zext_bin_rmw_8_64<rmw_8>, inst8_64>;
619 def : BinRMWPatExternSymOffOnly<i64, zext_bin_rmw_16_64<rmw_16>, inst16_64>;
620 def : BinRMWPatExternSymOffOnly<i64, zext_bin_rmw_32_64<rmw_32>, inst32_64>;
622 def : BinRMWPatExternSymOffOnly<i32, sext_bin_rmw_8_32<rmw_8>, inst8_32>;
623 def : BinRMWPatExternSymOffOnly<i32, sext_bin_rmw_16_32<rmw_16>, inst16_32>;
624 def : BinRMWPatExternSymOffOnly<i64, sext_bin_rmw_8_64<rmw_8>, inst8_64>;
625 def : BinRMWPatExternSymOffOnly<i64, sext_bin_rmw_16_64<rmw_16>, inst16_64>;
628 let Predicates = [HasAtomics] in {
629 defm : BinRMWTruncExtPattern<
630 atomic_load_add_8, atomic_load_add_16, atomic_load_add_32, atomic_load_add_64,
631 ATOMIC_RMW8_U_ADD_I32, ATOMIC_RMW16_U_ADD_I32,
632 ATOMIC_RMW8_U_ADD_I64, ATOMIC_RMW16_U_ADD_I64, ATOMIC_RMW32_U_ADD_I64>;
633 defm : BinRMWTruncExtPattern<
634 atomic_load_sub_8, atomic_load_sub_16, atomic_load_sub_32, atomic_load_sub_64,
635 ATOMIC_RMW8_U_SUB_I32, ATOMIC_RMW16_U_SUB_I32,
636 ATOMIC_RMW8_U_SUB_I64, ATOMIC_RMW16_U_SUB_I64, ATOMIC_RMW32_U_SUB_I64>;
637 defm : BinRMWTruncExtPattern<
638 atomic_load_and_8, atomic_load_and_16, atomic_load_and_32, atomic_load_and_64,
639 ATOMIC_RMW8_U_AND_I32, ATOMIC_RMW16_U_AND_I32,
640 ATOMIC_RMW8_U_AND_I64, ATOMIC_RMW16_U_AND_I64, ATOMIC_RMW32_U_AND_I64>;
641 defm : BinRMWTruncExtPattern<
642 atomic_load_or_8, atomic_load_or_16, atomic_load_or_32, atomic_load_or_64,
643 ATOMIC_RMW8_U_OR_I32, ATOMIC_RMW16_U_OR_I32,
644 ATOMIC_RMW8_U_OR_I64, ATOMIC_RMW16_U_OR_I64, ATOMIC_RMW32_U_OR_I64>;
645 defm : BinRMWTruncExtPattern<
646 atomic_load_xor_8, atomic_load_xor_16, atomic_load_xor_32, atomic_load_xor_64,
647 ATOMIC_RMW8_U_XOR_I32, ATOMIC_RMW16_U_XOR_I32,
648 ATOMIC_RMW8_U_XOR_I64, ATOMIC_RMW16_U_XOR_I64, ATOMIC_RMW32_U_XOR_I64>;
649 defm : BinRMWTruncExtPattern<
650 atomic_swap_8, atomic_swap_16, atomic_swap_32, atomic_swap_64,
651 ATOMIC_RMW8_U_XCHG_I32, ATOMIC_RMW16_U_XCHG_I32,
652 ATOMIC_RMW8_U_XCHG_I64, ATOMIC_RMW16_U_XCHG_I64, ATOMIC_RMW32_U_XCHG_I64>;
653 } // Predicates = [HasAtomics]
655 //===----------------------------------------------------------------------===//
656 // Atomic ternary read-modify-writes
657 //===----------------------------------------------------------------------===//
659 // TODO LLVM IR's cmpxchg instruction returns a pair of {loaded value, success
660 // flag}. When we use the success flag or both values, we can't make use of i64
661 // truncate/extend versions of instructions for now, which is suboptimal.
662 // Consider adding a pass after instruction selection that optimizes this case
663 // if it is frequent.
665 multiclass WebAssemblyTerRMW<WebAssemblyRegClass rc, string Name, int Opcode> {
666 defm "" : I<(outs rc:$dst),
667 (ins P2Align:$p2align, offset32_op:$off, I32:$addr, rc:$exp,
669 (outs), (ins P2Align:$p2align, offset32_op:$off), [],
670 !strconcat(Name, "\t$dst, ${off}(${addr})${p2align}, $exp, $new"),
671 !strconcat(Name, "\t${off}, ${p2align}"), Opcode>;
674 defm ATOMIC_RMW_CMPXCHG_I32 :
675 WebAssemblyTerRMW<I32, "i32.atomic.rmw.cmpxchg", 0xfe48>;
676 defm ATOMIC_RMW_CMPXCHG_I64 :
677 WebAssemblyTerRMW<I64, "i64.atomic.rmw.cmpxchg", 0xfe49>;
678 defm ATOMIC_RMW8_U_CMPXCHG_I32 :
679 WebAssemblyTerRMW<I32, "i32.atomic.rmw8.cmpxchg_u", 0xfe4a>;
680 defm ATOMIC_RMW16_U_CMPXCHG_I32 :
681 WebAssemblyTerRMW<I32, "i32.atomic.rmw16.cmpxchg_u", 0xfe4b>;
682 defm ATOMIC_RMW8_U_CMPXCHG_I64 :
683 WebAssemblyTerRMW<I64, "i64.atomic.rmw8.cmpxchg_u", 0xfe4c>;
684 defm ATOMIC_RMW16_U_CMPXCHG_I64 :
685 WebAssemblyTerRMW<I64, "i64.atomic.rmw16.cmpxchg_u", 0xfe4d>;
686 defm ATOMIC_RMW32_U_CMPXCHG_I64 :
687 WebAssemblyTerRMW<I64, "i64.atomic.rmw32.cmpxchg_u", 0xfe4e>;
689 // Select ternary RMWs with no constant offset.
690 class TerRMWPatNoOffset<ValueType ty, PatFrag kind, NI inst> :
691 Pat<(ty (kind I32:$addr, ty:$exp, ty:$new)),
692 (inst 0, 0, I32:$addr, ty:$exp, ty:$new)>;
694 // Select ternary RMWs with a constant offset.
696 // Pattern with address + immediate offset
697 class TerRMWPatImmOff<ValueType ty, PatFrag kind, PatFrag operand, NI inst> :
698 Pat<(ty (kind (operand I32:$addr, imm:$off), ty:$exp, ty:$new)),
699 (inst 0, imm:$off, I32:$addr, ty:$exp, ty:$new)>;
701 class TerRMWPatGlobalAddr<ValueType ty, PatFrag kind, NI inst> :
702 Pat<(ty (kind (regPlusGA I32:$addr, (WebAssemblywrapper tglobaladdr:$off)),
704 (inst 0, tglobaladdr:$off, I32:$addr, ty:$exp, ty:$new)>;
706 class TerRMWPatExternalSym<ValueType ty, PatFrag kind, NI inst> :
707 Pat<(ty (kind (add I32:$addr, (WebAssemblywrapper texternalsym:$off)),
709 (inst 0, texternalsym:$off, I32:$addr, ty:$exp, ty:$new)>;
711 // Select ternary RMWs with just a constant offset.
712 class TerRMWPatOffsetOnly<ValueType ty, PatFrag kind, NI inst> :
713 Pat<(ty (kind imm:$off, ty:$exp, ty:$new)),
714 (inst 0, imm:$off, (CONST_I32 0), ty:$exp, ty:$new)>;
716 class TerRMWPatGlobalAddrOffOnly<ValueType ty, PatFrag kind, NI inst> :
717 Pat<(ty (kind (WebAssemblywrapper tglobaladdr:$off), ty:$exp, ty:$new)),
718 (inst 0, tglobaladdr:$off, (CONST_I32 0), ty:$exp, ty:$new)>;
720 class TerRMWPatExternSymOffOnly<ValueType ty, PatFrag kind, NI inst> :
721 Pat<(ty (kind (WebAssemblywrapper texternalsym:$off), ty:$exp, ty:$new)),
722 (inst 0, texternalsym:$off, (CONST_I32 0), ty:$exp, ty:$new)>;
724 // Patterns for various addressing modes.
725 multiclass TerRMWPattern<PatFrag rmw_32, PatFrag rmw_64, NI inst_32,
727 def : TerRMWPatNoOffset<i32, rmw_32, inst_32>;
728 def : TerRMWPatNoOffset<i64, rmw_64, inst_64>;
730 def : TerRMWPatImmOff<i32, rmw_32, regPlusImm, inst_32>;
731 def : TerRMWPatImmOff<i64, rmw_64, regPlusImm, inst_64>;
732 def : TerRMWPatImmOff<i32, rmw_32, or_is_add, inst_32>;
733 def : TerRMWPatImmOff<i64, rmw_64, or_is_add, inst_64>;
735 def : TerRMWPatGlobalAddr<i32, rmw_32, inst_32>;
736 def : TerRMWPatGlobalAddr<i64, rmw_64, inst_64>;
738 def : TerRMWPatExternalSym<i32, rmw_32, inst_32>;
739 def : TerRMWPatExternalSym<i64, rmw_64, inst_64>;
741 def : TerRMWPatOffsetOnly<i32, rmw_32, inst_32>;
742 def : TerRMWPatOffsetOnly<i64, rmw_64, inst_64>;
744 def : TerRMWPatGlobalAddrOffOnly<i32, rmw_32, inst_32>;
745 def : TerRMWPatGlobalAddrOffOnly<i64, rmw_64, inst_64>;
747 def : TerRMWPatExternSymOffOnly<i32, rmw_32, inst_32>;
748 def : TerRMWPatExternSymOffOnly<i64, rmw_64, inst_64>;
751 let Predicates = [HasAtomics] in
752 defm : TerRMWPattern<atomic_cmp_swap_32, atomic_cmp_swap_64,
753 ATOMIC_RMW_CMPXCHG_I32, ATOMIC_RMW_CMPXCHG_I64>;
755 // Truncating & zero-extending ternary RMW patterns.
756 // DAG legalization & optimization before instruction selection may introduce
757 // additional nodes such as anyext or assertzext depending on operand types.
758 class zext_ter_rmw_8_32<PatFrag kind> :
759 PatFrag<(ops node:$addr, node:$exp, node:$new),
760 (and (i32 (kind node:$addr, node:$exp, node:$new)), 255)>;
761 class zext_ter_rmw_16_32<PatFrag kind> :
762 PatFrag<(ops node:$addr, node:$exp, node:$new),
763 (and (i32 (kind node:$addr, node:$exp, node:$new)), 65535)>;
764 class zext_ter_rmw_8_64<PatFrag kind> :
765 PatFrag<(ops node:$addr, node:$exp, node:$new),
766 (zext (i32 (assertzext (i32 (kind node:$addr,
767 (i32 (trunc (i64 node:$exp))),
768 (i32 (trunc (i64 node:$new))))))))>;
769 class zext_ter_rmw_16_64<PatFrag kind> : zext_ter_rmw_8_64<kind>;
770 class zext_ter_rmw_32_64<PatFrag kind> :
771 PatFrag<(ops node:$addr, node:$exp, node:$new),
772 (zext (i32 (kind node:$addr,
773 (i32 (trunc (i64 node:$exp))),
774 (i32 (trunc (i64 node:$new))))))>;
776 // Truncating & sign-extending ternary RMW patterns.
777 // We match subword RMWs (for 32-bit) and anyext RMWs (for 64-bit) and select a
778 // zext RMW; the next instruction will be sext_inreg which is selected by
780 class sext_ter_rmw_8_32<PatFrag kind> :
781 PatFrag<(ops node:$addr, node:$exp, node:$new),
782 (kind node:$addr, node:$exp, node:$new)>;
783 class sext_ter_rmw_16_32<PatFrag kind> : sext_ter_rmw_8_32<kind>;
784 class sext_ter_rmw_8_64<PatFrag kind> :
785 PatFrag<(ops node:$addr, node:$exp, node:$new),
786 (anyext (i32 (assertzext (i32
788 (i32 (trunc (i64 node:$exp))),
789 (i32 (trunc (i64 node:$new))))))))>;
790 class sext_ter_rmw_16_64<PatFrag kind> : sext_ter_rmw_8_64<kind>;
791 // 32->64 sext RMW gets selected as i32.atomic.rmw.***, i64.extend_i32_s
793 // Patterns for various addressing modes for truncating-extending ternary RMWs.
794 multiclass TerRMWTruncExtPattern<
795 PatFrag rmw_8, PatFrag rmw_16, PatFrag rmw_32, PatFrag rmw_64,
796 NI inst8_32, NI inst16_32, NI inst8_64, NI inst16_64, NI inst32_64> {
797 // Truncating-extending ternary RMWs with no constant offset
798 def : TerRMWPatNoOffset<i32, zext_ter_rmw_8_32<rmw_8>, inst8_32>;
799 def : TerRMWPatNoOffset<i32, zext_ter_rmw_16_32<rmw_16>, inst16_32>;
800 def : TerRMWPatNoOffset<i64, zext_ter_rmw_8_64<rmw_8>, inst8_64>;
801 def : TerRMWPatNoOffset<i64, zext_ter_rmw_16_64<rmw_16>, inst16_64>;
802 def : TerRMWPatNoOffset<i64, zext_ter_rmw_32_64<rmw_32>, inst32_64>;
804 def : TerRMWPatNoOffset<i32, sext_ter_rmw_8_32<rmw_8>, inst8_32>;
805 def : TerRMWPatNoOffset<i32, sext_ter_rmw_16_32<rmw_16>, inst16_32>;
806 def : TerRMWPatNoOffset<i64, sext_ter_rmw_8_64<rmw_8>, inst8_64>;
807 def : TerRMWPatNoOffset<i64, sext_ter_rmw_16_64<rmw_16>, inst16_64>;
809 // Truncating-extending ternary RMWs with a constant offset
810 def : TerRMWPatImmOff<i32, zext_ter_rmw_8_32<rmw_8>, regPlusImm, inst8_32>;
811 def : TerRMWPatImmOff<i32, zext_ter_rmw_16_32<rmw_16>, regPlusImm, inst16_32>;
812 def : TerRMWPatImmOff<i64, zext_ter_rmw_8_64<rmw_8>, regPlusImm, inst8_64>;
813 def : TerRMWPatImmOff<i64, zext_ter_rmw_16_64<rmw_16>, regPlusImm, inst16_64>;
814 def : TerRMWPatImmOff<i64, zext_ter_rmw_32_64<rmw_32>, regPlusImm, inst32_64>;
815 def : TerRMWPatImmOff<i32, zext_ter_rmw_8_32<rmw_8>, or_is_add, inst8_32>;
816 def : TerRMWPatImmOff<i32, zext_ter_rmw_16_32<rmw_16>, or_is_add, inst16_32>;
817 def : TerRMWPatImmOff<i64, zext_ter_rmw_8_64<rmw_8>, or_is_add, inst8_64>;
818 def : TerRMWPatImmOff<i64, zext_ter_rmw_16_64<rmw_16>, or_is_add, inst16_64>;
819 def : TerRMWPatImmOff<i64, zext_ter_rmw_32_64<rmw_32>, or_is_add, inst32_64>;
821 def : TerRMWPatImmOff<i32, sext_ter_rmw_8_32<rmw_8>, regPlusImm, inst8_32>;
822 def : TerRMWPatImmOff<i32, sext_ter_rmw_16_32<rmw_16>, regPlusImm, inst16_32>;
823 def : TerRMWPatImmOff<i64, sext_ter_rmw_8_64<rmw_8>, regPlusImm, inst8_64>;
824 def : TerRMWPatImmOff<i64, sext_ter_rmw_16_64<rmw_16>, regPlusImm, inst16_64>;
825 def : TerRMWPatImmOff<i32, sext_ter_rmw_8_32<rmw_8>, or_is_add, inst8_32>;
826 def : TerRMWPatImmOff<i32, sext_ter_rmw_16_32<rmw_16>, or_is_add, inst16_32>;
827 def : TerRMWPatImmOff<i64, sext_ter_rmw_8_64<rmw_8>, or_is_add, inst8_64>;
828 def : TerRMWPatImmOff<i64, sext_ter_rmw_16_64<rmw_16>, or_is_add, inst16_64>;
830 def : TerRMWPatGlobalAddr<i32, zext_ter_rmw_8_32<rmw_8>, inst8_32>;
831 def : TerRMWPatGlobalAddr<i32, zext_ter_rmw_16_32<rmw_16>, inst16_32>;
832 def : TerRMWPatGlobalAddr<i64, zext_ter_rmw_8_64<rmw_8>, inst8_64>;
833 def : TerRMWPatGlobalAddr<i64, zext_ter_rmw_16_64<rmw_16>, inst16_64>;
834 def : TerRMWPatGlobalAddr<i64, zext_ter_rmw_32_64<rmw_32>, inst32_64>;
836 def : TerRMWPatGlobalAddr<i32, sext_ter_rmw_8_32<rmw_8>, inst8_32>;
837 def : TerRMWPatGlobalAddr<i32, sext_ter_rmw_16_32<rmw_16>, inst16_32>;
838 def : TerRMWPatGlobalAddr<i64, sext_ter_rmw_8_64<rmw_8>, inst8_64>;
839 def : TerRMWPatGlobalAddr<i64, sext_ter_rmw_16_64<rmw_16>, inst16_64>;
841 def : TerRMWPatExternalSym<i32, zext_ter_rmw_8_32<rmw_8>, inst8_32>;
842 def : TerRMWPatExternalSym<i32, zext_ter_rmw_16_32<rmw_16>, inst16_32>;
843 def : TerRMWPatExternalSym<i64, zext_ter_rmw_8_64<rmw_8>, inst8_64>;
844 def : TerRMWPatExternalSym<i64, zext_ter_rmw_16_64<rmw_16>, inst16_64>;
845 def : TerRMWPatExternalSym<i64, zext_ter_rmw_32_64<rmw_32>, inst32_64>;
847 def : TerRMWPatExternalSym<i32, sext_ter_rmw_8_32<rmw_8>, inst8_32>;
848 def : TerRMWPatExternalSym<i32, sext_ter_rmw_16_32<rmw_16>, inst16_32>;
849 def : TerRMWPatExternalSym<i64, sext_ter_rmw_8_64<rmw_8>, inst8_64>;
850 def : TerRMWPatExternalSym<i64, sext_ter_rmw_16_64<rmw_16>, inst16_64>;
852 // Truncating-extending ternary RMWs with just a constant offset
853 def : TerRMWPatOffsetOnly<i32, zext_ter_rmw_8_32<rmw_8>, inst8_32>;
854 def : TerRMWPatOffsetOnly<i32, zext_ter_rmw_16_32<rmw_16>, inst16_32>;
855 def : TerRMWPatOffsetOnly<i64, zext_ter_rmw_8_64<rmw_8>, inst8_64>;
856 def : TerRMWPatOffsetOnly<i64, zext_ter_rmw_16_64<rmw_16>, inst16_64>;
857 def : TerRMWPatOffsetOnly<i64, zext_ter_rmw_32_64<rmw_32>, inst32_64>;
859 def : TerRMWPatOffsetOnly<i32, sext_ter_rmw_8_32<rmw_8>, inst8_32>;
860 def : TerRMWPatOffsetOnly<i32, sext_ter_rmw_16_32<rmw_16>, inst16_32>;
861 def : TerRMWPatOffsetOnly<i64, sext_ter_rmw_8_64<rmw_8>, inst8_64>;
862 def : TerRMWPatOffsetOnly<i64, sext_ter_rmw_16_64<rmw_16>, inst16_64>;
864 def : TerRMWPatGlobalAddrOffOnly<i32, zext_ter_rmw_8_32<rmw_8>, inst8_32>;
865 def : TerRMWPatGlobalAddrOffOnly<i32, zext_ter_rmw_16_32<rmw_16>, inst16_32>;
866 def : TerRMWPatGlobalAddrOffOnly<i64, zext_ter_rmw_8_64<rmw_8>, inst8_64>;
867 def : TerRMWPatGlobalAddrOffOnly<i64, zext_ter_rmw_16_64<rmw_16>, inst16_64>;
868 def : TerRMWPatGlobalAddrOffOnly<i64, zext_ter_rmw_32_64<rmw_32>, inst32_64>;
870 def : TerRMWPatGlobalAddrOffOnly<i32, sext_ter_rmw_8_32<rmw_8>, inst8_32>;
871 def : TerRMWPatGlobalAddrOffOnly<i32, sext_ter_rmw_16_32<rmw_16>, inst16_32>;
872 def : TerRMWPatGlobalAddrOffOnly<i64, sext_ter_rmw_8_64<rmw_8>, inst8_64>;
873 def : TerRMWPatGlobalAddrOffOnly<i64, sext_ter_rmw_16_64<rmw_16>, inst16_64>;
875 def : TerRMWPatExternSymOffOnly<i32, zext_ter_rmw_8_32<rmw_8>, inst8_32>;
876 def : TerRMWPatExternSymOffOnly<i32, zext_ter_rmw_16_32<rmw_16>, inst16_32>;
877 def : TerRMWPatExternSymOffOnly<i64, zext_ter_rmw_8_64<rmw_8>, inst8_64>;
878 def : TerRMWPatExternSymOffOnly<i64, zext_ter_rmw_16_64<rmw_16>, inst16_64>;
879 def : TerRMWPatExternSymOffOnly<i64, zext_ter_rmw_32_64<rmw_32>, inst32_64>;
881 def : TerRMWPatExternSymOffOnly<i32, sext_ter_rmw_8_32<rmw_8>, inst8_32>;
882 def : TerRMWPatExternSymOffOnly<i32, sext_ter_rmw_16_32<rmw_16>, inst16_32>;
883 def : TerRMWPatExternSymOffOnly<i64, sext_ter_rmw_8_64<rmw_8>, inst8_64>;
884 def : TerRMWPatExternSymOffOnly<i64, sext_ter_rmw_16_64<rmw_16>, inst16_64>;
887 let Predicates = [HasAtomics] in
888 defm : TerRMWTruncExtPattern<
889 atomic_cmp_swap_8, atomic_cmp_swap_16, atomic_cmp_swap_32, atomic_cmp_swap_64,
890 ATOMIC_RMW8_U_CMPXCHG_I32, ATOMIC_RMW16_U_CMPXCHG_I32,
891 ATOMIC_RMW8_U_CMPXCHG_I64, ATOMIC_RMW16_U_CMPXCHG_I64,
892 ATOMIC_RMW32_U_CMPXCHG_I64>;
894 //===----------------------------------------------------------------------===//
895 // Atomic wait / notify
896 //===----------------------------------------------------------------------===//
898 let hasSideEffects = 1 in {
901 (ins P2Align:$p2align, offset32_op:$off, I32:$addr, I32:$count),
902 (outs), (ins P2Align:$p2align, offset32_op:$off), [],
903 "atomic.notify \t$dst, ${off}(${addr})${p2align}, $count",
904 "atomic.notify \t${off}, ${p2align}", 0xfe00>;
906 defm ATOMIC_WAIT_I32 :
908 (ins P2Align:$p2align, offset32_op:$off, I32:$addr, I32:$exp, I64:$timeout),
909 (outs), (ins P2Align:$p2align, offset32_op:$off), [],
910 "i32.atomic.wait \t$dst, ${off}(${addr})${p2align}, $exp, $timeout",
911 "i32.atomic.wait \t${off}, ${p2align}", 0xfe01>;
912 defm ATOMIC_WAIT_I64 :
914 (ins P2Align:$p2align, offset32_op:$off, I32:$addr, I64:$exp, I64:$timeout),
915 (outs), (ins P2Align:$p2align, offset32_op:$off), [],
916 "i64.atomic.wait \t$dst, ${off}(${addr})${p2align}, $exp, $timeout",
917 "i64.atomic.wait \t${off}, ${p2align}", 0xfe02>;
919 } // hasSideEffects = 1
921 let Predicates = [HasAtomics] in {
922 // Select notifys with no constant offset.
923 class NotifyPatNoOffset<Intrinsic kind> :
924 Pat<(i32 (kind I32:$addr, I32:$count)),
925 (ATOMIC_NOTIFY 0, 0, I32:$addr, I32:$count)>;
926 def : NotifyPatNoOffset<int_wasm_atomic_notify>;
928 // Select notifys with a constant offset.
930 // Pattern with address + immediate offset
931 class NotifyPatImmOff<Intrinsic kind, PatFrag operand> :
932 Pat<(i32 (kind (operand I32:$addr, imm:$off), I32:$count)),
933 (ATOMIC_NOTIFY 0, imm:$off, I32:$addr, I32:$count)>;
934 def : NotifyPatImmOff<int_wasm_atomic_notify, regPlusImm>;
935 def : NotifyPatImmOff<int_wasm_atomic_notify, or_is_add>;
937 class NotifyPatGlobalAddr<Intrinsic kind> :
938 Pat<(i32 (kind (regPlusGA I32:$addr, (WebAssemblywrapper tglobaladdr:$off)),
940 (ATOMIC_NOTIFY 0, tglobaladdr:$off, I32:$addr, I32:$count)>;
941 def : NotifyPatGlobalAddr<int_wasm_atomic_notify>;
943 class NotifyPatExternalSym<Intrinsic kind> :
944 Pat<(i32 (kind (add I32:$addr, (WebAssemblywrapper texternalsym:$off)),
946 (ATOMIC_NOTIFY 0, texternalsym:$off, I32:$addr, I32:$count)>;
947 def : NotifyPatExternalSym<int_wasm_atomic_notify>;
949 // Select notifys with just a constant offset.
950 class NotifyPatOffsetOnly<Intrinsic kind> :
951 Pat<(i32 (kind imm:$off, I32:$count)),
952 (ATOMIC_NOTIFY 0, imm:$off, (CONST_I32 0), I32:$count)>;
953 def : NotifyPatOffsetOnly<int_wasm_atomic_notify>;
955 class NotifyPatGlobalAddrOffOnly<Intrinsic kind> :
956 Pat<(i32 (kind (WebAssemblywrapper tglobaladdr:$off), I32:$count)),
957 (ATOMIC_NOTIFY 0, tglobaladdr:$off, (CONST_I32 0), I32:$count)>;
958 def : NotifyPatGlobalAddrOffOnly<int_wasm_atomic_notify>;
960 class NotifyPatExternSymOffOnly<Intrinsic kind> :
961 Pat<(i32 (kind (WebAssemblywrapper texternalsym:$off), I32:$count)),
962 (ATOMIC_NOTIFY 0, texternalsym:$off, (CONST_I32 0), I32:$count)>;
963 def : NotifyPatExternSymOffOnly<int_wasm_atomic_notify>;
965 // Select waits with no constant offset.
966 class WaitPatNoOffset<ValueType ty, Intrinsic kind, NI inst> :
967 Pat<(i32 (kind I32:$addr, ty:$exp, I64:$timeout)),
968 (inst 0, 0, I32:$addr, ty:$exp, I64:$timeout)>;
969 def : WaitPatNoOffset<i32, int_wasm_atomic_wait_i32, ATOMIC_WAIT_I32>;
970 def : WaitPatNoOffset<i64, int_wasm_atomic_wait_i64, ATOMIC_WAIT_I64>;
972 // Select waits with a constant offset.
974 // Pattern with address + immediate offset
975 class WaitPatImmOff<ValueType ty, Intrinsic kind, PatFrag operand, NI inst> :
976 Pat<(i32 (kind (operand I32:$addr, imm:$off), ty:$exp, I64:$timeout)),
977 (inst 0, imm:$off, I32:$addr, ty:$exp, I64:$timeout)>;
978 def : WaitPatImmOff<i32, int_wasm_atomic_wait_i32, regPlusImm, ATOMIC_WAIT_I32>;
979 def : WaitPatImmOff<i32, int_wasm_atomic_wait_i32, or_is_add, ATOMIC_WAIT_I32>;
980 def : WaitPatImmOff<i64, int_wasm_atomic_wait_i64, regPlusImm, ATOMIC_WAIT_I64>;
981 def : WaitPatImmOff<i64, int_wasm_atomic_wait_i64, or_is_add, ATOMIC_WAIT_I64>;
983 class WaitPatGlobalAddr<ValueType ty, Intrinsic kind, NI inst> :
984 Pat<(i32 (kind (regPlusGA I32:$addr, (WebAssemblywrapper tglobaladdr:$off)),
985 ty:$exp, I64:$timeout)),
986 (inst 0, tglobaladdr:$off, I32:$addr, ty:$exp, I64:$timeout)>;
987 def : WaitPatGlobalAddr<i32, int_wasm_atomic_wait_i32, ATOMIC_WAIT_I32>;
988 def : WaitPatGlobalAddr<i64, int_wasm_atomic_wait_i64, ATOMIC_WAIT_I64>;
990 class WaitPatExternalSym<ValueType ty, Intrinsic kind, NI inst> :
991 Pat<(i32 (kind (add I32:$addr, (WebAssemblywrapper texternalsym:$off)),
992 ty:$exp, I64:$timeout)),
993 (inst 0, texternalsym:$off, I32:$addr, ty:$exp, I64:$timeout)>;
994 def : WaitPatExternalSym<i32, int_wasm_atomic_wait_i32, ATOMIC_WAIT_I32>;
995 def : WaitPatExternalSym<i64, int_wasm_atomic_wait_i64, ATOMIC_WAIT_I64>;
997 // Select wait_i32, ATOMIC_WAIT_I32s with just a constant offset.
998 class WaitPatOffsetOnly<ValueType ty, Intrinsic kind, NI inst> :
999 Pat<(i32 (kind imm:$off, ty:$exp, I64:$timeout)),
1000 (inst 0, imm:$off, (CONST_I32 0), ty:$exp, I64:$timeout)>;
1001 def : WaitPatOffsetOnly<i32, int_wasm_atomic_wait_i32, ATOMIC_WAIT_I32>;
1002 def : WaitPatOffsetOnly<i64, int_wasm_atomic_wait_i64, ATOMIC_WAIT_I64>;
1004 class WaitPatGlobalAddrOffOnly<ValueType ty, Intrinsic kind, NI inst> :
1005 Pat<(i32 (kind (WebAssemblywrapper tglobaladdr:$off), ty:$exp, I64:$timeout)),
1006 (inst 0, tglobaladdr:$off, (CONST_I32 0), ty:$exp, I64:$timeout)>;
1007 def : WaitPatGlobalAddrOffOnly<i32, int_wasm_atomic_wait_i32, ATOMIC_WAIT_I32>;
1008 def : WaitPatGlobalAddrOffOnly<i64, int_wasm_atomic_wait_i64, ATOMIC_WAIT_I64>;
1010 class WaitPatExternSymOffOnly<ValueType ty, Intrinsic kind, NI inst> :
1011 Pat<(i32 (kind (WebAssemblywrapper texternalsym:$off), ty:$exp,
1013 (inst 0, texternalsym:$off, (CONST_I32 0), ty:$exp, I64:$timeout)>;
1014 def : WaitPatExternSymOffOnly<i32, int_wasm_atomic_wait_i32, ATOMIC_WAIT_I32>;
1015 def : WaitPatExternSymOffOnly<i64, int_wasm_atomic_wait_i64, ATOMIC_WAIT_I64>;
1016 } // Predicates = [HasAtomics]