10b57cec5SDimitry Andric//===-- SystemZPatterns.td - SystemZ-specific pattern rules ---*- tblgen-*-===// 20b57cec5SDimitry Andric// 30b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric// 70b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric// Record that INSN performs a 64-bit version of unary operator OPERATOR 100b57cec5SDimitry Andric// in which the operand is sign-extended from 32 to 64 bits. 110b57cec5SDimitry Andricmulticlass SXU<SDPatternOperator operator, Instruction insn> { 120b57cec5SDimitry Andric def : Pat<(operator (sext (i32 GR32:$src))), 130b57cec5SDimitry Andric (insn GR32:$src)>; 140b57cec5SDimitry Andric def : Pat<(operator (sext_inreg GR64:$src, i32)), 150b57cec5SDimitry Andric (insn (EXTRACT_SUBREG GR64:$src, subreg_l32))>; 160b57cec5SDimitry Andric} 170b57cec5SDimitry Andric 180b57cec5SDimitry Andric// Record that INSN performs a 64-bit version of binary operator OPERATOR 190b57cec5SDimitry Andric// in which the first operand has class CLS and which the second operand 200b57cec5SDimitry Andric// is sign-extended from a 32-bit register. 210b57cec5SDimitry Andricmulticlass SXB<SDPatternOperator operator, RegisterOperand cls, 220b57cec5SDimitry Andric Instruction insn> { 230b57cec5SDimitry Andric def : Pat<(operator cls:$src1, (sext GR32:$src2)), 240b57cec5SDimitry Andric (insn cls:$src1, GR32:$src2)>; 250b57cec5SDimitry Andric def : Pat<(operator cls:$src1, (sext_inreg GR64:$src2, i32)), 260b57cec5SDimitry Andric (insn cls:$src1, (EXTRACT_SUBREG GR64:$src2, subreg_l32))>; 270b57cec5SDimitry Andric} 280b57cec5SDimitry Andric 290b57cec5SDimitry Andric// Like SXB, but for zero extension. 300b57cec5SDimitry Andricmulticlass ZXB<SDPatternOperator operator, RegisterOperand cls, 310b57cec5SDimitry Andric Instruction insn> { 320b57cec5SDimitry Andric def : Pat<(operator cls:$src1, (zext GR32:$src2)), 330b57cec5SDimitry Andric (insn cls:$src1, GR32:$src2)>; 340b57cec5SDimitry Andric def : Pat<(operator cls:$src1, (and GR64:$src2, 0xffffffff)), 350b57cec5SDimitry Andric (insn cls:$src1, (EXTRACT_SUBREG GR64:$src2, subreg_l32))>; 360b57cec5SDimitry Andric} 370b57cec5SDimitry Andric 380b57cec5SDimitry Andric// Record that INSN performs a binary read-modify-write operation, 390b57cec5SDimitry Andric// with LOAD, OPERATOR and STORE being the read, modify and write 400b57cec5SDimitry Andric// respectively. MODE is the addressing mode and IMM is the type 410b57cec5SDimitry Andric// of the second operand. 420b57cec5SDimitry Andricclass RMWI<SDPatternOperator load, SDPatternOperator operator, 430b57cec5SDimitry Andric SDPatternOperator store, AddressingMode mode, 440b57cec5SDimitry Andric PatFrag imm, Instruction insn> 450b57cec5SDimitry Andric : Pat<(store (operator (load mode:$addr), imm:$src), mode:$addr), 460b57cec5SDimitry Andric (insn mode:$addr, (UIMM8 imm:$src))>; 470b57cec5SDimitry Andric 480b57cec5SDimitry Andric// Record that INSN performs binary operation OPERATION on a byte 490b57cec5SDimitry Andric// memory location. IMM is the type of the second operand. 500b57cec5SDimitry Andricmulticlass RMWIByte<SDPatternOperator operator, AddressingMode mode, 510b57cec5SDimitry Andric Instruction insn> { 52*0fca6ea1SDimitry Andric def : RMWI<z_anyextloadi8, operator, truncstorei8, mode, imm32, insn>; 53*0fca6ea1SDimitry Andric def : RMWI<z_anyextloadi8, operator, truncstorei8, mode, imm64, insn>; 540b57cec5SDimitry Andric} 550b57cec5SDimitry Andric 560b57cec5SDimitry Andric// Record that INSN performs insertion TYPE into a register of class CLS. 570b57cec5SDimitry Andric// The inserted operand is loaded using LOAD from an address of mode MODE. 580b57cec5SDimitry Andricmulticlass InsertMem<string type, Instruction insn, RegisterOperand cls, 590b57cec5SDimitry Andric SDPatternOperator load, AddressingMode mode> { 605ffd83dbSDimitry Andric def : Pat<(!cast<SDPatternOperator>("or_as_"#type) 610b57cec5SDimitry Andric cls:$src1, (load mode:$src2)), 620b57cec5SDimitry Andric (insn cls:$src1, mode:$src2)>; 635ffd83dbSDimitry Andric def : Pat<(!cast<SDPatternOperator>("or_as_rev"#type) 640b57cec5SDimitry Andric (load mode:$src2), cls:$src1), 650b57cec5SDimitry Andric (insn cls:$src1, mode:$src2)>; 660b57cec5SDimitry Andric} 670b57cec5SDimitry Andric 680b57cec5SDimitry Andric// INSN stores the low 32 bits of a GPR to a memory with addressing mode MODE. 690b57cec5SDimitry Andric// Record that it is equivalent to using OPERATOR to store a GR64. 700b57cec5SDimitry Andricclass StoreGR64<Instruction insn, SDPatternOperator operator, 710b57cec5SDimitry Andric AddressingMode mode> 720b57cec5SDimitry Andric : Pat<(operator GR64:$R1, mode:$XBD2), 730b57cec5SDimitry Andric (insn (EXTRACT_SUBREG GR64:$R1, subreg_l32), mode:$XBD2)>; 740b57cec5SDimitry Andric 750b57cec5SDimitry Andric// INSN and INSNY are an RX/RXY pair of instructions that store the low 760b57cec5SDimitry Andric// 32 bits of a GPR to memory. Record that they are equivalent to using 770b57cec5SDimitry Andric// OPERATOR to store a GR64. 780b57cec5SDimitry Andricmulticlass StoreGR64Pair<Instruction insn, Instruction insny, 790b57cec5SDimitry Andric SDPatternOperator operator> { 800b57cec5SDimitry Andric def : StoreGR64<insn, operator, bdxaddr12pair>; 810b57cec5SDimitry Andric def : StoreGR64<insny, operator, bdxaddr20pair>; 820b57cec5SDimitry Andric} 830b57cec5SDimitry Andric 840b57cec5SDimitry Andric// INSN stores the low 32 bits of a GPR using PC-relative addressing. 850b57cec5SDimitry Andric// Record that it is equivalent to using OPERATOR to store a GR64. 860b57cec5SDimitry Andricclass StoreGR64PC<Instruction insn, SDPatternOperator operator> 870b57cec5SDimitry Andric : Pat<(operator GR64:$R1, pcrel32:$XBD2), 880b57cec5SDimitry Andric (insn (EXTRACT_SUBREG GR64:$R1, subreg_l32), pcrel32:$XBD2)> { 890b57cec5SDimitry Andric // We want PC-relative addresses to be tried ahead of BD and BDX addresses. 900b57cec5SDimitry Andric // However, BDXs have two extra operands and are therefore 6 units more 910b57cec5SDimitry Andric // complex. 920b57cec5SDimitry Andric let AddedComplexity = 7; 930b57cec5SDimitry Andric} 940b57cec5SDimitry Andric 950b57cec5SDimitry Andric// INSN and INSNINV conditionally store the low 32 bits of a GPR to memory, 960b57cec5SDimitry Andric// with INSN storing when the condition is true and INSNINV storing when the 970b57cec5SDimitry Andric// condition is false. Record that they are equivalent to a LOAD/select/STORE 980b57cec5SDimitry Andric// sequence for GR64s. 990b57cec5SDimitry Andricmulticlass CondStores64<Instruction insn, Instruction insninv, 1000b57cec5SDimitry Andric SDPatternOperator store, SDPatternOperator load, 1010b57cec5SDimitry Andric AddressingMode mode> { 1020b57cec5SDimitry Andric def : Pat<(store (z_select_ccmask GR64:$new, (load mode:$addr), 1038bcb0991SDimitry Andric imm32zx4_timm:$valid, imm32zx4_timm:$cc), 1040b57cec5SDimitry Andric mode:$addr), 1050b57cec5SDimitry Andric (insn (EXTRACT_SUBREG GR64:$new, subreg_l32), mode:$addr, 1060b57cec5SDimitry Andric imm32zx4:$valid, imm32zx4:$cc)>; 1070b57cec5SDimitry Andric def : Pat<(store (z_select_ccmask (load mode:$addr), GR64:$new, 1088bcb0991SDimitry Andric imm32zx4_timm:$valid, imm32zx4_timm:$cc), 1090b57cec5SDimitry Andric mode:$addr), 1100b57cec5SDimitry Andric (insninv (EXTRACT_SUBREG GR64:$new, subreg_l32), mode:$addr, 1110b57cec5SDimitry Andric imm32zx4:$valid, imm32zx4:$cc)>; 1120b57cec5SDimitry Andric} 1130b57cec5SDimitry Andric 1140b57cec5SDimitry Andric// Try to use MVC instruction INSN for a load of type LOAD followed by a store 1150b57cec5SDimitry Andric// of the same size. VT is the type of the intermediate (legalized) value and 1160b57cec5SDimitry Andric// LENGTH is the number of bytes loaded by LOAD. 1170b57cec5SDimitry Andricmulticlass MVCLoadStore<SDPatternOperator load, ValueType vt, Instruction insn, 1180b57cec5SDimitry Andric bits<5> length> { 1190b57cec5SDimitry Andric def : Pat<(mvc_store (vt (load bdaddr12only:$src)), bdaddr12only:$dest), 1200b57cec5SDimitry Andric (insn bdaddr12only:$dest, bdaddr12only:$src, length)>; 1210b57cec5SDimitry Andric} 1220b57cec5SDimitry Andric 1230b57cec5SDimitry Andric// Use NC-like instruction INSN for block_op operation OPERATOR. 1240b57cec5SDimitry Andric// The other operand is a load of type LOAD, which accesses LENGTH bytes. 1250b57cec5SDimitry Andric// VT is the intermediate legalized type in which the binary operation 1260b57cec5SDimitry Andric// is actually done. 1270b57cec5SDimitry Andricmulticlass BinaryLoadStore<SDPatternOperator operator, SDPatternOperator load, 1280b57cec5SDimitry Andric ValueType vt, Instruction insn, bits<5> length> { 1290b57cec5SDimitry Andric def : Pat<(operator (vt (load bdaddr12only:$src)), bdaddr12only:$dest), 1300b57cec5SDimitry Andric (insn bdaddr12only:$dest, bdaddr12only:$src, length)>; 1310b57cec5SDimitry Andric} 1320b57cec5SDimitry Andric 1330b57cec5SDimitry Andric// A convenient way of generating all block peepholes for a particular 1340b57cec5SDimitry Andric// LOAD/VT/LENGTH combination. 1350b57cec5SDimitry Andricmulticlass BlockLoadStore<SDPatternOperator load, ValueType vt, 1360b57cec5SDimitry Andric Instruction mvc, Instruction nc, Instruction oc, 1370b57cec5SDimitry Andric Instruction xc, bits<5> length> { 1380b57cec5SDimitry Andric defm : MVCLoadStore<load, vt, mvc, length>; 1390b57cec5SDimitry Andric defm : BinaryLoadStore<block_and1, load, vt, nc, length>; 1400b57cec5SDimitry Andric defm : BinaryLoadStore<block_and2, load, vt, nc, length>; 1410b57cec5SDimitry Andric defm : BinaryLoadStore<block_or1, load, vt, oc, length>; 1420b57cec5SDimitry Andric defm : BinaryLoadStore<block_or2, load, vt, oc, length>; 1430b57cec5SDimitry Andric defm : BinaryLoadStore<block_xor1, load, vt, xc, length>; 1440b57cec5SDimitry Andric defm : BinaryLoadStore<block_xor2, load, vt, xc, length>; 1450b57cec5SDimitry Andric} 1460b57cec5SDimitry Andric 1470b57cec5SDimitry Andric// Record that INSN is a LOAD AND TEST that can be used to compare 1487a6dacacSDimitry Andric// registers in CLS against zero. 1490b57cec5SDimitry Andricmulticlass CompareZeroFP<Instruction insn, RegisterOperand cls> { 1507a6dacacSDimitry Andric def : Pat<(z_any_fcmp cls:$reg, (fpimm0)), (insn cls:$reg)>; 1510b57cec5SDimitry Andric // The sign of the zero makes no difference. 1527a6dacacSDimitry Andric def : Pat<(z_any_fcmp cls:$reg, (fpimmneg0)), (insn cls:$reg)>; 1530b57cec5SDimitry Andric} 1540b57cec5SDimitry Andric 1550b57cec5SDimitry Andric// Use INSN for performing binary operation OPERATION of type VT 1560b57cec5SDimitry Andric// on registers of class CLS. 1570b57cec5SDimitry Andricclass BinaryRRWithType<Instruction insn, RegisterOperand cls, 1580b57cec5SDimitry Andric SDPatternOperator operator, ValueType vt> 1590b57cec5SDimitry Andric : Pat<(vt (operator cls:$x, cls:$y)), (insn cls:$x, cls:$y)>; 1600b57cec5SDimitry Andric 1610b57cec5SDimitry Andric// Use INSN to perform conversion operation OPERATOR, with the input being 1620b57cec5SDimitry Andric// TR2 and the output being TR1. SUPPRESS is 4 to suppress inexact conditions 1630b57cec5SDimitry Andric// and 0 to allow them. MODE is the rounding mode to use. 1640b57cec5SDimitry Andricclass FPConversion<Instruction insn, SDPatternOperator operator, TypedReg tr1, 1650b57cec5SDimitry Andric TypedReg tr2, bits<3> suppress, bits<4> mode> 1660b57cec5SDimitry Andric : Pat<(tr1.vt (operator (tr2.vt tr2.op:$vec))), 1670b57cec5SDimitry Andric (insn tr2.op:$vec, suppress, mode)>; 1680b57cec5SDimitry Andric 1695ffd83dbSDimitry Andric// Use INSN to perform minimum/maximum operation OPERATOR on type TR. 1700b57cec5SDimitry Andric// FUNCTION is the type of minimum/maximum function to perform. 1710b57cec5SDimitry Andricclass FPMinMax<Instruction insn, SDPatternOperator operator, TypedReg tr, 1720b57cec5SDimitry Andric bits<4> function> 1730b57cec5SDimitry Andric : Pat<(tr.vt (operator (tr.vt tr.op:$vec1), (tr.vt tr.op:$vec2))), 1740b57cec5SDimitry Andric (insn tr.op:$vec1, tr.op:$vec2, function)>; 175