//===-- RISCVGIsel.td - RISC-V GlobalISel Patterns ---------*- tablegen -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // /// \file /// This file contains patterns that are relevant to GlobalISel, including /// GIComplexOperandMatcher definitions for equivalent SelectionDAG /// ComplexPatterns. // //===----------------------------------------------------------------------===// include "RISCV.td" include "RISCVCombine.td" def simm12Plus1 : ImmLeaf= -2047 && Imm <= 2048;}]>; def simm12Plus1i32 : ImmLeaf= -2047 && Imm <= 2048;}]>; // FIXME: This doesn't check that the G_CONSTANT we're deriving the immediate // from is only used once def simm12Minus1Nonzero : ImmLeaf= -2049 && Imm <= 2046 && Imm != 0;}]>; def simm12Minus1NonzeroNonNeg1 : ImmLeaf= -2049 && Imm < -1) || (Imm > 0 && Imm <= 2046);}]>; // Return an immediate value plus 1. def ImmPlus1 : SDNodeXFormgetTargetConstant(N->getSExtValue() + 1, SDLoc(N), N->getValueType(0));}]>; def GIImmPlus1 : GICustomOperandRenderer<"renderImmPlus1">, GISDNodeXFormEquiv; // Ptr type used in patterns with GlobalISelEmitter def PtrVT : PtrValueTypeByHwMode; // Define pattern expansions for pointer ult/slt conditional codes def : Pat<(XLenVT (setult (PtrVT GPR:$rs1), simm12_lo:$imm12)), (SLTIU GPR:$rs1, simm12_lo:$imm12)>; def : Pat<(XLenVT (setult (PtrVT GPR:$rs1), (PtrVT GPR:$rs2))), (SLTU GPR:$rs1, GPR:$rs2)>; def : Pat<(XLenVT (setlt (PtrVT GPR:$rs1), simm12_lo:$imm12)), (SLTI GPR:$rs1, simm12_lo:$imm12)>; def : Pat<(XLenVT (setlt (PtrVT GPR:$rs1), (PtrVT GPR:$rs2))), (SLT GPR:$rs1, GPR:$rs2)>; // Define pattern expansions for setcc operations that aren't directly // handled by a RISC-V instruction. foreach Ty = [PtrVT, XLenVT] in { def : Pat<(XLenVT (seteq (Ty GPR:$rs1), (Ty 0))), (SLTIU GPR:$rs1, 1)>; def : Pat<(XLenVT (seteq (Ty GPR:$rs1), (Ty simm12Plus1:$imm12))), (SLTIU (ADDI GPR:$rs1, (NegImm simm12Plus1:$imm12)), 1)>; def : Pat<(XLenVT (seteq (Ty GPR:$rs1), (Ty GPR:$rs2))), (SLTIU (XOR GPR:$rs1, GPR:$rs2), 1)>; def : Pat<(XLenVT (setne (Ty GPR:$rs1), (Ty 0))), (SLTU (XLenVT X0), GPR:$rs1)>; def : Pat<(XLenVT (setne (Ty GPR:$rs1), (Ty simm12Plus1:$imm12))), (SLTU (XLenVT X0), (ADDI GPR:$rs1, (NegImm simm12Plus1:$imm12)))>; def : Pat<(XLenVT (setne (Ty GPR:$rs1), (Ty GPR:$rs2))), (SLTU (XLenVT X0), (XOR GPR:$rs1, GPR:$rs2))>; def : Pat<(XLenVT (setugt (Ty GPR:$rs1), (Ty simm12Minus1NonzeroNonNeg1:$imm))), (XORI (SLTIU GPR:$rs1, (ImmPlus1 simm12Minus1NonzeroNonNeg1:$imm)), 1)>; def : Pat<(XLenVT (setugt (Ty GPR:$rs1), (Ty GPR:$rs2))), (SLTU GPR:$rs2, GPR:$rs1)>; def : Pat<(XLenVT (setgt (Ty GPR:$rs1), (Ty simm12Minus1Nonzero:$imm))), (XORI (SLTI GPR:$rs1, (ImmPlus1 simm12Minus1Nonzero:$imm)), 1)>; def : Pat<(XLenVT (setgt (Ty GPR:$rs1), (Ty GPR:$rs2))), (SLT GPR:$rs2, GPR:$rs1)>; def : Pat<(XLenVT (setuge (XLenVT GPR:$rs1), (Ty simm12_lo:$imm))), (XORI (SLTIU GPR:$rs1, simm12_lo:$imm), 1)>; def : Pat<(XLenVT (setuge (Ty GPR:$rs1), (Ty GPR:$rs2))), (XORI (SLTU GPR:$rs1, GPR:$rs2), 1)>; def : Pat<(XLenVT (setge (Ty GPR:$rs1), (Ty simm12_lo:$imm))), (XORI (SLTI GPR:$rs1, simm12_lo:$imm), 1)>; def : Pat<(XLenVT (setge (Ty GPR:$rs1), (Ty GPR:$rs2))), (XORI (SLT GPR:$rs1, GPR:$rs2), 1)>; def : Pat<(XLenVT (setule (Ty GPR:$rs1), (Ty simm12Minus1NonzeroNonNeg1:$imm))), (SLTIU GPR:$rs1, (ImmPlus1 simm12Minus1NonzeroNonNeg1:$imm))>; def : Pat<(XLenVT (setule (Ty GPR:$rs1), (Ty GPR:$rs2))), (XORI (SLTU GPR:$rs2, GPR:$rs1), 1)>; def : Pat<(XLenVT (setle (Ty GPR:$rs1), (Ty simm12Minus1Nonzero:$imm))), (SLTI GPR:$rs1, (ImmPlus1 simm12Minus1Nonzero:$imm))>; def : Pat<(XLenVT (setle (Ty GPR:$rs1), (Ty GPR:$rs2))), (XORI (SLT GPR:$rs2, GPR:$rs1), 1)>; } let Predicates = [IsRV32] in { def : LdPat; def : StPat; } let Predicates = [IsRV64] in { def : LdPat; def : StPat; } //===----------------------------------------------------------------------===// // RV64 i32 patterns not used by SelectionDAG //===----------------------------------------------------------------------===// let Predicates = [IsRV64] in { def : Pat<(sext_inreg (i64 (add GPR:$rs1, simm12_lo:$imm)), i32), (ADDIW GPR:$rs1, simm12_lo:$imm)>; }