xref: /aosp_15_r20/external/llvm/lib/Target/WebAssembly/WebAssemblyInstrInteger.td (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker// WebAssemblyInstrInteger.td-WebAssembly Integer codegen -------*- tablegen -*-
2*9880d681SAndroid Build Coastguard Worker//
3*9880d681SAndroid Build Coastguard Worker//                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker//
5*9880d681SAndroid Build Coastguard Worker// This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker// License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker//
8*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker///
10*9880d681SAndroid Build Coastguard Worker/// \file
11*9880d681SAndroid Build Coastguard Worker/// \brief WebAssembly Integer operand code-gen constructs.
12*9880d681SAndroid Build Coastguard Worker///
13*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard Workerlet Defs = [ARGUMENTS] in {
16*9880d681SAndroid Build Coastguard Worker
17*9880d681SAndroid Build Coastguard Worker// The spaces after the names are for aesthetic purposes only, to make
18*9880d681SAndroid Build Coastguard Worker// operands line up vertically after tab expansion.
19*9880d681SAndroid Build Coastguard Workerlet isCommutable = 1 in
20*9880d681SAndroid Build Coastguard Workerdefm ADD : BinaryInt<add, "add ">;
21*9880d681SAndroid Build Coastguard Workerdefm SUB : BinaryInt<sub, "sub ">;
22*9880d681SAndroid Build Coastguard Workerlet isCommutable = 1 in
23*9880d681SAndroid Build Coastguard Workerdefm MUL : BinaryInt<mul, "mul ">;
24*9880d681SAndroid Build Coastguard Worker// Divide and remainder trap on a zero denominator.
25*9880d681SAndroid Build Coastguard Workerlet hasSideEffects = 1 in {
26*9880d681SAndroid Build Coastguard Workerdefm DIV_S : BinaryInt<sdiv, "div_s">;
27*9880d681SAndroid Build Coastguard Workerdefm DIV_U : BinaryInt<udiv, "div_u">;
28*9880d681SAndroid Build Coastguard Workerdefm REM_S : BinaryInt<srem, "rem_s">;
29*9880d681SAndroid Build Coastguard Workerdefm REM_U : BinaryInt<urem, "rem_u">;
30*9880d681SAndroid Build Coastguard Worker} // hasSideEffects = 1
31*9880d681SAndroid Build Coastguard Workerlet isCommutable = 1 in {
32*9880d681SAndroid Build Coastguard Workerdefm AND : BinaryInt<and, "and ">;
33*9880d681SAndroid Build Coastguard Workerdefm OR : BinaryInt<or, "or  ">;
34*9880d681SAndroid Build Coastguard Workerdefm XOR : BinaryInt<xor, "xor ">;
35*9880d681SAndroid Build Coastguard Worker} // isCommutable = 1
36*9880d681SAndroid Build Coastguard Workerdefm SHL : BinaryInt<shl, "shl ">;
37*9880d681SAndroid Build Coastguard Workerdefm SHR_U : BinaryInt<srl, "shr_u">;
38*9880d681SAndroid Build Coastguard Workerdefm SHR_S : BinaryInt<sra, "shr_s">;
39*9880d681SAndroid Build Coastguard Workerdefm ROTL : BinaryInt<rotl, "rotl">;
40*9880d681SAndroid Build Coastguard Workerdefm ROTR : BinaryInt<rotr, "rotr">;
41*9880d681SAndroid Build Coastguard Worker
42*9880d681SAndroid Build Coastguard Workerlet isCommutable = 1 in {
43*9880d681SAndroid Build Coastguard Workerdefm EQ : ComparisonInt<SETEQ, "eq  ">;
44*9880d681SAndroid Build Coastguard Workerdefm NE : ComparisonInt<SETNE, "ne  ">;
45*9880d681SAndroid Build Coastguard Worker} // isCommutable = 1
46*9880d681SAndroid Build Coastguard Workerdefm LT_S : ComparisonInt<SETLT, "lt_s">;
47*9880d681SAndroid Build Coastguard Workerdefm LE_S : ComparisonInt<SETLE, "le_s">;
48*9880d681SAndroid Build Coastguard Workerdefm LT_U : ComparisonInt<SETULT, "lt_u">;
49*9880d681SAndroid Build Coastguard Workerdefm LE_U : ComparisonInt<SETULE, "le_u">;
50*9880d681SAndroid Build Coastguard Workerdefm GT_S : ComparisonInt<SETGT, "gt_s">;
51*9880d681SAndroid Build Coastguard Workerdefm GE_S : ComparisonInt<SETGE, "ge_s">;
52*9880d681SAndroid Build Coastguard Workerdefm GT_U : ComparisonInt<SETUGT, "gt_u">;
53*9880d681SAndroid Build Coastguard Workerdefm GE_U : ComparisonInt<SETUGE, "ge_u">;
54*9880d681SAndroid Build Coastguard Worker
55*9880d681SAndroid Build Coastguard Workerdefm CLZ : UnaryInt<ctlz, "clz ">;
56*9880d681SAndroid Build Coastguard Workerdefm CTZ : UnaryInt<cttz, "ctz ">;
57*9880d681SAndroid Build Coastguard Workerdefm POPCNT : UnaryInt<ctpop, "popcnt">;
58*9880d681SAndroid Build Coastguard Worker
59*9880d681SAndroid Build Coastguard Workerdef EQZ_I32 : I<(outs I32:$dst), (ins I32:$src),
60*9880d681SAndroid Build Coastguard Worker                [(set I32:$dst, (setcc I32:$src, 0, SETEQ))],
61*9880d681SAndroid Build Coastguard Worker                "i32.eqz \t$dst, $src">;
62*9880d681SAndroid Build Coastguard Workerdef EQZ_I64 : I<(outs I32:$dst), (ins I64:$src),
63*9880d681SAndroid Build Coastguard Worker                [(set I32:$dst, (setcc I64:$src, 0, SETEQ))],
64*9880d681SAndroid Build Coastguard Worker                "i64.eqz \t$dst, $src">;
65*9880d681SAndroid Build Coastguard Worker
66*9880d681SAndroid Build Coastguard Worker} // Defs = [ARGUMENTS]
67*9880d681SAndroid Build Coastguard Worker
68*9880d681SAndroid Build Coastguard Worker// Optimize away an explicit mask on a rotate count.
69*9880d681SAndroid Build Coastguard Workerdef : Pat<(rotl I32:$lhs, (and I32:$rhs, 31)), (ROTL_I32 I32:$lhs, I32:$rhs)>;
70*9880d681SAndroid Build Coastguard Workerdef : Pat<(rotr I32:$lhs, (and I32:$rhs, 31)), (ROTR_I32 I32:$lhs, I32:$rhs)>;
71*9880d681SAndroid Build Coastguard Workerdef : Pat<(rotl I64:$lhs, (and I64:$rhs, 63)), (ROTL_I64 I64:$lhs, I64:$rhs)>;
72*9880d681SAndroid Build Coastguard Workerdef : Pat<(rotr I64:$lhs, (and I64:$rhs, 63)), (ROTR_I64 I64:$lhs, I64:$rhs)>;
73*9880d681SAndroid Build Coastguard Worker
74*9880d681SAndroid Build Coastguard Workerlet Defs = [ARGUMENTS] in {
75*9880d681SAndroid Build Coastguard Worker
76*9880d681SAndroid Build Coastguard Workerdef SELECT_I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs, I32:$cond),
77*9880d681SAndroid Build Coastguard Worker                   [(set I32:$dst, (select I32:$cond, I32:$lhs, I32:$rhs))],
78*9880d681SAndroid Build Coastguard Worker                   "i32.select\t$dst, $lhs, $rhs, $cond">;
79*9880d681SAndroid Build Coastguard Workerdef SELECT_I64 : I<(outs I64:$dst), (ins I64:$lhs, I64:$rhs, I32:$cond),
80*9880d681SAndroid Build Coastguard Worker                   [(set I64:$dst, (select I32:$cond, I64:$lhs, I64:$rhs))],
81*9880d681SAndroid Build Coastguard Worker                   "i64.select\t$dst, $lhs, $rhs, $cond">;
82*9880d681SAndroid Build Coastguard Worker
83*9880d681SAndroid Build Coastguard Worker} // Defs = [ARGUMENTS]
84*9880d681SAndroid Build Coastguard Worker
85*9880d681SAndroid Build Coastguard Worker// ISD::SELECT requires its operand to conform to getBooleanContents, but
86*9880d681SAndroid Build Coastguard Worker// WebAssembly's select interprets any non-zero value as true, so we can fold
87*9880d681SAndroid Build Coastguard Worker// a setne with 0 into a select.
88*9880d681SAndroid Build Coastguard Workerdef : Pat<(select (i32 (setne I32:$cond, 0)), I32:$lhs, I32:$rhs),
89*9880d681SAndroid Build Coastguard Worker          (SELECT_I32 I32:$lhs, I32:$rhs, I32:$cond)>;
90*9880d681SAndroid Build Coastguard Workerdef : Pat<(select (i32 (setne I32:$cond, 0)), I64:$lhs, I64:$rhs),
91*9880d681SAndroid Build Coastguard Worker          (SELECT_I64 I64:$lhs, I64:$rhs, I32:$cond)>;
92*9880d681SAndroid Build Coastguard Worker
93*9880d681SAndroid Build Coastguard Worker// And again, this time with seteq instead of setne and the arms reversed.
94*9880d681SAndroid Build Coastguard Workerdef : Pat<(select (i32 (seteq I32:$cond, 0)), I32:$lhs, I32:$rhs),
95*9880d681SAndroid Build Coastguard Worker          (SELECT_I32 I32:$rhs, I32:$lhs, I32:$cond)>;
96*9880d681SAndroid Build Coastguard Workerdef : Pat<(select (i32 (seteq I32:$cond, 0)), I64:$lhs, I64:$rhs),
97*9880d681SAndroid Build Coastguard Worker          (SELECT_I64 I64:$rhs, I64:$lhs, I32:$cond)>;
98