WebAssemblyInstrConv.td revision 344779
1//===-- WebAssemblyInstrConv.td-WebAssembly Conversion 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/// WebAssembly datatype conversions, truncations, reinterpretations,
12/// promotions, and demotions operand code-gen constructs.
13///
14//===----------------------------------------------------------------------===//
15
16defm I32_WRAP_I64 : I<(outs I32:$dst), (ins I64:$src), (outs), (ins),
17                      [(set I32:$dst, (trunc I64:$src))],
18                      "i32.wrap_i64\t$dst, $src", "i32.wrap_i64", 0xa7>;
19
20defm I64_EXTEND_S_I32 : I<(outs I64:$dst), (ins I32:$src), (outs), (ins),
21                          [(set I64:$dst, (sext I32:$src))],
22                          "i64.extend_i32_s\t$dst, $src", "i64.extend_i32_s",
23                          0xac>;
24defm I64_EXTEND_U_I32 : I<(outs I64:$dst), (ins I32:$src), (outs), (ins),
25                          [(set I64:$dst, (zext I32:$src))],
26                          "i64.extend_i32_u\t$dst, $src", "i64.extend_i32_u",
27                          0xad>;
28
29let Predicates = [HasSignExt] in {
30defm I32_EXTEND8_S_I32 : I<(outs I32:$dst), (ins I32:$src), (outs), (ins),
31                           [(set I32:$dst, (sext_inreg I32:$src, i8))],
32                           "i32.extend8_s\t$dst, $src", "i32.extend8_s",
33                           0xc0>;
34defm I32_EXTEND16_S_I32 : I<(outs I32:$dst), (ins I32:$src), (outs), (ins),
35                            [(set I32:$dst, (sext_inreg I32:$src, i16))],
36                            "i32.extend16_s\t$dst, $src", "i32.extend16_s",
37                            0xc1>;
38defm I64_EXTEND8_S_I64 : I<(outs I64:$dst), (ins I64:$src), (outs), (ins),
39                            [(set I64:$dst, (sext_inreg I64:$src, i8))],
40                            "i64.extend8_s\t$dst, $src", "i64.extend8_s",
41                            0xc2>;
42defm I64_EXTEND16_S_I64 : I<(outs I64:$dst), (ins I64:$src), (outs), (ins),
43                            [(set I64:$dst, (sext_inreg I64:$src, i16))],
44                            "i64.extend16_s\t$dst, $src", "i64.extend16_s",
45                            0xc3>;
46defm I64_EXTEND32_S_I64 : I<(outs I64:$dst), (ins I64:$src), (outs), (ins),
47                            [(set I64:$dst, (sext_inreg I64:$src, i32))],
48                            "i64.extend32_s\t$dst, $src", "i64.extend32_s",
49                            0xc4>;
50} // Predicates = [HasSignExt]
51
52// Expand a "don't care" extend into zero-extend (chosen over sign-extend
53// somewhat arbitrarily, although it favors popular hardware architectures
54// and is conceptually a simpler operation).
55def : Pat<(i64 (anyext I32:$src)), (I64_EXTEND_U_I32 I32:$src)>;
56
57// Conversion from floating point to integer instructions which don't trap on
58// overflow or invalid.
59defm I32_TRUNC_S_SAT_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
60                             [(set I32:$dst, (fp_to_sint F32:$src))],
61                             "i32.trunc_sat_f32_s\t$dst, $src",
62                             "i32.trunc_sat_f32_s", 0xfc00>,
63                             Requires<[HasNontrappingFPToInt]>;
64defm I32_TRUNC_U_SAT_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
65                             [(set I32:$dst, (fp_to_uint F32:$src))],
66                             "i32.trunc_sat_f32_u\t$dst, $src",
67                             "i32.trunc_sat_f32_u", 0xfc01>,
68                             Requires<[HasNontrappingFPToInt]>;
69defm I64_TRUNC_S_SAT_F32 : I<(outs I64:$dst), (ins F32:$src), (outs), (ins),
70                             [(set I64:$dst, (fp_to_sint F32:$src))],
71                             "i64.trunc_sat_f32_s\t$dst, $src",
72                             "i64.trunc_sat_f32_s", 0xfc04>,
73                             Requires<[HasNontrappingFPToInt]>;
74defm I64_TRUNC_U_SAT_F32 : I<(outs I64:$dst), (ins F32:$src), (outs), (ins),
75                             [(set I64:$dst, (fp_to_uint F32:$src))],
76                             "i64.trunc_sat_f32_u\t$dst, $src",
77                             "i64.trunc_sat_f32_u", 0xfc05>,
78                             Requires<[HasNontrappingFPToInt]>;
79defm I32_TRUNC_S_SAT_F64 : I<(outs I32:$dst), (ins F64:$src), (outs), (ins),
80                             [(set I32:$dst, (fp_to_sint F64:$src))],
81                             "i32.trunc_sat_f64_s\t$dst, $src",
82                             "i32.trunc_sat_f64_s", 0xfc02>,
83                             Requires<[HasNontrappingFPToInt]>;
84defm I32_TRUNC_U_SAT_F64 : I<(outs I32:$dst), (ins F64:$src), (outs), (ins),
85                             [(set I32:$dst, (fp_to_uint F64:$src))],
86                             "i32.trunc_sat_f64_u\t$dst, $src",
87                             "i32.trunc_sat_f64_u", 0xfc03>,
88                             Requires<[HasNontrappingFPToInt]>;
89defm I64_TRUNC_S_SAT_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
90                             [(set I64:$dst, (fp_to_sint F64:$src))],
91                             "i64.trunc_sat_f64_s\t$dst, $src",
92                             "i64.trunc_sat_f64_s", 0xfc06>,
93                             Requires<[HasNontrappingFPToInt]>;
94defm I64_TRUNC_U_SAT_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
95                             [(set I64:$dst, (fp_to_uint F64:$src))],
96                             "i64.trunc_sat_f64_u\t$dst, $src",
97                             "i64.trunc_sat_f64_u", 0xfc07>,
98                             Requires<[HasNontrappingFPToInt]>;
99
100// Lower llvm.wasm.trunc.saturate.* to saturating instructions
101def : Pat<(int_wasm_trunc_saturate_signed F32:$src),
102          (I32_TRUNC_S_SAT_F32 F32:$src)>;
103def : Pat<(int_wasm_trunc_saturate_unsigned F32:$src),
104          (I32_TRUNC_U_SAT_F32 F32:$src)>;
105def : Pat<(int_wasm_trunc_saturate_signed F64:$src),
106          (I32_TRUNC_S_SAT_F64 F64:$src)>;
107def : Pat<(int_wasm_trunc_saturate_unsigned F64:$src),
108          (I32_TRUNC_U_SAT_F64 F64:$src)>;
109def : Pat<(int_wasm_trunc_saturate_signed F32:$src),
110          (I64_TRUNC_S_SAT_F32 F32:$src)>;
111def : Pat<(int_wasm_trunc_saturate_unsigned F32:$src),
112          (I64_TRUNC_U_SAT_F32 F32:$src)>;
113def : Pat<(int_wasm_trunc_saturate_signed F64:$src),
114          (I64_TRUNC_S_SAT_F64 F64:$src)>;
115def : Pat<(int_wasm_trunc_saturate_unsigned F64:$src),
116          (I64_TRUNC_U_SAT_F64 F64:$src)>;
117
118// Conversion from floating point to integer pseudo-instructions which don't
119// trap on overflow or invalid.
120let usesCustomInserter = 1, isCodeGenOnly = 1 in {
121defm FP_TO_SINT_I32_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
122                            [(set I32:$dst, (fp_to_sint F32:$src))], "", "", 0>,
123                            Requires<[NotHasNontrappingFPToInt]>;
124defm FP_TO_UINT_I32_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
125                            [(set I32:$dst, (fp_to_uint F32:$src))], "", "", 0>,
126                            Requires<[NotHasNontrappingFPToInt]>;
127defm FP_TO_SINT_I64_F32 : I<(outs I64:$dst), (ins F32:$src), (outs), (ins),
128                            [(set I64:$dst, (fp_to_sint F32:$src))], "", "", 0>,
129                            Requires<[NotHasNontrappingFPToInt]>;
130defm FP_TO_UINT_I64_F32 : I<(outs I64:$dst), (ins F32:$src), (outs), (ins),
131                            [(set I64:$dst, (fp_to_uint F32:$src))], "", "", 0>,
132                            Requires<[NotHasNontrappingFPToInt]>;
133defm FP_TO_SINT_I32_F64 : I<(outs I32:$dst), (ins F64:$src), (outs), (ins),
134                            [(set I32:$dst, (fp_to_sint F64:$src))], "", "", 0>,
135                            Requires<[NotHasNontrappingFPToInt]>;
136defm FP_TO_UINT_I32_F64 : I<(outs I32:$dst), (ins F64:$src), (outs), (ins),
137                            [(set I32:$dst, (fp_to_uint F64:$src))], "", "", 0>,
138                            Requires<[NotHasNontrappingFPToInt]>;
139defm FP_TO_SINT_I64_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
140                            [(set I64:$dst, (fp_to_sint F64:$src))], "", "", 0>,
141                            Requires<[NotHasNontrappingFPToInt]>;
142defm FP_TO_UINT_I64_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
143                            [(set I64:$dst, (fp_to_uint F64:$src))], "", "", 0>,
144                            Requires<[NotHasNontrappingFPToInt]>;
145} // usesCustomInserter, isCodeGenOnly = 1
146
147// Conversion from floating point to integer traps on overflow and invalid.
148let hasSideEffects = 1 in {
149defm I32_TRUNC_S_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
150                         [], "i32.trunc_f32_s\t$dst, $src", "i32.trunc_f32_s",
151                         0xa8>;
152defm I32_TRUNC_U_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
153                         [], "i32.trunc_f32_u\t$dst, $src", "i32.trunc_f32_u",
154                         0xa9>;
155defm I64_TRUNC_S_F32 : I<(outs I64:$dst), (ins F32:$src), (outs), (ins),
156                         [], "i64.trunc_f32_s\t$dst, $src", "i64.trunc_f32_s",
157                         0xae>;
158defm I64_TRUNC_U_F32 : I<(outs I64:$dst), (ins F32:$src), (outs), (ins),
159                         [], "i64.trunc_f32_u\t$dst, $src", "i64.trunc_f32_u",
160                         0xaf>;
161defm I32_TRUNC_S_F64 : I<(outs I32:$dst), (ins F64:$src), (outs), (ins),
162                         [], "i32.trunc_f64_s\t$dst, $src", "i32.trunc_f64_s",
163                         0xaa>;
164defm I32_TRUNC_U_F64 : I<(outs I32:$dst), (ins F64:$src), (outs), (ins),
165                         [], "i32.trunc_f64_u\t$dst, $src", "i32.trunc_f64_u",
166                         0xab>;
167defm I64_TRUNC_S_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
168                         [], "i64.trunc_f64_s\t$dst, $src", "i64.trunc_f64_s",
169                         0xb0>;
170defm I64_TRUNC_U_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
171                         [], "i64.trunc_f64_u\t$dst, $src", "i64.trunc_f64_u",
172                         0xb1>;
173} // hasSideEffects = 1
174
175defm F32_CONVERT_S_I32 : I<(outs F32:$dst), (ins I32:$src), (outs), (ins),
176                           [(set F32:$dst, (sint_to_fp I32:$src))],
177                           "f32.convert_i32_s\t$dst, $src", "f32.convert_i32_s",
178                           0xb2>;
179defm F32_CONVERT_U_I32 : I<(outs F32:$dst), (ins I32:$src), (outs), (ins),
180                           [(set F32:$dst, (uint_to_fp I32:$src))],
181                           "f32.convert_i32_u\t$dst, $src", "f32.convert_i32_u",
182                           0xb3>;
183defm F64_CONVERT_S_I32 : I<(outs F64:$dst), (ins I32:$src), (outs), (ins),
184                           [(set F64:$dst, (sint_to_fp I32:$src))],
185                           "f64.convert_i32_s\t$dst, $src", "f64.convert_i32_s",
186                           0xb7>;
187defm F64_CONVERT_U_I32 : I<(outs F64:$dst), (ins I32:$src), (outs), (ins),
188                           [(set F64:$dst, (uint_to_fp I32:$src))],
189                           "f64.convert_i32_u\t$dst, $src", "f64.convert_i32_u",
190                           0xb8>;
191defm F32_CONVERT_S_I64 : I<(outs F32:$dst), (ins I64:$src), (outs), (ins),
192                           [(set F32:$dst, (sint_to_fp I64:$src))],
193                           "f32.convert_i64_s\t$dst, $src", "f32.convert_i64_s",
194                           0xb4>;
195defm F32_CONVERT_U_I64 : I<(outs F32:$dst), (ins I64:$src), (outs), (ins),
196                           [(set F32:$dst, (uint_to_fp I64:$src))],
197                           "f32.convert_i64_u\t$dst, $src", "f32.convert_i64_u",
198                           0xb5>;
199defm F64_CONVERT_S_I64 : I<(outs F64:$dst), (ins I64:$src), (outs), (ins),
200                           [(set F64:$dst, (sint_to_fp I64:$src))],
201                           "f64.convert_i64_s\t$dst, $src", "f64.convert_i64_s",
202                           0xb9>;
203defm F64_CONVERT_U_I64 : I<(outs F64:$dst), (ins I64:$src), (outs), (ins),
204                           [(set F64:$dst, (uint_to_fp I64:$src))],
205                           "f64.convert_i64_u\t$dst, $src", "f64.convert_i64_u",
206                           0xba>;
207
208defm F64_PROMOTE_F32 : I<(outs F64:$dst), (ins F32:$src), (outs), (ins),
209                         [(set F64:$dst, (fpextend F32:$src))],
210                         "f64.promote_f32\t$dst, $src", "f64.promote_f32",
211                         0xbb>;
212defm F32_DEMOTE_F64 : I<(outs F32:$dst), (ins F64:$src), (outs), (ins),
213                        [(set F32:$dst, (fpround F64:$src))],
214                        "f32.demote_f64\t$dst, $src", "f32.demote_f64",
215                        0xb6>;
216
217defm I32_REINTERPRET_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
218                             [(set I32:$dst, (bitconvert F32:$src))],
219                             "i32.reinterpret_f32\t$dst, $src",
220                             "i32.reinterpret_f32", 0xbc>;
221defm F32_REINTERPRET_I32 : I<(outs F32:$dst), (ins I32:$src), (outs), (ins),
222                             [(set F32:$dst, (bitconvert I32:$src))],
223                             "f32.reinterpret_i32\t$dst, $src",
224                             "f32.reinterpret_i32", 0xbe>;
225defm I64_REINTERPRET_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
226                             [(set I64:$dst, (bitconvert F64:$src))],
227                             "i64.reinterpret_f64\t$dst, $src",
228                             "i64.reinterpret_f64", 0xbd>;
229defm F64_REINTERPRET_I64 : I<(outs F64:$dst), (ins I64:$src), (outs), (ins),
230                             [(set F64:$dst, (bitconvert I64:$src))],
231                             "f64.reinterpret_i64\t$dst, $src",
232                             "f64.reinterpret_i64", 0xbf>;
233