WebAssemblyInstrConv.td revision 353358
176082Sbmah//===-- WebAssemblyInstrConv.td-WebAssembly Conversion support -*- tablegen -*-=
276082Sbmah//
376082Sbmah// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
476082Sbmah// See https://llvm.org/LICENSE.txt for license information.
576082Sbmah// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
676082Sbmah//
776082Sbmah//===----------------------------------------------------------------------===//
876082Sbmah///
976082Sbmah/// \file
1076082Sbmah/// WebAssembly datatype conversions, truncations, reinterpretations,
1176082Sbmah/// promotions, and demotions operand code-gen constructs.
1276082Sbmah///
1386157Solgeni//===----------------------------------------------------------------------===//
1476082Sbmah
1576082Sbmahdefm I32_WRAP_I64 : I<(outs I32:$dst), (ins I64:$src), (outs), (ins),
1676082Sbmah                      [(set I32:$dst, (trunc I64:$src))],
1776082Sbmah                      "i32.wrap_i64\t$dst, $src", "i32.wrap_i64", 0xa7>;
1876082Sbmah
1976082Sbmahdefm I64_EXTEND_S_I32 : I<(outs I64:$dst), (ins I32:$src), (outs), (ins),
2086157Solgeni                          [(set I64:$dst, (sext I32:$src))],
2176082Sbmah                          "i64.extend_i32_s\t$dst, $src", "i64.extend_i32_s",
2276082Sbmah                          0xac>;
2376560Sbmahdefm I64_EXTEND_U_I32 : I<(outs I64:$dst), (ins I32:$src), (outs), (ins),
2476560Sbmah                          [(set I64:$dst, (zext I32:$src))],
2576560Sbmah                          "i64.extend_i32_u\t$dst, $src", "i64.extend_i32_u",
2676560Sbmah                          0xad>;
2776560Sbmah
2876560Sbmahlet Predicates = [HasSignExt] in {
2976560Sbmahdefm I32_EXTEND8_S_I32 : I<(outs I32:$dst), (ins I32:$src), (outs), (ins),
3076082Sbmah                           [(set I32:$dst, (sext_inreg I32:$src, i8))],
3176082Sbmah                           "i32.extend8_s\t$dst, $src", "i32.extend8_s",
3276082Sbmah                           0xc0>;
3376598Sbmahdefm I32_EXTEND16_S_I32 : I<(outs I32:$dst), (ins I32:$src), (outs), (ins),
3476598Sbmah                            [(set I32:$dst, (sext_inreg I32:$src, i16))],
3576598Sbmah                            "i32.extend16_s\t$dst, $src", "i32.extend16_s",
3676598Sbmah                            0xc1>;
3776082Sbmahdefm I64_EXTEND8_S_I64 : I<(outs I64:$dst), (ins I64:$src), (outs), (ins),
3876082Sbmah                            [(set I64:$dst, (sext_inreg I64:$src, i8))],
3976082Sbmah                            "i64.extend8_s\t$dst, $src", "i64.extend8_s",
4085416Sbmah                            0xc2>;
4176082Sbmahdefm I64_EXTEND16_S_I64 : I<(outs I64:$dst), (ins I64:$src), (outs), (ins),
4276082Sbmah                            [(set I64:$dst, (sext_inreg I64:$src, i16))],
4376082Sbmah                            "i64.extend16_s\t$dst, $src", "i64.extend16_s",
4476560Sbmah                            0xc3>;
4576560Sbmahdefm I64_EXTEND32_S_I64 : I<(outs I64:$dst), (ins I64:$src), (outs), (ins),
4676560Sbmah                            [(set I64:$dst, (sext_inreg I64:$src, i32))],
4776560Sbmah                            "i64.extend32_s\t$dst, $src", "i64.extend32_s",
4876082Sbmah                            0xc4>;
4976082Sbmah} // Predicates = [HasSignExt]
5087808Sbmah
5176082Sbmah// Expand a "don't care" extend into zero-extend (chosen over sign-extend
5276082Sbmah// somewhat arbitrarily, although it favors popular hardware architectures
5376082Sbmah// and is conceptually a simpler operation).
5476082Sbmahdef : Pat<(i64 (anyext I32:$src)), (I64_EXTEND_U_I32 I32:$src)>;
5576082Sbmah
5695526Sbmah// Conversion from floating point to integer instructions which don't trap on
5776082Sbmah// overflow or invalid.
5876082Sbmahdefm I32_TRUNC_S_SAT_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
5995526Sbmah                             [(set I32:$dst, (fp_to_sint F32:$src))],
6095526Sbmah                             "i32.trunc_sat_f32_s\t$dst, $src",
6195526Sbmah                             "i32.trunc_sat_f32_s", 0xfc00>,
6276082Sbmah                             Requires<[HasNontrappingFPToInt]>;
6376082Sbmahdefm I32_TRUNC_U_SAT_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
6476082Sbmah                             [(set I32:$dst, (fp_to_uint F32:$src))],
6576082Sbmah                             "i32.trunc_sat_f32_u\t$dst, $src",
6676082Sbmah                             "i32.trunc_sat_f32_u", 0xfc01>,
6776082Sbmah                             Requires<[HasNontrappingFPToInt]>;
6895526Sbmahdefm I64_TRUNC_S_SAT_F32 : I<(outs I64:$dst), (ins F32:$src), (outs), (ins),
6976082Sbmah                             [(set I64:$dst, (fp_to_sint F32:$src))],
7076082Sbmah                             "i64.trunc_sat_f32_s\t$dst, $src",
7195526Sbmah                             "i64.trunc_sat_f32_s", 0xfc04>,
7276082Sbmah                             Requires<[HasNontrappingFPToInt]>;
7376082Sbmahdefm I64_TRUNC_U_SAT_F32 : I<(outs I64:$dst), (ins F32:$src), (outs), (ins),
7476082Sbmah                             [(set I64:$dst, (fp_to_uint F32:$src))],
7576082Sbmah                             "i64.trunc_sat_f32_u\t$dst, $src",
7676082Sbmah                             "i64.trunc_sat_f32_u", 0xfc05>,
77103657Sbmah                             Requires<[HasNontrappingFPToInt]>;
7876082Sbmahdefm I32_TRUNC_S_SAT_F64 : I<(outs I32:$dst), (ins F64:$src), (outs), (ins),
7976082Sbmah                             [(set I32:$dst, (fp_to_sint F64:$src))],
8095526Sbmah                             "i32.trunc_sat_f64_s\t$dst, $src",
8195526Sbmah                             "i32.trunc_sat_f64_s", 0xfc02>,
8295526Sbmah                             Requires<[HasNontrappingFPToInt]>;
8376082Sbmahdefm I32_TRUNC_U_SAT_F64 : I<(outs I32:$dst), (ins F64:$src), (outs), (ins),
8476082Sbmah                             [(set I32:$dst, (fp_to_uint F64:$src))],
8576082Sbmah                             "i32.trunc_sat_f64_u\t$dst, $src",
86101750Sbmah                             "i32.trunc_sat_f64_u", 0xfc03>,
87101750Sbmah                             Requires<[HasNontrappingFPToInt]>;
88101750Sbmahdefm I64_TRUNC_S_SAT_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
89103657Sbmah                             [(set I64:$dst, (fp_to_sint F64:$src))],
9076082Sbmah                             "i64.trunc_sat_f64_s\t$dst, $src",
9176082Sbmah                             "i64.trunc_sat_f64_s", 0xfc06>,
92103657Sbmah                             Requires<[HasNontrappingFPToInt]>;
9376082Sbmahdefm I64_TRUNC_U_SAT_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
9476082Sbmah                             [(set I64:$dst, (fp_to_uint F64:$src))],
9576082Sbmah                             "i64.trunc_sat_f64_u\t$dst, $src",
9676082Sbmah                             "i64.trunc_sat_f64_u", 0xfc07>,
9776082Sbmah                             Requires<[HasNontrappingFPToInt]>;
9895526Sbmah
9995526Sbmah// Lower llvm.wasm.trunc.saturate.* to saturating instructions
10095526Sbmahdef : Pat<(int_wasm_trunc_saturate_signed F32:$src),
101103657Sbmah          (I32_TRUNC_S_SAT_F32 F32:$src)>;
102103657Sbmahdef : Pat<(int_wasm_trunc_saturate_unsigned F32:$src),
103103657Sbmah          (I32_TRUNC_U_SAT_F32 F32:$src)>;
10487357Sbmahdef : Pat<(int_wasm_trunc_saturate_signed F64:$src),
10587357Sbmah          (I32_TRUNC_S_SAT_F64 F64:$src)>;
10687357Sbmahdef : Pat<(int_wasm_trunc_saturate_unsigned F64:$src),
10796742Sbmah          (I32_TRUNC_U_SAT_F64 F64:$src)>;
10887357Sbmahdef : Pat<(int_wasm_trunc_saturate_signed F32:$src),
10987357Sbmah          (I64_TRUNC_S_SAT_F32 F32:$src)>;
110103657Sbmahdef : Pat<(int_wasm_trunc_saturate_unsigned F32:$src),
11176082Sbmah          (I64_TRUNC_U_SAT_F32 F32:$src)>;
11276082Sbmahdef : Pat<(int_wasm_trunc_saturate_signed F64:$src),
11386055Sbmah          (I64_TRUNC_S_SAT_F64 F64:$src)>;
11476082Sbmahdef : Pat<(int_wasm_trunc_saturate_unsigned F64:$src),
115103657Sbmah          (I64_TRUNC_U_SAT_F64 F64:$src)>;
116103657Sbmah
117103657Sbmah// Conversion from floating point to integer pseudo-instructions which don't
11876082Sbmah// trap on overflow or invalid.
11976082Sbmahlet usesCustomInserter = 1, isCodeGenOnly = 1 in {
12097677Snyandefm FP_TO_SINT_I32_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
12176082Sbmah                            [(set I32:$dst, (fp_to_sint F32:$src))], "", "", 0>,
12297677Snyan                            Requires<[NotHasNontrappingFPToInt]>;
12397677Snyandefm FP_TO_UINT_I32_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
12497677Snyan                            [(set I32:$dst, (fp_to_uint F32:$src))], "", "", 0>,
12597677Snyan                            Requires<[NotHasNontrappingFPToInt]>;
12697677Snyandefm FP_TO_SINT_I64_F32 : I<(outs I64:$dst), (ins F32:$src), (outs), (ins),
12797677Snyan                            [(set I64:$dst, (fp_to_sint F32:$src))], "", "", 0>,
12897677Snyan                            Requires<[NotHasNontrappingFPToInt]>;
12987993Sbmahdefm FP_TO_UINT_I64_F32 : I<(outs I64:$dst), (ins F32:$src), (outs), (ins),
13076082Sbmah                            [(set I64:$dst, (fp_to_uint F32:$src))], "", "", 0>,
13176082Sbmah                            Requires<[NotHasNontrappingFPToInt]>;
13287993Sbmahdefm FP_TO_SINT_I32_F64 : I<(outs I32:$dst), (ins F64:$src), (outs), (ins),
13376560Sbmah                            [(set I32:$dst, (fp_to_sint F64:$src))], "", "", 0>,
13476560Sbmah                            Requires<[NotHasNontrappingFPToInt]>;
13576082Sbmahdefm FP_TO_UINT_I32_F64 : I<(outs I32:$dst), (ins F64:$src), (outs), (ins),
13676082Sbmah                            [(set I32:$dst, (fp_to_uint F64:$src))], "", "", 0>,
13776560Sbmah                            Requires<[NotHasNontrappingFPToInt]>;
13876560Sbmahdefm FP_TO_SINT_I64_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
13976082Sbmah                            [(set I64:$dst, (fp_to_sint F64:$src))], "", "", 0>,
14076082Sbmah                            Requires<[NotHasNontrappingFPToInt]>;
14176082Sbmahdefm FP_TO_UINT_I64_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
14286139Sbmah                            [(set I64:$dst, (fp_to_uint F64:$src))], "", "", 0>,
14376082Sbmah                            Requires<[NotHasNontrappingFPToInt]>;
14486896Sbmah} // usesCustomInserter, isCodeGenOnly = 1
14586896Sbmah
14686896Sbmah// Conversion from floating point to integer traps on overflow and invalid.
14786896Sbmahlet hasSideEffects = 1 in {
14886896Sbmahdefm I32_TRUNC_S_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
14986896Sbmah                         [], "i32.trunc_f32_s\t$dst, $src", "i32.trunc_f32_s",
15086896Sbmah                         0xa8>;
15186896Sbmahdefm I32_TRUNC_U_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
15286896Sbmah                         [], "i32.trunc_f32_u\t$dst, $src", "i32.trunc_f32_u",
15386896Sbmah                         0xa9>;
15486896Sbmahdefm I64_TRUNC_S_F32 : I<(outs I64:$dst), (ins F32:$src), (outs), (ins),
15586896Sbmah                         [], "i64.trunc_f32_s\t$dst, $src", "i64.trunc_f32_s",
15686896Sbmah                         0xae>;
15776560Sbmahdefm I64_TRUNC_U_F32 : I<(outs I64:$dst), (ins F32:$src), (outs), (ins),
15876560Sbmah                         [], "i64.trunc_f32_u\t$dst, $src", "i64.trunc_f32_u",
15976082Sbmah                         0xaf>;
16086896Sbmahdefm I32_TRUNC_S_F64 : I<(outs I32:$dst), (ins F64:$src), (outs), (ins),
16176560Sbmah                         [], "i32.trunc_f64_s\t$dst, $src", "i32.trunc_f64_s",
16276560Sbmah                         0xaa>;
16376560Sbmahdefm I32_TRUNC_U_F64 : I<(outs I32:$dst), (ins F64:$src), (outs), (ins),
16476082Sbmah                         [], "i32.trunc_f64_u\t$dst, $src", "i32.trunc_f64_u",
16576082Sbmah                         0xab>;
16676082Sbmahdefm I64_TRUNC_S_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
16776082Sbmah                         [], "i64.trunc_f64_s\t$dst, $src", "i64.trunc_f64_s",
16876082Sbmah                         0xb0>;
16976082Sbmahdefm I64_TRUNC_U_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
17076560Sbmah                         [], "i64.trunc_f64_u\t$dst, $src", "i64.trunc_f64_u",
17176560Sbmah                         0xb1>;
17276082Sbmah} // hasSideEffects = 1
17376082Sbmah
17476082Sbmahdefm F32_CONVERT_S_I32 : I<(outs F32:$dst), (ins I32:$src), (outs), (ins),
17576560Sbmah                           [(set F32:$dst, (sint_to_fp I32:$src))],
17676560Sbmah                           "f32.convert_i32_s\t$dst, $src", "f32.convert_i32_s",
17776082Sbmah                           0xb2>;
17897677Snyandefm F32_CONVERT_U_I32 : I<(outs F32:$dst), (ins I32:$src), (outs), (ins),
17997677Snyan                           [(set F32:$dst, (uint_to_fp I32:$src))],
18097677Snyan                           "f32.convert_i32_u\t$dst, $src", "f32.convert_i32_u",
18197677Snyan                           0xb3>;
18297677Snyandefm F64_CONVERT_S_I32 : I<(outs F64:$dst), (ins I32:$src), (outs), (ins),
18397677Snyan                           [(set F64:$dst, (sint_to_fp I32:$src))],
18497677Snyan                           "f64.convert_i32_s\t$dst, $src", "f64.convert_i32_s",
18597677Snyan                           0xb7>;
18697677Snyandefm F64_CONVERT_U_I32 : I<(outs F64:$dst), (ins I32:$src), (outs), (ins),
18776082Sbmah                           [(set F64:$dst, (uint_to_fp I32:$src))],
18876082Sbmah                           "f64.convert_i32_u\t$dst, $src", "f64.convert_i32_u",
18976082Sbmah                           0xb8>;
190102813Sbmahdefm F32_CONVERT_S_I64 : I<(outs F32:$dst), (ins I64:$src), (outs), (ins),
191102813Sbmah                           [(set F32:$dst, (sint_to_fp I64:$src))],
192102444Sbmah                           "f32.convert_i64_s\t$dst, $src", "f32.convert_i64_s",
193102444Sbmah                           0xb4>;
194102813Sbmahdefm F32_CONVERT_U_I64 : I<(outs F32:$dst), (ins I64:$src), (outs), (ins),
195102444Sbmah                           [(set F32:$dst, (uint_to_fp I64:$src))],
196102444Sbmah                           "f32.convert_i64_u\t$dst, $src", "f32.convert_i64_u",
197102444Sbmah                           0xb5>;
198102444Sbmahdefm F64_CONVERT_S_I64 : I<(outs F64:$dst), (ins I64:$src), (outs), (ins),
199102444Sbmah                           [(set F64:$dst, (sint_to_fp I64:$src))],
200102444Sbmah                           "f64.convert_i64_s\t$dst, $src", "f64.convert_i64_s",
201102444Sbmah                           0xb9>;
20282597Sscottldefm F64_CONVERT_U_I64 : I<(outs F64:$dst), (ins I64:$src), (outs), (ins),
20376082Sbmah                           [(set F64:$dst, (uint_to_fp I64:$src))],
20476082Sbmah                           "f64.convert_i64_u\t$dst, $src", "f64.convert_i64_u",
20582597Sscottl                           0xba>;
20682597Sscottl
20782597Sscottldefm F64_PROMOTE_F32 : I<(outs F64:$dst), (ins F32:$src), (outs), (ins),
20876396Sscottl                         [(set F64:$dst, (fpextend F32:$src))],
20976396Sscottl                         "f64.promote_f32\t$dst, $src", "f64.promote_f32",
21076396Sscottl                         0xbb>;
21176082Sbmahdefm F32_DEMOTE_F64 : I<(outs F32:$dst), (ins F64:$src), (outs), (ins),
21276082Sbmah                        [(set F32:$dst, (fpround F64:$src))],
21376082Sbmah                        "f32.demote_f64\t$dst, $src", "f32.demote_f64",
21476082Sbmah                        0xb6>;
21576082Sbmah
21676082Sbmahdefm I32_REINTERPRET_F32 : I<(outs I32:$dst), (ins F32:$src), (outs), (ins),
21776082Sbmah                             [(set I32:$dst, (bitconvert F32:$src))],
21876082Sbmah                             "i32.reinterpret_f32\t$dst, $src",
21976082Sbmah                             "i32.reinterpret_f32", 0xbc>;
22082597Sscottldefm F32_REINTERPRET_I32 : I<(outs F32:$dst), (ins I32:$src), (outs), (ins),
22176082Sbmah                             [(set F32:$dst, (bitconvert I32:$src))],
22276082Sbmah                             "f32.reinterpret_i32\t$dst, $src",
22376082Sbmah                             "f32.reinterpret_i32", 0xbe>;
22476082Sbmahdefm I64_REINTERPRET_F64 : I<(outs I64:$dst), (ins F64:$src), (outs), (ins),
22576082Sbmah                             [(set I64:$dst, (bitconvert F64:$src))],
22676082Sbmah                             "i64.reinterpret_f64\t$dst, $src",
22776082Sbmah                             "i64.reinterpret_f64", 0xbd>;
22876082Sbmahdefm F64_REINTERPRET_I64 : I<(outs F64:$dst), (ins I64:$src), (outs), (ins),
22976082Sbmah                             [(set F64:$dst, (bitconvert I64:$src))],
23076082Sbmah                             "f64.reinterpret_i64\t$dst, $src",
23176082Sbmah                             "f64.reinterpret_i64", 0xbf>;
23276082Sbmah