15f613dfdSUlrich Weigand//===-- SystemZPatterns.td - SystemZ-specific pattern rules ---*- tblgen-*-===//
25f613dfdSUlrich Weigand//
35f613dfdSUlrich Weigand//                     The LLVM Compiler Infrastructure
45f613dfdSUlrich Weigand//
55f613dfdSUlrich Weigand// This file is distributed under the University of Illinois Open Source
65f613dfdSUlrich Weigand// License. See LICENSE.TXT for details.
75f613dfdSUlrich Weigand//
85f613dfdSUlrich Weigand//===----------------------------------------------------------------------===//
95f613dfdSUlrich Weigand
105f613dfdSUlrich Weigand// Record that INSN performs a 64-bit version of unary operator OPERATOR
115f613dfdSUlrich Weigand// in which the operand is sign-extended from 32 to 64 bits.
125f613dfdSUlrich Weigandmulticlass SXU<SDPatternOperator operator, Instruction insn> {
135f613dfdSUlrich Weigand  def : Pat<(operator (sext (i32 GR32:$src))),
145f613dfdSUlrich Weigand            (insn GR32:$src)>;
155f613dfdSUlrich Weigand  def : Pat<(operator (sext_inreg GR64:$src, i32)),
1687a44364SRichard Sandiford            (insn (EXTRACT_SUBREG GR64:$src, subreg_l32))>;
175f613dfdSUlrich Weigand}
185f613dfdSUlrich Weigand
195f613dfdSUlrich Weigand// Record that INSN performs a 64-bit version of binary operator OPERATOR
205f613dfdSUlrich Weigand// in which the first operand has class CLS and which the second operand
215f613dfdSUlrich Weigand// is sign-extended from a 32-bit register.
225f613dfdSUlrich Weigandmulticlass SXB<SDPatternOperator operator, RegisterOperand cls,
235f613dfdSUlrich Weigand               Instruction insn> {
245f613dfdSUlrich Weigand  def : Pat<(operator cls:$src1, (sext GR32:$src2)),
255f613dfdSUlrich Weigand            (insn cls:$src1, GR32:$src2)>;
265f613dfdSUlrich Weigand  def : Pat<(operator cls:$src1, (sext_inreg GR64:$src2, i32)),
2787a44364SRichard Sandiford            (insn cls:$src1, (EXTRACT_SUBREG GR64:$src2, subreg_l32))>;
285f613dfdSUlrich Weigand}
295f613dfdSUlrich Weigand
305f613dfdSUlrich Weigand// Like SXB, but for zero extension.
315f613dfdSUlrich Weigandmulticlass ZXB<SDPatternOperator operator, RegisterOperand cls,
325f613dfdSUlrich Weigand               Instruction insn> {
335f613dfdSUlrich Weigand  def : Pat<(operator cls:$src1, (zext GR32:$src2)),
345f613dfdSUlrich Weigand            (insn cls:$src1, GR32:$src2)>;
355f613dfdSUlrich Weigand  def : Pat<(operator cls:$src1, (and GR64:$src2, 0xffffffff)),
3687a44364SRichard Sandiford            (insn cls:$src1, (EXTRACT_SUBREG GR64:$src2, subreg_l32))>;
375f613dfdSUlrich Weigand}
385f613dfdSUlrich Weigand
395f613dfdSUlrich Weigand// Record that INSN performs a binary read-modify-write operation,
405f613dfdSUlrich Weigand// with LOAD, OPERATOR and STORE being the read, modify and write
415f613dfdSUlrich Weigand// respectively.  MODE is the addressing mode and IMM is the type
425f613dfdSUlrich Weigand// of the second operand.
435f613dfdSUlrich Weigandclass RMWI<SDPatternOperator load, SDPatternOperator operator,
445f613dfdSUlrich Weigand           SDPatternOperator store, AddressingMode mode,
455f613dfdSUlrich Weigand           PatFrag imm, Instruction insn>
465f613dfdSUlrich Weigand  : Pat<(store (operator (load mode:$addr), imm:$src), mode:$addr),
475f613dfdSUlrich Weigand        (insn mode:$addr, (UIMM8 imm:$src))>;
485f613dfdSUlrich Weigand
495f613dfdSUlrich Weigand// Record that INSN performs binary operation OPERATION on a byte
505f613dfdSUlrich Weigand// memory location.  IMM is the type of the second operand.
515f613dfdSUlrich Weigandmulticlass RMWIByte<SDPatternOperator operator, AddressingMode mode,
525f613dfdSUlrich Weigand                    Instruction insn> {
53b86a8348SRichard Sandiford  def : RMWI<anyextloadi8, operator, truncstorei8, mode, imm32, insn>;
54b86a8348SRichard Sandiford  def : RMWI<anyextloadi8, operator, truncstorei8, mode, imm64, insn>;
555f613dfdSUlrich Weigand}
565f613dfdSUlrich Weigand
575f613dfdSUlrich Weigand// Record that INSN performs insertion TYPE into a register of class CLS.
585f613dfdSUlrich Weigand// The inserted operand is loaded using LOAD from an address of mode MODE.
595f613dfdSUlrich Weigandmulticlass InsertMem<string type, Instruction insn, RegisterOperand cls,
605f613dfdSUlrich Weigand                     SDPatternOperator load, AddressingMode mode> {
615f613dfdSUlrich Weigand  def : Pat<(!cast<SDPatternOperator>("or_as_"##type)
625f613dfdSUlrich Weigand              cls:$src1, (load mode:$src2)),
635f613dfdSUlrich Weigand            (insn cls:$src1, mode:$src2)>;
645f613dfdSUlrich Weigand  def : Pat<(!cast<SDPatternOperator>("or_as_rev"##type)
655f613dfdSUlrich Weigand              (load mode:$src2), cls:$src1),
665f613dfdSUlrich Weigand            (insn cls:$src1, mode:$src2)>;
675f613dfdSUlrich Weigand}
6897846491SRichard Sandiford
696cbd7f0cSRichard Sandiford// INSN stores the low 32 bits of a GPR to a memory with addressing mode MODE.
706cbd7f0cSRichard Sandiford// Record that it is equivalent to using OPERATOR to store a GR64.
716cbd7f0cSRichard Sandifordclass StoreGR64<Instruction insn, SDPatternOperator operator,
726cbd7f0cSRichard Sandiford                AddressingMode mode>
736cbd7f0cSRichard Sandiford  : Pat<(operator GR64:$R1, mode:$XBD2),
7487a44364SRichard Sandiford        (insn (EXTRACT_SUBREG GR64:$R1, subreg_l32), mode:$XBD2)>;
756cbd7f0cSRichard Sandiford
766cbd7f0cSRichard Sandiford// INSN and INSNY are an RX/RXY pair of instructions that store the low
776cbd7f0cSRichard Sandiford// 32 bits of a GPR to memory.  Record that they are equivalent to using
786cbd7f0cSRichard Sandiford// OPERATOR to store a GR64.
796cbd7f0cSRichard Sandifordmulticlass StoreGR64Pair<Instruction insn, Instruction insny,
806cbd7f0cSRichard Sandiford                         SDPatternOperator operator> {
816cbd7f0cSRichard Sandiford  def : StoreGR64<insn, operator, bdxaddr12pair>;
826cbd7f0cSRichard Sandiford  def : StoreGR64<insny, operator, bdxaddr20pair>;
836cbd7f0cSRichard Sandiford}
846cbd7f0cSRichard Sandiford
856cbd7f0cSRichard Sandiford// INSN stores the low 32 bits of a GPR using PC-relative addressing.
866cbd7f0cSRichard Sandiford// Record that it is equivalent to using OPERATOR to store a GR64.
876cbd7f0cSRichard Sandifordclass StoreGR64PC<Instruction insn, SDPatternOperator operator>
886cbd7f0cSRichard Sandiford  : Pat<(operator GR64:$R1, pcrel32:$XBD2),
8987a44364SRichard Sandiford        (insn (EXTRACT_SUBREG GR64:$R1, subreg_l32), pcrel32:$XBD2)> {
906cbd7f0cSRichard Sandiford  // We want PC-relative addresses to be tried ahead of BD and BDX addresses.
916cbd7f0cSRichard Sandiford  // However, BDXs have two extra operands and are therefore 6 units more
926cbd7f0cSRichard Sandiford  // complex.
936cbd7f0cSRichard Sandiford  let AddedComplexity = 7;
946cbd7f0cSRichard Sandiford}
956cbd7f0cSRichard Sandiford
966cbd7f0cSRichard Sandiford// INSN and INSNINV conditionally store the low 32 bits of a GPR to memory,
976cbd7f0cSRichard Sandiford// with INSN storing when the condition is true and INSNINV storing when the
986cbd7f0cSRichard Sandiford// condition is false.  Record that they are equivalent to a LOAD/select/STORE
996cbd7f0cSRichard Sandiford// sequence for GR64s.
1006cbd7f0cSRichard Sandifordmulticlass CondStores64<Instruction insn, Instruction insninv,
1016cbd7f0cSRichard Sandiford                        SDPatternOperator store, SDPatternOperator load,
1026cbd7f0cSRichard Sandiford                        AddressingMode mode> {
1036cbd7f0cSRichard Sandiford  def : Pat<(store (z_select_ccmask GR64:$new, (load mode:$addr),
104ca44614aSRichard Sandiford                                    imm32zx4:$valid, imm32zx4:$cc),
1056cbd7f0cSRichard Sandiford                   mode:$addr),
10687a44364SRichard Sandiford            (insn (EXTRACT_SUBREG GR64:$new, subreg_l32), mode:$addr,
107ca44614aSRichard Sandiford                  imm32zx4:$valid, imm32zx4:$cc)>;
1086cbd7f0cSRichard Sandiford  def : Pat<(store (z_select_ccmask (load mode:$addr), GR64:$new,
109ca44614aSRichard Sandiford                                    imm32zx4:$valid, imm32zx4:$cc),
1106cbd7f0cSRichard Sandiford                   mode:$addr),
11187a44364SRichard Sandiford            (insninv (EXTRACT_SUBREG GR64:$new, subreg_l32), mode:$addr,
112ca44614aSRichard Sandiford                     imm32zx4:$valid, imm32zx4:$cc)>;
1136cbd7f0cSRichard Sandiford}
1146cbd7f0cSRichard Sandiford
115178273a1SRichard Sandiford// Try to use MVC instruction INSN for a load of type LOAD followed by a store
116178273a1SRichard Sandiford// of the same size.  VT is the type of the intermediate (legalized) value and
117178273a1SRichard Sandiford// LENGTH is the number of bytes loaded by LOAD.
118178273a1SRichard Sandifordmulticlass MVCLoadStore<SDPatternOperator load, ValueType vt, Instruction insn,
119178273a1SRichard Sandiford                        bits<5> length> {
120178273a1SRichard Sandiford  def : Pat<(mvc_store (vt (load bdaddr12only:$src)), bdaddr12only:$dest),
12197846491SRichard Sandiford            (insn bdaddr12only:$dest, bdaddr12only:$src, length)>;
12297846491SRichard Sandiford}
1239f11bc19SRichard Sandiford
124178273a1SRichard Sandiford// Use NC-like instruction INSN for block_op operation OPERATOR.
125178273a1SRichard Sandiford// The other operand is a load of type LOAD, which accesses LENGTH bytes.
126178273a1SRichard Sandiford// VT is the intermediate legalized type in which the binary operation
127178273a1SRichard Sandiford// is actually done.
128178273a1SRichard Sandifordmulticlass BinaryLoadStore<SDPatternOperator operator, SDPatternOperator load,
129178273a1SRichard Sandiford                           ValueType vt, Instruction insn, bits<5> length> {
130178273a1SRichard Sandiford  def : Pat<(operator (vt (load bdaddr12only:$src)), bdaddr12only:$dest),
131178273a1SRichard Sandiford            (insn bdaddr12only:$dest, bdaddr12only:$src, length)>;
132178273a1SRichard Sandiford}
133178273a1SRichard Sandiford
134178273a1SRichard Sandiford// A convenient way of generating all block peepholes for a particular
135178273a1SRichard Sandiford// LOAD/VT/LENGTH combination.
136178273a1SRichard Sandifordmulticlass BlockLoadStore<SDPatternOperator load, ValueType vt,
137178273a1SRichard Sandiford                          Instruction mvc, Instruction nc, Instruction oc,
138178273a1SRichard Sandiford                          Instruction xc, bits<5> length> {
139178273a1SRichard Sandiford  defm : MVCLoadStore<load, vt, mvc, length>;
140178273a1SRichard Sandiford  defm : BinaryLoadStore<block_and1, load, vt, nc, length>;
141178273a1SRichard Sandiford  defm : BinaryLoadStore<block_and2, load, vt, nc, length>;
142178273a1SRichard Sandiford  defm : BinaryLoadStore<block_or1,  load, vt, oc, length>;
143178273a1SRichard Sandiford  defm : BinaryLoadStore<block_or2,  load, vt, oc, length>;
144178273a1SRichard Sandiford  defm : BinaryLoadStore<block_xor1, load, vt, xc, length>;
145178273a1SRichard Sandiford  defm : BinaryLoadStore<block_xor2, load, vt, xc, length>;
146178273a1SRichard Sandiford}
147178273a1SRichard Sandiford
1489f11bc19SRichard Sandiford// Record that INSN is a LOAD AND TEST that can be used to compare
1499f11bc19SRichard Sandiford// registers in CLS against zero.  The instruction has separate R1 and R2
1509f11bc19SRichard Sandiford// operands, but they must be the same when the instruction is used like this.
151198ddf83SRichard Sandifordmulticlass CompareZeroFP<Instruction insn, RegisterOperand cls> {
152198ddf83SRichard Sandiford  def : Pat<(z_fcmp cls:$reg, (fpimm0)), (insn cls:$reg, cls:$reg)>;
153198ddf83SRichard Sandiford  // The sign of the zero makes no difference.
154198ddf83SRichard Sandiford  def : Pat<(z_fcmp cls:$reg, (fpimmneg0)), (insn cls:$reg, cls:$reg)>;
155198ddf83SRichard Sandiford}
156*cd808237SUlrich Weigand
157*cd808237SUlrich Weigand// Use INSN for performing binary operation OPERATION of type VT
158*cd808237SUlrich Weigand// on registers of class CLS.
159*cd808237SUlrich Weigandclass BinaryRRWithType<Instruction insn, RegisterOperand cls,
160*cd808237SUlrich Weigand                       SDPatternOperator operator, ValueType vt>
161*cd808237SUlrich Weigand  : Pat<(vt (operator cls:$x, cls:$y)), (insn cls:$x, cls:$y)>;
162*cd808237SUlrich Weigand
163*cd808237SUlrich Weigand// Use INSN to perform conversion operation OPERATOR, with the input being
164*cd808237SUlrich Weigand// TR2 and the output being TR1.  SUPPRESS is 4 to suppress inexact conditions
165*cd808237SUlrich Weigand// and 0 to allow them.  MODE is the rounding mode to use.
166*cd808237SUlrich Weigandclass FPConversion<Instruction insn, SDPatternOperator operator, TypedReg tr1,
167*cd808237SUlrich Weigand                   TypedReg tr2, bits<3> suppress, bits<4> mode>
168*cd808237SUlrich Weigand  : Pat<(tr1.vt (operator (tr2.vt tr2.op:$vec))),
169*cd808237SUlrich Weigand        (insn tr2.op:$vec, suppress, mode)>;
170