xref: /aosp_15_r20/external/llvm/lib/Target/SystemZ/SystemZPatterns.td (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker//===-- SystemZPatterns.td - SystemZ-specific pattern rules ---*- tblgen-*-===//
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// Record that INSN performs a 64-bit version of unary operator OPERATOR
11*9880d681SAndroid Build Coastguard Worker// in which the operand is sign-extended from 32 to 64 bits.
12*9880d681SAndroid Build Coastguard Workermulticlass SXU<SDPatternOperator operator, Instruction insn> {
13*9880d681SAndroid Build Coastguard Worker  def : Pat<(operator (sext (i32 GR32:$src))),
14*9880d681SAndroid Build Coastguard Worker            (insn GR32:$src)>;
15*9880d681SAndroid Build Coastguard Worker  def : Pat<(operator (sext_inreg GR64:$src, i32)),
16*9880d681SAndroid Build Coastguard Worker            (insn (EXTRACT_SUBREG GR64:$src, subreg_l32))>;
17*9880d681SAndroid Build Coastguard Worker}
18*9880d681SAndroid Build Coastguard Worker
19*9880d681SAndroid Build Coastguard Worker// Record that INSN performs a 64-bit version of binary operator OPERATOR
20*9880d681SAndroid Build Coastguard Worker// in which the first operand has class CLS and which the second operand
21*9880d681SAndroid Build Coastguard Worker// is sign-extended from a 32-bit register.
22*9880d681SAndroid Build Coastguard Workermulticlass SXB<SDPatternOperator operator, RegisterOperand cls,
23*9880d681SAndroid Build Coastguard Worker               Instruction insn> {
24*9880d681SAndroid Build Coastguard Worker  def : Pat<(operator cls:$src1, (sext GR32:$src2)),
25*9880d681SAndroid Build Coastguard Worker            (insn cls:$src1, GR32:$src2)>;
26*9880d681SAndroid Build Coastguard Worker  def : Pat<(operator cls:$src1, (sext_inreg GR64:$src2, i32)),
27*9880d681SAndroid Build Coastguard Worker            (insn cls:$src1, (EXTRACT_SUBREG GR64:$src2, subreg_l32))>;
28*9880d681SAndroid Build Coastguard Worker}
29*9880d681SAndroid Build Coastguard Worker
30*9880d681SAndroid Build Coastguard Worker// Like SXB, but for zero extension.
31*9880d681SAndroid Build Coastguard Workermulticlass ZXB<SDPatternOperator operator, RegisterOperand cls,
32*9880d681SAndroid Build Coastguard Worker               Instruction insn> {
33*9880d681SAndroid Build Coastguard Worker  def : Pat<(operator cls:$src1, (zext GR32:$src2)),
34*9880d681SAndroid Build Coastguard Worker            (insn cls:$src1, GR32:$src2)>;
35*9880d681SAndroid Build Coastguard Worker  def : Pat<(operator cls:$src1, (and GR64:$src2, 0xffffffff)),
36*9880d681SAndroid Build Coastguard Worker            (insn cls:$src1, (EXTRACT_SUBREG GR64:$src2, subreg_l32))>;
37*9880d681SAndroid Build Coastguard Worker}
38*9880d681SAndroid Build Coastguard Worker
39*9880d681SAndroid Build Coastguard Worker// Record that INSN performs a binary read-modify-write operation,
40*9880d681SAndroid Build Coastguard Worker// with LOAD, OPERATOR and STORE being the read, modify and write
41*9880d681SAndroid Build Coastguard Worker// respectively.  MODE is the addressing mode and IMM is the type
42*9880d681SAndroid Build Coastguard Worker// of the second operand.
43*9880d681SAndroid Build Coastguard Workerclass RMWI<SDPatternOperator load, SDPatternOperator operator,
44*9880d681SAndroid Build Coastguard Worker           SDPatternOperator store, AddressingMode mode,
45*9880d681SAndroid Build Coastguard Worker           PatFrag imm, Instruction insn>
46*9880d681SAndroid Build Coastguard Worker  : Pat<(store (operator (load mode:$addr), imm:$src), mode:$addr),
47*9880d681SAndroid Build Coastguard Worker        (insn mode:$addr, (UIMM8 imm:$src))>;
48*9880d681SAndroid Build Coastguard Worker
49*9880d681SAndroid Build Coastguard Worker// Record that INSN performs binary operation OPERATION on a byte
50*9880d681SAndroid Build Coastguard Worker// memory location.  IMM is the type of the second operand.
51*9880d681SAndroid Build Coastguard Workermulticlass RMWIByte<SDPatternOperator operator, AddressingMode mode,
52*9880d681SAndroid Build Coastguard Worker                    Instruction insn> {
53*9880d681SAndroid Build Coastguard Worker  def : RMWI<anyextloadi8, operator, truncstorei8, mode, imm32, insn>;
54*9880d681SAndroid Build Coastguard Worker  def : RMWI<anyextloadi8, operator, truncstorei8, mode, imm64, insn>;
55*9880d681SAndroid Build Coastguard Worker}
56*9880d681SAndroid Build Coastguard Worker
57*9880d681SAndroid Build Coastguard Worker// Record that INSN performs insertion TYPE into a register of class CLS.
58*9880d681SAndroid Build Coastguard Worker// The inserted operand is loaded using LOAD from an address of mode MODE.
59*9880d681SAndroid Build Coastguard Workermulticlass InsertMem<string type, Instruction insn, RegisterOperand cls,
60*9880d681SAndroid Build Coastguard Worker                     SDPatternOperator load, AddressingMode mode> {
61*9880d681SAndroid Build Coastguard Worker  def : Pat<(!cast<SDPatternOperator>("or_as_"##type)
62*9880d681SAndroid Build Coastguard Worker              cls:$src1, (load mode:$src2)),
63*9880d681SAndroid Build Coastguard Worker            (insn cls:$src1, mode:$src2)>;
64*9880d681SAndroid Build Coastguard Worker  def : Pat<(!cast<SDPatternOperator>("or_as_rev"##type)
65*9880d681SAndroid Build Coastguard Worker              (load mode:$src2), cls:$src1),
66*9880d681SAndroid Build Coastguard Worker            (insn cls:$src1, mode:$src2)>;
67*9880d681SAndroid Build Coastguard Worker}
68*9880d681SAndroid Build Coastguard Worker
69*9880d681SAndroid Build Coastguard Worker// INSN stores the low 32 bits of a GPR to a memory with addressing mode MODE.
70*9880d681SAndroid Build Coastguard Worker// Record that it is equivalent to using OPERATOR to store a GR64.
71*9880d681SAndroid Build Coastguard Workerclass StoreGR64<Instruction insn, SDPatternOperator operator,
72*9880d681SAndroid Build Coastguard Worker                AddressingMode mode>
73*9880d681SAndroid Build Coastguard Worker  : Pat<(operator GR64:$R1, mode:$XBD2),
74*9880d681SAndroid Build Coastguard Worker        (insn (EXTRACT_SUBREG GR64:$R1, subreg_l32), mode:$XBD2)>;
75*9880d681SAndroid Build Coastguard Worker
76*9880d681SAndroid Build Coastguard Worker// INSN and INSNY are an RX/RXY pair of instructions that store the low
77*9880d681SAndroid Build Coastguard Worker// 32 bits of a GPR to memory.  Record that they are equivalent to using
78*9880d681SAndroid Build Coastguard Worker// OPERATOR to store a GR64.
79*9880d681SAndroid Build Coastguard Workermulticlass StoreGR64Pair<Instruction insn, Instruction insny,
80*9880d681SAndroid Build Coastguard Worker                         SDPatternOperator operator> {
81*9880d681SAndroid Build Coastguard Worker  def : StoreGR64<insn, operator, bdxaddr12pair>;
82*9880d681SAndroid Build Coastguard Worker  def : StoreGR64<insny, operator, bdxaddr20pair>;
83*9880d681SAndroid Build Coastguard Worker}
84*9880d681SAndroid Build Coastguard Worker
85*9880d681SAndroid Build Coastguard Worker// INSN stores the low 32 bits of a GPR using PC-relative addressing.
86*9880d681SAndroid Build Coastguard Worker// Record that it is equivalent to using OPERATOR to store a GR64.
87*9880d681SAndroid Build Coastguard Workerclass StoreGR64PC<Instruction insn, SDPatternOperator operator>
88*9880d681SAndroid Build Coastguard Worker  : Pat<(operator GR64:$R1, pcrel32:$XBD2),
89*9880d681SAndroid Build Coastguard Worker        (insn (EXTRACT_SUBREG GR64:$R1, subreg_l32), pcrel32:$XBD2)> {
90*9880d681SAndroid Build Coastguard Worker  // We want PC-relative addresses to be tried ahead of BD and BDX addresses.
91*9880d681SAndroid Build Coastguard Worker  // However, BDXs have two extra operands and are therefore 6 units more
92*9880d681SAndroid Build Coastguard Worker  // complex.
93*9880d681SAndroid Build Coastguard Worker  let AddedComplexity = 7;
94*9880d681SAndroid Build Coastguard Worker}
95*9880d681SAndroid Build Coastguard Worker
96*9880d681SAndroid Build Coastguard Worker// INSN and INSNINV conditionally store the low 32 bits of a GPR to memory,
97*9880d681SAndroid Build Coastguard Worker// with INSN storing when the condition is true and INSNINV storing when the
98*9880d681SAndroid Build Coastguard Worker// condition is false.  Record that they are equivalent to a LOAD/select/STORE
99*9880d681SAndroid Build Coastguard Worker// sequence for GR64s.
100*9880d681SAndroid Build Coastguard Workermulticlass CondStores64<Instruction insn, Instruction insninv,
101*9880d681SAndroid Build Coastguard Worker                        SDPatternOperator store, SDPatternOperator load,
102*9880d681SAndroid Build Coastguard Worker                        AddressingMode mode> {
103*9880d681SAndroid Build Coastguard Worker  def : Pat<(store (z_select_ccmask GR64:$new, (load mode:$addr),
104*9880d681SAndroid Build Coastguard Worker                                    imm32zx4:$valid, imm32zx4:$cc),
105*9880d681SAndroid Build Coastguard Worker                   mode:$addr),
106*9880d681SAndroid Build Coastguard Worker            (insn (EXTRACT_SUBREG GR64:$new, subreg_l32), mode:$addr,
107*9880d681SAndroid Build Coastguard Worker                  imm32zx4:$valid, imm32zx4:$cc)>;
108*9880d681SAndroid Build Coastguard Worker  def : Pat<(store (z_select_ccmask (load mode:$addr), GR64:$new,
109*9880d681SAndroid Build Coastguard Worker                                    imm32zx4:$valid, imm32zx4:$cc),
110*9880d681SAndroid Build Coastguard Worker                   mode:$addr),
111*9880d681SAndroid Build Coastguard Worker            (insninv (EXTRACT_SUBREG GR64:$new, subreg_l32), mode:$addr,
112*9880d681SAndroid Build Coastguard Worker                     imm32zx4:$valid, imm32zx4:$cc)>;
113*9880d681SAndroid Build Coastguard Worker}
114*9880d681SAndroid Build Coastguard Worker
115*9880d681SAndroid Build Coastguard Worker// Try to use MVC instruction INSN for a load of type LOAD followed by a store
116*9880d681SAndroid Build Coastguard Worker// of the same size.  VT is the type of the intermediate (legalized) value and
117*9880d681SAndroid Build Coastguard Worker// LENGTH is the number of bytes loaded by LOAD.
118*9880d681SAndroid Build Coastguard Workermulticlass MVCLoadStore<SDPatternOperator load, ValueType vt, Instruction insn,
119*9880d681SAndroid Build Coastguard Worker                        bits<5> length> {
120*9880d681SAndroid Build Coastguard Worker  def : Pat<(mvc_store (vt (load bdaddr12only:$src)), bdaddr12only:$dest),
121*9880d681SAndroid Build Coastguard Worker            (insn bdaddr12only:$dest, bdaddr12only:$src, length)>;
122*9880d681SAndroid Build Coastguard Worker}
123*9880d681SAndroid Build Coastguard Worker
124*9880d681SAndroid Build Coastguard Worker// Use NC-like instruction INSN for block_op operation OPERATOR.
125*9880d681SAndroid Build Coastguard Worker// The other operand is a load of type LOAD, which accesses LENGTH bytes.
126*9880d681SAndroid Build Coastguard Worker// VT is the intermediate legalized type in which the binary operation
127*9880d681SAndroid Build Coastguard Worker// is actually done.
128*9880d681SAndroid Build Coastguard Workermulticlass BinaryLoadStore<SDPatternOperator operator, SDPatternOperator load,
129*9880d681SAndroid Build Coastguard Worker                           ValueType vt, Instruction insn, bits<5> length> {
130*9880d681SAndroid Build Coastguard Worker  def : Pat<(operator (vt (load bdaddr12only:$src)), bdaddr12only:$dest),
131*9880d681SAndroid Build Coastguard Worker            (insn bdaddr12only:$dest, bdaddr12only:$src, length)>;
132*9880d681SAndroid Build Coastguard Worker}
133*9880d681SAndroid Build Coastguard Worker
134*9880d681SAndroid Build Coastguard Worker// A convenient way of generating all block peepholes for a particular
135*9880d681SAndroid Build Coastguard Worker// LOAD/VT/LENGTH combination.
136*9880d681SAndroid Build Coastguard Workermulticlass BlockLoadStore<SDPatternOperator load, ValueType vt,
137*9880d681SAndroid Build Coastguard Worker                          Instruction mvc, Instruction nc, Instruction oc,
138*9880d681SAndroid Build Coastguard Worker                          Instruction xc, bits<5> length> {
139*9880d681SAndroid Build Coastguard Worker  defm : MVCLoadStore<load, vt, mvc, length>;
140*9880d681SAndroid Build Coastguard Worker  defm : BinaryLoadStore<block_and1, load, vt, nc, length>;
141*9880d681SAndroid Build Coastguard Worker  defm : BinaryLoadStore<block_and2, load, vt, nc, length>;
142*9880d681SAndroid Build Coastguard Worker  defm : BinaryLoadStore<block_or1,  load, vt, oc, length>;
143*9880d681SAndroid Build Coastguard Worker  defm : BinaryLoadStore<block_or2,  load, vt, oc, length>;
144*9880d681SAndroid Build Coastguard Worker  defm : BinaryLoadStore<block_xor1, load, vt, xc, length>;
145*9880d681SAndroid Build Coastguard Worker  defm : BinaryLoadStore<block_xor2, load, vt, xc, length>;
146*9880d681SAndroid Build Coastguard Worker}
147*9880d681SAndroid Build Coastguard Worker
148*9880d681SAndroid Build Coastguard Worker// Record that INSN is a LOAD AND TEST that can be used to compare
149*9880d681SAndroid Build Coastguard Worker// registers in CLS against zero.  The instruction has separate R1 and R2
150*9880d681SAndroid Build Coastguard Worker// operands, but they must be the same when the instruction is used like this.
151*9880d681SAndroid Build Coastguard Workermulticlass CompareZeroFP<Instruction insn, RegisterOperand cls> {
152*9880d681SAndroid Build Coastguard Worker  def : Pat<(z_fcmp cls:$reg, (fpimm0)), (insn cls:$reg, cls:$reg)>;
153*9880d681SAndroid Build Coastguard Worker  // The sign of the zero makes no difference.
154*9880d681SAndroid Build Coastguard Worker  def : Pat<(z_fcmp cls:$reg, (fpimmneg0)), (insn cls:$reg, cls:$reg)>;
155*9880d681SAndroid Build Coastguard Worker}
156*9880d681SAndroid Build Coastguard Worker
157*9880d681SAndroid Build Coastguard Worker// Use INSN for performing binary operation OPERATION of type VT
158*9880d681SAndroid Build Coastguard Worker// on registers of class CLS.
159*9880d681SAndroid Build Coastguard Workerclass BinaryRRWithType<Instruction insn, RegisterOperand cls,
160*9880d681SAndroid Build Coastguard Worker                       SDPatternOperator operator, ValueType vt>
161*9880d681SAndroid Build Coastguard Worker  : Pat<(vt (operator cls:$x, cls:$y)), (insn cls:$x, cls:$y)>;
162*9880d681SAndroid Build Coastguard Worker
163*9880d681SAndroid Build Coastguard Worker// Use INSN to perform conversion operation OPERATOR, with the input being
164*9880d681SAndroid Build Coastguard Worker// TR2 and the output being TR1.  SUPPRESS is 4 to suppress inexact conditions
165*9880d681SAndroid Build Coastguard Worker// and 0 to allow them.  MODE is the rounding mode to use.
166*9880d681SAndroid Build Coastguard Workerclass FPConversion<Instruction insn, SDPatternOperator operator, TypedReg tr1,
167*9880d681SAndroid Build Coastguard Worker                   TypedReg tr2, bits<3> suppress, bits<4> mode>
168*9880d681SAndroid Build Coastguard Worker  : Pat<(tr1.vt (operator (tr2.vt tr2.op:$vec))),
169*9880d681SAndroid Build Coastguard Worker        (insn tr2.op:$vec, suppress, mode)>;
170