blob: 5bd09bd57955978209770887421dcb8f6c7b21df [file] [log] [blame]
JF Bastien5ca0bac2015-07-10 18:23:10 +00001// WebAssemblyInstrMemory.td-WebAssembly Memory codegen support -*- tablegen -*-
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief WebAssembly Memory operand code-gen constructs.
12///
13//===----------------------------------------------------------------------===//
14
Dan Gohman9c54d3b2015-11-25 18:13:18 +000015// TODO:
JF Bastien73ff6af2015-08-31 22:24:11 +000016// - HasAddr64
JF Bastien73ff6af2015-08-31 22:24:11 +000017// - WebAssemblyTargetLowering having to do with atomics
Dan Gohman4b9d7912015-12-15 22:01:29 +000018// - Each has optional alignment.
JF Bastien73ff6af2015-08-31 22:24:11 +000019
20// WebAssembly has i8/i16/i32/i64/f32/f64 memory types, but doesn't have i8/i16
21// local types. These memory-only types instead zero- or sign-extend into local
22// types when loading, and truncate when storing.
23
Dan Gohman4b9d7912015-12-15 22:01:29 +000024// WebAssembly constant offsets are performed as unsigned with infinite
25// precision, so we need to check for NoUnsignedWrap so that we don't fold an
26// offset for an add that needs wrapping.
Dan Gohmanf225a632016-01-11 22:05:44 +000027def regPlusImm : PatFrag<(ops node:$addr, node:$off),
Dan Gohman4b9d7912015-12-15 22:01:29 +000028 (add node:$addr, node:$off),
29 [{ return N->getFlags()->hasNoUnsignedWrap(); }]>;
30
Dan Gohman3b09d272016-02-22 20:04:02 +000031// Treat an 'or' node as an 'add' if the or'ed bits are known to be zero.
32def or_is_add : PatFrag<(ops node:$lhs, node:$rhs), (or node:$lhs, node:$rhs),[{
33 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N->getOperand(1)))
34 return CurDAG->MaskedValueIsZero(N->getOperand(0), CN->getAPIntValue());
35
36 APInt KnownZero0, KnownOne0;
37 CurDAG->computeKnownBits(N->getOperand(0), KnownZero0, KnownOne0, 0);
38 APInt KnownZero1, KnownOne1;
39 CurDAG->computeKnownBits(N->getOperand(1), KnownZero1, KnownOne1, 0);
40 return (~KnownZero0 & ~KnownZero1) == 0;
41}]>;
42
Dan Gohmanf225a632016-01-11 22:05:44 +000043// GlobalAddresses are conceptually unsigned values, so we can also fold them
Derek Schuff1b258d32016-08-31 20:27:20 +000044// into immediate values as long as the add is 'nuw'.
45// TODO: We'd like to also match GA offsets but there are cases where the
46// register can have a negative value. Find out what more we can do.
Dan Gohmanf225a632016-01-11 22:05:44 +000047def regPlusGA : PatFrag<(ops node:$addr, node:$off),
48 (add node:$addr, node:$off),
49 [{
Derek Schuff1b258d32016-08-31 20:27:20 +000050 return N->getFlags()->hasNoUnsignedWrap();
Dan Gohmanf225a632016-01-11 22:05:44 +000051}]>;
52
53// We don't need a regPlusES because external symbols never have constant
54// offsets folded into them, so we can just use add.
55
Dan Gohmanfb3e0592015-11-25 19:36:19 +000056let Defs = [ARGUMENTS] in {
57
JF Bastien73ff6af2015-08-31 22:24:11 +000058// Basic load.
Dan Gohmanbb372242016-01-26 03:39:31 +000059def LOAD_I32 : I<(outs I32:$dst), (ins i32imm:$off, I32:$addr,
60 P2Align:$p2align), [],
61 "i32.load\t$dst, ${off}(${addr})${p2align}">;
62def LOAD_I64 : I<(outs I64:$dst), (ins i32imm:$off, I32:$addr,
63 P2Align:$p2align), [],
64 "i64.load\t$dst, ${off}(${addr})${p2align}">;
65def LOAD_F32 : I<(outs F32:$dst), (ins i32imm:$off, I32:$addr,
66 P2Align:$p2align), [],
67 "f32.load\t$dst, ${off}(${addr})${p2align}">;
68def LOAD_F64 : I<(outs F64:$dst), (ins i32imm:$off, I32:$addr,
69 P2Align:$p2align), [],
70 "f64.load\t$dst, ${off}(${addr})${p2align}">;
JF Bastien73ff6af2015-08-31 22:24:11 +000071
Dan Gohman4b9d7912015-12-15 22:01:29 +000072} // Defs = [ARGUMENTS]
73
74// Select loads with no constant offset.
Dan Gohmanbb372242016-01-26 03:39:31 +000075def : Pat<(i32 (load I32:$addr)), (LOAD_I32 0, $addr, 0)>;
76def : Pat<(i64 (load I32:$addr)), (LOAD_I64 0, $addr, 0)>;
77def : Pat<(f32 (load I32:$addr)), (LOAD_F32 0, $addr, 0)>;
78def : Pat<(f64 (load I32:$addr)), (LOAD_F64 0, $addr, 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +000079
80// Select loads with a constant offset.
Dan Gohmanf225a632016-01-11 22:05:44 +000081def : Pat<(i32 (load (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +000082 (LOAD_I32 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +000083def : Pat<(i64 (load (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +000084 (LOAD_I64 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +000085def : Pat<(f32 (load (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +000086 (LOAD_F32 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +000087def : Pat<(f64 (load (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +000088 (LOAD_F64 imm:$off, $addr, 0)>;
Dan Gohman3b09d272016-02-22 20:04:02 +000089def : Pat<(i32 (load (or_is_add I32:$addr, imm:$off))),
90 (LOAD_I32 imm:$off, $addr, 0)>;
91def : Pat<(i64 (load (or_is_add I32:$addr, imm:$off))),
92 (LOAD_I64 imm:$off, $addr, 0)>;
93def : Pat<(f32 (load (or_is_add I32:$addr, imm:$off))),
94 (LOAD_F32 imm:$off, $addr, 0)>;
95def : Pat<(f64 (load (or_is_add I32:$addr, imm:$off))),
96 (LOAD_F64 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +000097def : Pat<(i32 (load (regPlusGA I32:$addr,
98 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +000099 (LOAD_I32 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000100def : Pat<(i64 (load (regPlusGA I32:$addr,
101 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000102 (LOAD_I64 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000103def : Pat<(f32 (load (regPlusGA I32:$addr,
104 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000105 (LOAD_F32 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000106def : Pat<(f64 (load (regPlusGA I32:$addr,
107 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000108 (LOAD_F64 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000109def : Pat<(i32 (load (add I32:$addr, (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000110 (LOAD_I32 texternalsym:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000111def : Pat<(i64 (load (add I32:$addr, (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000112 (LOAD_I64 texternalsym:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000113def : Pat<(f32 (load (add I32:$addr, (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000114 (LOAD_F32 texternalsym:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000115def : Pat<(f64 (load (add I32:$addr, (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000116 (LOAD_F64 texternalsym:$off, $addr, 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000117
118// Select loads with just a constant offset.
Dan Gohmanbb372242016-01-26 03:39:31 +0000119def : Pat<(i32 (load imm:$off)), (LOAD_I32 imm:$off, (CONST_I32 0), 0)>;
120def : Pat<(i64 (load imm:$off)), (LOAD_I64 imm:$off, (CONST_I32 0), 0)>;
121def : Pat<(f32 (load imm:$off)), (LOAD_F32 imm:$off, (CONST_I32 0), 0)>;
122def : Pat<(f64 (load imm:$off)), (LOAD_F64 imm:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000123def : Pat<(i32 (load (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000124 (LOAD_I32 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000125def : Pat<(i64 (load (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000126 (LOAD_I64 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000127def : Pat<(f32 (load (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000128 (LOAD_F32 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000129def : Pat<(f64 (load (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000130 (LOAD_F64 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000131def : Pat<(i32 (load (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000132 (LOAD_I32 texternalsym:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000133def : Pat<(i64 (load (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000134 (LOAD_I64 texternalsym:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000135def : Pat<(f32 (load (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000136 (LOAD_F32 texternalsym:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000137def : Pat<(f64 (load (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000138 (LOAD_F64 texternalsym:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000139
140let Defs = [ARGUMENTS] in {
141
JF Bastien73ff6af2015-08-31 22:24:11 +0000142// Extending load.
Dan Gohmanbb372242016-01-26 03:39:31 +0000143def LOAD8_S_I32 : I<(outs I32:$dst), (ins i32imm:$off, I32:$addr,
144 P2Align:$p2align), [],
145 "i32.load8_s\t$dst, ${off}(${addr})${p2align}">;
146def LOAD8_U_I32 : I<(outs I32:$dst), (ins i32imm:$off, I32:$addr,
147 P2Align:$p2align), [],
148 "i32.load8_u\t$dst, ${off}(${addr})${p2align}">;
149def LOAD16_S_I32 : I<(outs I32:$dst), (ins i32imm:$off, I32:$addr,
150 P2Align:$p2align), [],
151 "i32.load16_s\t$dst, ${off}(${addr})${p2align}">;
152def LOAD16_U_I32 : I<(outs I32:$dst), (ins i32imm:$off, I32:$addr,
153 P2Align:$p2align), [],
154 "i32.load16_u\t$dst, ${off}(${addr})${p2align}">;
155def LOAD8_S_I64 : I<(outs I64:$dst), (ins i32imm:$off, I32:$addr,
156 P2Align:$p2align), [],
157 "i64.load8_s\t$dst, ${off}(${addr})${p2align}">;
158def LOAD8_U_I64 : I<(outs I64:$dst), (ins i32imm:$off, I32:$addr,
159 P2Align:$p2align), [],
160 "i64.load8_u\t$dst, ${off}(${addr})${p2align}">;
161def LOAD16_S_I64 : I<(outs I64:$dst), (ins i32imm:$off, I32:$addr,
162 P2Align:$p2align), [],
163 "i64.load16_s\t$dst, ${off}(${addr})${p2align}">;
164def LOAD16_U_I64 : I<(outs I64:$dst), (ins i32imm:$off, I32:$addr,
165 P2Align:$p2align), [],
166 "i64.load16_u\t$dst, ${off}(${addr})${p2align}">;
167def LOAD32_S_I64 : I<(outs I64:$dst), (ins i32imm:$off, I32:$addr,
168 P2Align:$p2align), [],
169 "i64.load32_s\t$dst, ${off}(${addr})${p2align}">;
170def LOAD32_U_I64 : I<(outs I64:$dst), (ins i32imm:$off, I32:$addr,
171 P2Align:$p2align), [],
172 "i64.load32_u\t$dst, ${off}(${addr})${p2align}">;
JF Bastien73ff6af2015-08-31 22:24:11 +0000173
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000174} // Defs = [ARGUMENTS]
175
Derek Schuff9d779522015-12-05 00:26:39 +0000176// Select extending loads with no constant offset.
Dan Gohmanbb372242016-01-26 03:39:31 +0000177def : Pat<(i32 (sextloadi8 I32:$addr)), (LOAD8_S_I32 0, $addr, 0)>;
178def : Pat<(i32 (zextloadi8 I32:$addr)), (LOAD8_U_I32 0, $addr, 0)>;
179def : Pat<(i32 (sextloadi16 I32:$addr)), (LOAD16_S_I32 0, $addr, 0)>;
180def : Pat<(i32 (zextloadi16 I32:$addr)), (LOAD16_U_I32 0, $addr, 0)>;
181def : Pat<(i64 (sextloadi8 I32:$addr)), (LOAD8_S_I64 0, $addr, 0)>;
182def : Pat<(i64 (zextloadi8 I32:$addr)), (LOAD8_U_I64 0, $addr, 0)>;
183def : Pat<(i64 (sextloadi16 I32:$addr)), (LOAD16_S_I64 0, $addr, 0)>;
184def : Pat<(i64 (zextloadi16 I32:$addr)), (LOAD16_U_I64 0, $addr, 0)>;
185def : Pat<(i64 (sextloadi32 I32:$addr)), (LOAD32_S_I64 0, $addr, 0)>;
186def : Pat<(i64 (zextloadi32 I32:$addr)), (LOAD32_U_I64 0, $addr, 0)>;
Derek Schuff9d779522015-12-05 00:26:39 +0000187
Dan Gohman4b9d7912015-12-15 22:01:29 +0000188// Select extending loads with a constant offset.
Dan Gohmanf225a632016-01-11 22:05:44 +0000189def : Pat<(i32 (sextloadi8 (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000190 (LOAD8_S_I32 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000191def : Pat<(i32 (zextloadi8 (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000192 (LOAD8_U_I32 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000193def : Pat<(i32 (sextloadi16 (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000194 (LOAD16_S_I32 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000195def : Pat<(i32 (zextloadi16 (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000196 (LOAD16_U_I32 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000197def : Pat<(i64 (sextloadi8 (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000198 (LOAD8_S_I64 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000199def : Pat<(i64 (zextloadi8 (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000200 (LOAD8_U_I64 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000201def : Pat<(i64 (sextloadi16 (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000202 (LOAD16_S_I64 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000203def : Pat<(i64 (zextloadi16 (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000204 (LOAD16_U_I64 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000205def : Pat<(i64 (sextloadi32 (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000206 (LOAD32_S_I64 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000207def : Pat<(i64 (zextloadi32 (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000208 (LOAD32_U_I64 imm:$off, $addr, 0)>;
Dan Gohman3b09d272016-02-22 20:04:02 +0000209def : Pat<(i32 (sextloadi8 (or_is_add I32:$addr, imm:$off))),
210 (LOAD8_S_I32 imm:$off, $addr, 0)>;
211def : Pat<(i32 (zextloadi8 (or_is_add I32:$addr, imm:$off))),
212 (LOAD8_U_I32 imm:$off, $addr, 0)>;
213def : Pat<(i32 (sextloadi16 (or_is_add I32:$addr, imm:$off))),
214 (LOAD16_S_I32 imm:$off, $addr, 0)>;
215def : Pat<(i32 (zextloadi16 (or_is_add I32:$addr, imm:$off))),
216 (LOAD16_U_I32 imm:$off, $addr, 0)>;
217def : Pat<(i64 (sextloadi8 (or_is_add I32:$addr, imm:$off))),
218 (LOAD8_S_I64 imm:$off, $addr, 0)>;
219def : Pat<(i64 (zextloadi8 (or_is_add I32:$addr, imm:$off))),
220 (LOAD8_U_I64 imm:$off, $addr, 0)>;
221def : Pat<(i64 (sextloadi16 (or_is_add I32:$addr, imm:$off))),
222 (LOAD16_S_I64 imm:$off, $addr, 0)>;
223def : Pat<(i64 (zextloadi16 (or_is_add I32:$addr, imm:$off))),
224 (LOAD16_U_I64 imm:$off, $addr, 0)>;
225def : Pat<(i64 (sextloadi32 (or_is_add I32:$addr, imm:$off))),
226 (LOAD32_S_I64 imm:$off, $addr, 0)>;
227def : Pat<(i64 (zextloadi32 (or_is_add I32:$addr, imm:$off))),
228 (LOAD32_U_I64 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000229def : Pat<(i32 (sextloadi8 (regPlusGA I32:$addr,
230 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000231 (LOAD8_S_I32 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000232def : Pat<(i32 (zextloadi8 (regPlusGA I32:$addr,
233 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000234 (LOAD8_U_I32 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000235def : Pat<(i32 (sextloadi16 (regPlusGA I32:$addr,
236 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000237 (LOAD16_S_I32 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000238def : Pat<(i32 (zextloadi16 (regPlusGA I32:$addr,
239 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000240 (LOAD16_U_I32 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000241def : Pat<(i64 (sextloadi8 (regPlusGA I32:$addr,
242 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000243 (LOAD8_S_I64 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000244def : Pat<(i64 (zextloadi8 (regPlusGA I32:$addr,
245 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000246 (LOAD8_U_I64 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000247def : Pat<(i64 (sextloadi16 (regPlusGA I32:$addr,
248 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000249 (LOAD16_S_I64 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000250def : Pat<(i64 (zextloadi16 (regPlusGA I32:$addr,
251 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000252 (LOAD16_U_I64 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000253def : Pat<(i64 (sextloadi32 (regPlusGA I32:$addr,
254 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000255 (LOAD32_S_I64 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000256def : Pat<(i64 (zextloadi32 (regPlusGA I32:$addr,
257 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000258 (LOAD32_U_I64 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000259def : Pat<(i32 (sextloadi8 (add I32:$addr,
260 (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000261 (LOAD8_S_I32 texternalsym:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000262def : Pat<(i32 (zextloadi8 (add I32:$addr,
263 (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000264 (LOAD8_U_I32 texternalsym:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000265def : Pat<(i32 (sextloadi16 (add I32:$addr,
266 (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000267 (LOAD16_S_I32 texternalsym:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000268def : Pat<(i32 (zextloadi16 (add I32:$addr,
269 (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000270 (LOAD16_U_I32 texternalsym:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000271def : Pat<(i64 (sextloadi8 (add I32:$addr,
272 (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000273 (LOAD8_S_I64 texternalsym:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000274def : Pat<(i64 (zextloadi8 (add I32:$addr,
275 (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000276 (LOAD8_U_I64 texternalsym:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000277def : Pat<(i64 (sextloadi16 (add I32:$addr,
278 (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000279 (LOAD16_S_I64 texternalsym:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000280def : Pat<(i64 (zextloadi16 (add I32:$addr,
281 (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000282 (LOAD16_U_I64 texternalsym:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000283def : Pat<(i64 (sextloadi32 (add I32:$addr,
284 (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000285 (LOAD32_S_I64 texternalsym:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000286def : Pat<(i64 (zextloadi32 (add I32:$addr,
287 (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000288 (LOAD32_U_I64 texternalsym:$off, $addr, 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000289
290// Select extending loads with just a constant offset.
Dan Gohmanbb372242016-01-26 03:39:31 +0000291def : Pat<(i32 (sextloadi8 imm:$off)),
292 (LOAD8_S_I32 imm:$off, (CONST_I32 0), 0)>;
293def : Pat<(i32 (zextloadi8 imm:$off)),
294 (LOAD8_U_I32 imm:$off, (CONST_I32 0), 0)>;
295def : Pat<(i32 (sextloadi16 imm:$off)),
296 (LOAD16_S_I32 imm:$off, (CONST_I32 0), 0)>;
297def : Pat<(i32 (zextloadi16 imm:$off)),
298 (LOAD16_U_I32 imm:$off, (CONST_I32 0), 0)>;
299def : Pat<(i64 (sextloadi8 imm:$off)),
300 (LOAD8_S_I64 imm:$off, (CONST_I32 0), 0)>;
301def : Pat<(i64 (zextloadi8 imm:$off)),
302 (LOAD8_U_I64 imm:$off, (CONST_I32 0), 0)>;
303def : Pat<(i64 (sextloadi16 imm:$off)),
304 (LOAD16_S_I64 imm:$off, (CONST_I32 0), 0)>;
305def : Pat<(i64 (zextloadi16 imm:$off)),
306 (LOAD16_U_I64 imm:$off, (CONST_I32 0), 0)>;
307def : Pat<(i64 (sextloadi32 imm:$off)),
308 (LOAD32_S_I64 imm:$off, (CONST_I32 0), 0)>;
309def : Pat<(i64 (zextloadi32 imm:$off)),
310 (LOAD32_U_I64 imm:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000311def : Pat<(i32 (sextloadi8 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000312 (LOAD8_S_I32 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000313def : Pat<(i32 (zextloadi8 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000314 (LOAD8_U_I32 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000315def : Pat<(i32 (sextloadi16 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000316 (LOAD16_S_I32 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000317def : Pat<(i32 (zextloadi16 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000318 (LOAD16_U_I32 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000319def : Pat<(i64 (sextloadi8 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000320 (LOAD8_S_I64 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000321def : Pat<(i64 (zextloadi8 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000322 (LOAD8_U_I64 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000323def : Pat<(i64 (sextloadi16 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000324 (LOAD16_S_I64 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000325def : Pat<(i64 (zextloadi16 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000326 (LOAD16_U_I64 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000327def : Pat<(i64 (sextloadi32 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000328 (LOAD32_S_I64 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000329def : Pat<(i64 (zextloadi32 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000330 (LOAD32_U_I64 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000331def : Pat<(i32 (sextloadi8 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000332 (LOAD8_S_I32 texternalsym:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000333def : Pat<(i32 (zextloadi8 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000334 (LOAD8_U_I32 texternalsym:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000335def : Pat<(i32 (sextloadi16 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000336 (LOAD16_S_I32 texternalsym:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000337def : Pat<(i32 (zextloadi16 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000338 (LOAD16_U_I32 texternalsym:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000339def : Pat<(i64 (sextloadi8 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000340 (LOAD8_S_I64 texternalsym:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000341def : Pat<(i64 (zextloadi8 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000342 (LOAD8_U_I64 texternalsym:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000343def : Pat<(i64 (sextloadi16 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000344 (LOAD16_S_I64 texternalsym:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000345def : Pat<(i64 (zextloadi16 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000346 (LOAD16_U_I64 texternalsym:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000347def : Pat<(i64 (sextloadi32 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000348 (LOAD32_S_I64 texternalsym:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000349def : Pat<(i64 (zextloadi32 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000350 (LOAD32_U_I64 texternalsym:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000351
352// Resolve "don't care" extending loads to zero-extending loads. This is
353// somewhat arbitrary, but zero-extending is conceptually simpler.
354
355// Select "don't care" extending loads with no constant offset.
Dan Gohmanbb372242016-01-26 03:39:31 +0000356def : Pat<(i32 (extloadi8 I32:$addr)), (LOAD8_U_I32 0, $addr, 0)>;
357def : Pat<(i32 (extloadi16 I32:$addr)), (LOAD16_U_I32 0, $addr, 0)>;
358def : Pat<(i64 (extloadi8 I32:$addr)), (LOAD8_U_I64 0, $addr, 0)>;
359def : Pat<(i64 (extloadi16 I32:$addr)), (LOAD16_U_I64 0, $addr, 0)>;
360def : Pat<(i64 (extloadi32 I32:$addr)), (LOAD32_U_I64 0, $addr, 0)>;
JF Bastien73ff6af2015-08-31 22:24:11 +0000361
Dan Gohman4b9d7912015-12-15 22:01:29 +0000362// Select "don't care" extending loads with a constant offset.
Dan Gohmanf225a632016-01-11 22:05:44 +0000363def : Pat<(i32 (extloadi8 (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000364 (LOAD8_U_I32 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000365def : Pat<(i32 (extloadi16 (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000366 (LOAD16_U_I32 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000367def : Pat<(i64 (extloadi8 (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000368 (LOAD8_U_I64 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000369def : Pat<(i64 (extloadi16 (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000370 (LOAD16_U_I64 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000371def : Pat<(i64 (extloadi32 (regPlusImm I32:$addr, imm:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000372 (LOAD32_U_I64 imm:$off, $addr, 0)>;
Dan Gohman3b09d272016-02-22 20:04:02 +0000373def : Pat<(i32 (extloadi8 (or_is_add I32:$addr, imm:$off))),
374 (LOAD8_U_I32 imm:$off, $addr, 0)>;
375def : Pat<(i32 (extloadi16 (or_is_add I32:$addr, imm:$off))),
376 (LOAD16_U_I32 imm:$off, $addr, 0)>;
377def : Pat<(i64 (extloadi8 (or_is_add I32:$addr, imm:$off))),
378 (LOAD8_U_I64 imm:$off, $addr, 0)>;
379def : Pat<(i64 (extloadi16 (or_is_add I32:$addr, imm:$off))),
380 (LOAD16_U_I64 imm:$off, $addr, 0)>;
381def : Pat<(i64 (extloadi32 (or_is_add I32:$addr, imm:$off))),
382 (LOAD32_U_I64 imm:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000383def : Pat<(i32 (extloadi8 (regPlusGA I32:$addr,
384 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000385 (LOAD8_U_I32 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000386def : Pat<(i32 (extloadi16 (regPlusGA I32:$addr,
387 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000388 (LOAD16_U_I32 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000389def : Pat<(i64 (extloadi8 (regPlusGA I32:$addr,
390 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000391 (LOAD8_U_I64 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000392def : Pat<(i64 (extloadi16 (regPlusGA I32:$addr,
393 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000394 (LOAD16_U_I64 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000395def : Pat<(i64 (extloadi32 (regPlusGA I32:$addr,
396 (WebAssemblywrapper tglobaladdr:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000397 (LOAD32_U_I64 tglobaladdr:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000398def : Pat<(i32 (extloadi8 (add I32:$addr,
399 (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000400 (LOAD8_U_I32 texternalsym:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000401def : Pat<(i32 (extloadi16 (add I32:$addr,
402 (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000403 (LOAD16_U_I32 texternalsym:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000404def : Pat<(i64 (extloadi8 (add I32:$addr,
405 (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000406 (LOAD8_U_I64 texternalsym:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000407def : Pat<(i64 (extloadi16 (add I32:$addr,
408 (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000409 (LOAD16_U_I64 texternalsym:$off, $addr, 0)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000410def : Pat<(i64 (extloadi32 (add I32:$addr,
411 (WebAssemblywrapper texternalsym:$off)))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000412 (LOAD32_U_I64 texternalsym:$off, $addr, 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000413
414// Select "don't care" extending loads with just a constant offset.
Dan Gohmanbb372242016-01-26 03:39:31 +0000415def : Pat<(i32 (extloadi8 imm:$off)),
416 (LOAD8_U_I32 imm:$off, (CONST_I32 0), 0)>;
417def : Pat<(i32 (extloadi16 imm:$off)),
418 (LOAD16_U_I32 imm:$off, (CONST_I32 0), 0)>;
419def : Pat<(i64 (extloadi8 imm:$off)),
420 (LOAD8_U_I64 imm:$off, (CONST_I32 0), 0)>;
421def : Pat<(i64 (extloadi16 imm:$off)),
422 (LOAD16_U_I64 imm:$off, (CONST_I32 0), 0)>;
423def : Pat<(i64 (extloadi32 imm:$off)),
424 (LOAD32_U_I64 imm:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000425def : Pat<(i32 (extloadi8 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000426 (LOAD8_U_I32 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000427def : Pat<(i32 (extloadi16 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000428 (LOAD16_U_I32 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000429def : Pat<(i64 (extloadi8 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000430 (LOAD8_U_I64 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000431def : Pat<(i64 (extloadi16 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000432 (LOAD16_U_I64 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000433def : Pat<(i64 (extloadi32 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000434 (LOAD32_U_I64 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000435def : Pat<(i32 (extloadi8 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000436 (LOAD8_U_I32 texternalsym:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000437def : Pat<(i32 (extloadi16 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000438 (LOAD16_U_I32 texternalsym:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000439def : Pat<(i64 (extloadi8 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000440 (LOAD8_U_I64 texternalsym:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000441def : Pat<(i64 (extloadi16 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000442 (LOAD16_U_I64 texternalsym:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000443def : Pat<(i64 (extloadi32 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000444 (LOAD32_U_I64 tglobaladdr:$off, (CONST_I32 0), 0)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000445
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000446let Defs = [ARGUMENTS] in {
447
JF Bastien73ff6af2015-08-31 22:24:11 +0000448// Basic store.
Dan Gohman7054ac12015-11-23 21:16:35 +0000449// Note that we split the patterns out of the instruction definitions because
450// WebAssembly's stores return their operand value, and tablegen doesn't like
451// instruction definition patterns that don't reference all of the output
452// operands.
JF Bastien73ff6af2015-08-31 22:24:11 +0000453// Note: WebAssembly inverts SelectionDAG's usual operand order.
Dan Gohmanbb372242016-01-26 03:39:31 +0000454def STORE_I32 : I<(outs I32:$dst), (ins i32imm:$off, I32:$addr,
455 P2Align:$p2align, I32:$val), [],
456 "i32.store\t$dst, ${off}(${addr})${p2align}, $val">;
457def STORE_I64 : I<(outs I64:$dst), (ins i32imm:$off, I32:$addr,
458 P2Align:$p2align, I64:$val), [],
459 "i64.store\t$dst, ${off}(${addr})${p2align}, $val">;
460def STORE_F32 : I<(outs F32:$dst), (ins i32imm:$off, I32:$addr,
461 P2Align:$p2align, F32:$val), [],
462 "f32.store\t$dst, ${off}(${addr})${p2align}, $val">;
463def STORE_F64 : I<(outs F64:$dst), (ins i32imm:$off, I32:$addr,
464 P2Align:$p2align, F64:$val), [],
465 "f64.store\t$dst, ${off}(${addr})${p2align}, $val">;
Dan Gohman7054ac12015-11-23 21:16:35 +0000466
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000467} // Defs = [ARGUMENTS]
468
Dan Gohman4b9d7912015-12-15 22:01:29 +0000469// Select stores with no constant offset.
Dan Gohmanbb372242016-01-26 03:39:31 +0000470def : Pat<(store I32:$val, I32:$addr), (STORE_I32 0, I32:$addr, 0, I32:$val)>;
471def : Pat<(store I64:$val, I32:$addr), (STORE_I64 0, I32:$addr, 0, I64:$val)>;
472def : Pat<(store F32:$val, I32:$addr), (STORE_F32 0, I32:$addr, 0, F32:$val)>;
473def : Pat<(store F64:$val, I32:$addr), (STORE_F64 0, I32:$addr, 0, F64:$val)>;
Derek Schuff9d779522015-12-05 00:26:39 +0000474
Dan Gohman4b9d7912015-12-15 22:01:29 +0000475// Select stores with a constant offset.
Dan Gohmanf225a632016-01-11 22:05:44 +0000476def : Pat<(store I32:$val, (regPlusImm I32:$addr, imm:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000477 (STORE_I32 imm:$off, I32:$addr, 0, I32:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000478def : Pat<(store I64:$val, (regPlusImm I32:$addr, imm:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000479 (STORE_I64 imm:$off, I32:$addr, 0, I64:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000480def : Pat<(store F32:$val, (regPlusImm I32:$addr, imm:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000481 (STORE_F32 imm:$off, I32:$addr, 0, F32:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000482def : Pat<(store F64:$val, (regPlusImm I32:$addr, imm:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000483 (STORE_F64 imm:$off, I32:$addr, 0, F64:$val)>;
Dan Gohman3b09d272016-02-22 20:04:02 +0000484def : Pat<(store I32:$val, (or_is_add I32:$addr, imm:$off)),
485 (STORE_I32 imm:$off, I32:$addr, 0, I32:$val)>;
486def : Pat<(store I64:$val, (or_is_add I32:$addr, imm:$off)),
487 (STORE_I64 imm:$off, I32:$addr, 0, I64:$val)>;
488def : Pat<(store F32:$val, (or_is_add I32:$addr, imm:$off)),
489 (STORE_F32 imm:$off, I32:$addr, 0, F32:$val)>;
490def : Pat<(store F64:$val, (or_is_add I32:$addr, imm:$off)),
491 (STORE_F64 imm:$off, I32:$addr, 0, F64:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000492def : Pat<(store I32:$val, (regPlusGA I32:$addr,
493 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000494 (STORE_I32 tglobaladdr:$off, I32:$addr, 0, I32:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000495def : Pat<(store I64:$val, (regPlusGA I32:$addr,
496 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000497 (STORE_I64 tglobaladdr:$off, I32:$addr, 0, I64:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000498def : Pat<(store F32:$val, (regPlusGA I32:$addr,
499 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000500 (STORE_F32 tglobaladdr:$off, I32:$addr, 0, F32:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000501def : Pat<(store F64:$val, (regPlusGA I32:$addr,
502 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000503 (STORE_F64 tglobaladdr:$off, I32:$addr, 0, F64:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000504def : Pat<(store I32:$val, (add I32:$addr,
505 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000506 (STORE_I32 texternalsym:$off, I32:$addr, 0, I32:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000507def : Pat<(store I64:$val, (add I32:$addr,
508 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000509 (STORE_I64 texternalsym:$off, I32:$addr, 0, I64:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000510def : Pat<(store F32:$val, (add I32:$addr,
511 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000512 (STORE_F32 texternalsym:$off, I32:$addr, 0, F32:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000513def : Pat<(store F64:$val, (add I32:$addr,
514 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000515 (STORE_F64 texternalsym:$off, I32:$addr, 0, F64:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000516
517// Select stores with just a constant offset.
518def : Pat<(store I32:$val, imm:$off),
Dan Gohmanbb372242016-01-26 03:39:31 +0000519 (STORE_I32 imm:$off, (CONST_I32 0), 0, I32:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000520def : Pat<(store I64:$val, imm:$off),
Dan Gohmanbb372242016-01-26 03:39:31 +0000521 (STORE_I64 imm:$off, (CONST_I32 0), 0, I64:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000522def : Pat<(store F32:$val, imm:$off),
Dan Gohmanbb372242016-01-26 03:39:31 +0000523 (STORE_F32 imm:$off, (CONST_I32 0), 0, F32:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000524def : Pat<(store F64:$val, imm:$off),
Dan Gohmanbb372242016-01-26 03:39:31 +0000525 (STORE_F64 imm:$off, (CONST_I32 0), 0, F64:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000526def : Pat<(store I32:$val, (WebAssemblywrapper tglobaladdr:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000527 (STORE_I32 tglobaladdr:$off, (CONST_I32 0), 0, I32:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000528def : Pat<(store I64:$val, (WebAssemblywrapper tglobaladdr:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000529 (STORE_I64 tglobaladdr:$off, (CONST_I32 0), 0, I64:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000530def : Pat<(store F32:$val, (WebAssemblywrapper tglobaladdr:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000531 (STORE_F32 tglobaladdr:$off, (CONST_I32 0), 0, F32:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000532def : Pat<(store F64:$val, (WebAssemblywrapper tglobaladdr:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000533 (STORE_F64 tglobaladdr:$off, (CONST_I32 0), 0, F64:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000534def : Pat<(store I32:$val, (WebAssemblywrapper texternalsym:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000535 (STORE_I32 texternalsym:$off, (CONST_I32 0), 0, I32:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000536def : Pat<(store I64:$val, (WebAssemblywrapper texternalsym:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000537 (STORE_I64 texternalsym:$off, (CONST_I32 0), 0, I64:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000538def : Pat<(store F32:$val, (WebAssemblywrapper texternalsym:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000539 (STORE_F32 texternalsym:$off, (CONST_I32 0), 0, F32:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000540def : Pat<(store F64:$val, (WebAssemblywrapper texternalsym:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000541 (STORE_F64 texternalsym:$off, (CONST_I32 0), 0, F64:$val)>;
JF Bastien73ff6af2015-08-31 22:24:11 +0000542
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000543let Defs = [ARGUMENTS] in {
544
JF Bastien73ff6af2015-08-31 22:24:11 +0000545// Truncating store.
Dan Gohmanbb372242016-01-26 03:39:31 +0000546def STORE8_I32 : I<(outs I32:$dst), (ins i32imm:$off, I32:$addr,
547 P2Align:$p2align, I32:$val), [],
548 "i32.store8\t$dst, ${off}(${addr})${p2align}, $val">;
549def STORE16_I32 : I<(outs I32:$dst), (ins i32imm:$off, I32:$addr,
550 P2Align:$p2align, I32:$val), [],
551 "i32.store16\t$dst, ${off}(${addr})${p2align}, $val">;
552def STORE8_I64 : I<(outs I64:$dst), (ins i32imm:$off, I32:$addr,
553 P2Align:$p2align, I64:$val), [],
554 "i64.store8\t$dst, ${off}(${addr})${p2align}, $val">;
555def STORE16_I64 : I<(outs I64:$dst), (ins i32imm:$off, I32:$addr,
556 P2Align:$p2align, I64:$val), [],
557 "i64.store16\t$dst, ${off}(${addr})${p2align}, $val">;
558def STORE32_I64 : I<(outs I64:$dst), (ins i32imm:$off, I32:$addr,
559 P2Align:$p2align, I64:$val), [],
560 "i64.store32\t$dst, ${off}(${addr})${p2align}, $val">;
Dan Gohman7054ac12015-11-23 21:16:35 +0000561
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000562} // Defs = [ARGUMENTS]
563
Dan Gohman4b9d7912015-12-15 22:01:29 +0000564// Select truncating stores with no constant offset.
Dan Gohman7054ac12015-11-23 21:16:35 +0000565def : Pat<(truncstorei8 I32:$val, I32:$addr),
Dan Gohmanbb372242016-01-26 03:39:31 +0000566 (STORE8_I32 0, I32:$addr, 0, I32:$val)>;
Dan Gohman7054ac12015-11-23 21:16:35 +0000567def : Pat<(truncstorei16 I32:$val, I32:$addr),
Dan Gohmanbb372242016-01-26 03:39:31 +0000568 (STORE16_I32 0, I32:$addr, 0, I32:$val)>;
Dan Gohman7054ac12015-11-23 21:16:35 +0000569def : Pat<(truncstorei8 I64:$val, I32:$addr),
Dan Gohmanbb372242016-01-26 03:39:31 +0000570 (STORE8_I64 0, I32:$addr, 0, I64:$val)>;
Dan Gohman7054ac12015-11-23 21:16:35 +0000571def : Pat<(truncstorei16 I64:$val, I32:$addr),
Dan Gohmanbb372242016-01-26 03:39:31 +0000572 (STORE16_I64 0, I32:$addr, 0, I64:$val)>;
Dan Gohman7054ac12015-11-23 21:16:35 +0000573def : Pat<(truncstorei32 I64:$val, I32:$addr),
Dan Gohmanbb372242016-01-26 03:39:31 +0000574 (STORE32_I64 0, I32:$addr, 0, I64:$val)>;
JF Bastien73ff6af2015-08-31 22:24:11 +0000575
Dan Gohman4b9d7912015-12-15 22:01:29 +0000576// Select truncating stores with a constant offset.
Dan Gohmanf225a632016-01-11 22:05:44 +0000577def : Pat<(truncstorei8 I32:$val, (regPlusImm I32:$addr, imm:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000578 (STORE8_I32 imm:$off, I32:$addr, 0, I32:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000579def : Pat<(truncstorei16 I32:$val, (regPlusImm I32:$addr, imm:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000580 (STORE16_I32 imm:$off, I32:$addr, 0, I32:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000581def : Pat<(truncstorei8 I64:$val, (regPlusImm I32:$addr, imm:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000582 (STORE8_I64 imm:$off, I32:$addr, 0, I64:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000583def : Pat<(truncstorei16 I64:$val, (regPlusImm I32:$addr, imm:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000584 (STORE16_I64 imm:$off, I32:$addr, 0, I64:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000585def : Pat<(truncstorei32 I64:$val, (regPlusImm I32:$addr, imm:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000586 (STORE32_I64 imm:$off, I32:$addr, 0, I64:$val)>;
Dan Gohman3b09d272016-02-22 20:04:02 +0000587def : Pat<(truncstorei8 I32:$val, (or_is_add I32:$addr, imm:$off)),
588 (STORE8_I32 imm:$off, I32:$addr, 0, I32:$val)>;
589def : Pat<(truncstorei16 I32:$val, (or_is_add I32:$addr, imm:$off)),
590 (STORE16_I32 imm:$off, I32:$addr, 0, I32:$val)>;
591def : Pat<(truncstorei8 I64:$val, (or_is_add I32:$addr, imm:$off)),
592 (STORE8_I64 imm:$off, I32:$addr, 0, I64:$val)>;
593def : Pat<(truncstorei16 I64:$val, (or_is_add I32:$addr, imm:$off)),
594 (STORE16_I64 imm:$off, I32:$addr, 0, I64:$val)>;
595def : Pat<(truncstorei32 I64:$val, (or_is_add I32:$addr, imm:$off)),
596 (STORE32_I64 imm:$off, I32:$addr, 0, I64:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000597def : Pat<(truncstorei8 I32:$val,
598 (regPlusGA I32:$addr,
599 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000600 (STORE8_I32 tglobaladdr:$off, I32:$addr, 0, I32:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000601def : Pat<(truncstorei16 I32:$val,
602 (regPlusGA I32:$addr,
603 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000604 (STORE16_I32 tglobaladdr:$off, I32:$addr, 0, I32:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000605def : Pat<(truncstorei8 I64:$val,
606 (regPlusGA I32:$addr,
607 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000608 (STORE8_I64 tglobaladdr:$off, I32:$addr, 0, I64:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000609def : Pat<(truncstorei16 I64:$val,
610 (regPlusGA I32:$addr,
611 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000612 (STORE16_I64 tglobaladdr:$off, I32:$addr, 0, I64:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000613def : Pat<(truncstorei32 I64:$val,
614 (regPlusGA I32:$addr,
615 (WebAssemblywrapper tglobaladdr:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000616 (STORE32_I64 tglobaladdr:$off, I32:$addr, 0, I64:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000617def : Pat<(truncstorei8 I32:$val, (add I32:$addr,
618 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000619 (STORE8_I32 texternalsym:$off, I32:$addr, 0, I32:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000620def : Pat<(truncstorei16 I32:$val,
621 (add I32:$addr,
622 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000623 (STORE16_I32 texternalsym:$off, I32:$addr, 0, I32:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000624def : Pat<(truncstorei8 I64:$val,
625 (add I32:$addr,
626 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000627 (STORE8_I64 texternalsym:$off, I32:$addr, 0, I64:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000628def : Pat<(truncstorei16 I64:$val,
629 (add I32:$addr,
630 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000631 (STORE16_I64 texternalsym:$off, I32:$addr, 0, I64:$val)>;
Dan Gohmanf225a632016-01-11 22:05:44 +0000632def : Pat<(truncstorei32 I64:$val,
633 (add I32:$addr,
634 (WebAssemblywrapper texternalsym:$off))),
Dan Gohmanbb372242016-01-26 03:39:31 +0000635 (STORE32_I64 texternalsym:$off, I32:$addr, 0, I64:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000636
637// Select truncating stores with just a constant offset.
638def : Pat<(truncstorei8 I32:$val, imm:$off),
Dan Gohmanbb372242016-01-26 03:39:31 +0000639 (STORE8_I32 imm:$off, (CONST_I32 0), 0, I32:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000640def : Pat<(truncstorei16 I32:$val, imm:$off),
Dan Gohmanbb372242016-01-26 03:39:31 +0000641 (STORE16_I32 imm:$off, (CONST_I32 0), 0, I32:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000642def : Pat<(truncstorei8 I64:$val, imm:$off),
Dan Gohmanbb372242016-01-26 03:39:31 +0000643 (STORE8_I64 imm:$off, (CONST_I32 0), 0, I64:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000644def : Pat<(truncstorei16 I64:$val, imm:$off),
Dan Gohmanbb372242016-01-26 03:39:31 +0000645 (STORE16_I64 imm:$off, (CONST_I32 0), 0, I64:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000646def : Pat<(truncstorei32 I64:$val, imm:$off),
Dan Gohmanbb372242016-01-26 03:39:31 +0000647 (STORE32_I64 imm:$off, (CONST_I32 0), 0, I64:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000648def : Pat<(truncstorei8 I32:$val, (WebAssemblywrapper tglobaladdr:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000649 (STORE8_I32 tglobaladdr:$off, (CONST_I32 0), 0, I32:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000650def : Pat<(truncstorei16 I32:$val, (WebAssemblywrapper tglobaladdr:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000651 (STORE16_I32 tglobaladdr:$off, (CONST_I32 0), 0, I32:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000652def : Pat<(truncstorei8 I64:$val, (WebAssemblywrapper tglobaladdr:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000653 (STORE8_I64 tglobaladdr:$off, (CONST_I32 0), 0, I64:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000654def : Pat<(truncstorei16 I64:$val, (WebAssemblywrapper tglobaladdr:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000655 (STORE16_I64 tglobaladdr:$off, (CONST_I32 0), 0, I64:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000656def : Pat<(truncstorei32 I64:$val, (WebAssemblywrapper tglobaladdr:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000657 (STORE32_I64 tglobaladdr:$off, (CONST_I32 0), 0, I64:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000658def : Pat<(truncstorei8 I32:$val, (WebAssemblywrapper texternalsym:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000659 (STORE8_I32 texternalsym:$off, (CONST_I32 0), 0, I32:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000660def : Pat<(truncstorei16 I32:$val, (WebAssemblywrapper texternalsym:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000661 (STORE16_I32 texternalsym:$off, (CONST_I32 0), 0, I32:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000662def : Pat<(truncstorei8 I64:$val, (WebAssemblywrapper texternalsym:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000663 (STORE8_I64 texternalsym:$off, (CONST_I32 0), 0, I64:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000664def : Pat<(truncstorei16 I64:$val, (WebAssemblywrapper texternalsym:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000665 (STORE16_I64 texternalsym:$off, (CONST_I32 0), 0, I64:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000666def : Pat<(truncstorei32 I64:$val, (WebAssemblywrapper texternalsym:$off)),
Dan Gohmanbb372242016-01-26 03:39:31 +0000667 (STORE32_I64 texternalsym:$off, (CONST_I32 0), 0, I64:$val)>;
Dan Gohman4b9d7912015-12-15 22:01:29 +0000668
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000669let Defs = [ARGUMENTS] in {
670
Derek Schuff31680dd2016-05-02 17:25:22 +0000671// Current memory size.
672def CURRENT_MEMORY_I32 : I<(outs I32:$dst), (ins),
673 [(set I32:$dst, (int_wasm_current_memory))],
674 "current_memory\t$dst">,
675 Requires<[HasAddr32]>;
676def CURRENT_MEMORY_I64 : I<(outs I64:$dst), (ins),
677 [(set I64:$dst, (int_wasm_current_memory))],
678 "current_memory\t$dst">,
679 Requires<[HasAddr64]>;
Dan Gohmanbaba8c62015-10-02 20:10:26 +0000680
Dan Gohmand7ffb912015-11-05 20:16:59 +0000681// Grow memory.
Dan Gohmanf4333242015-11-13 20:19:11 +0000682def GROW_MEMORY_I32 : I<(outs), (ins I32:$delta),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000683 [(int_wasm_grow_memory I32:$delta)],
Dan Gohman192dddc2015-11-23 22:37:29 +0000684 "grow_memory\t$delta">,
Dan Gohmand7ffb912015-11-05 20:16:59 +0000685 Requires<[HasAddr32]>;
Dan Gohmanf4333242015-11-13 20:19:11 +0000686def GROW_MEMORY_I64 : I<(outs), (ins I64:$delta),
Dan Gohmanaf29bd42015-11-05 20:42:30 +0000687 [(int_wasm_grow_memory I64:$delta)],
Dan Gohman192dddc2015-11-23 22:37:29 +0000688 "grow_memory\t$delta">,
Dan Gohmand7ffb912015-11-05 20:16:59 +0000689 Requires<[HasAddr64]>;
Dan Gohmanfb3e0592015-11-25 19:36:19 +0000690
691} // Defs = [ARGUMENTS]