From 90e9e946ca16fc945ea18cbc61bd1f53c50dce46 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Thu, 12 Dec 2024 09:36:09 -0800 Subject: [PATCH] [RISCV] Move GIComplexOperandMatcher and GICustomOperandRenderer next to their SelectionDAG equivalents. NFC This makes it easier to see if the SelectionDAG node has an equivalent without needing to check another file. Putting them in the same file helps associate them with the relevant ISA and any additional context that may be provided by comments. Naming is a little messy because we inconsistently use camel case and snake case in the SelectionDAG node names. Thus the GISel node names are named the same as the SelectionDAG node name with either GI or gi_ as a prefix. --- llvm/lib/Target/RISCV/RISCVGISel.td | 60 ------------------- llvm/lib/Target/RISCV/RISCVInstrInfo.td | 35 +++++++++++ .../Target/RISCV/RISCVInstrInfoVPseudos.td | 7 +++ llvm/lib/Target/RISCV/RISCVInstrInfoZb.td | 13 ++++ 4 files changed, 55 insertions(+), 60 deletions(-) diff --git a/llvm/lib/Target/RISCV/RISCVGISel.td b/llvm/lib/Target/RISCV/RISCVGISel.td index f9c17cf5eed5d..5045e5eaa9408 100644 --- a/llvm/lib/Target/RISCV/RISCVGISel.td +++ b/llvm/lib/Target/RISCV/RISCVGISel.td @@ -33,70 +33,10 @@ def simm12Minus1NonzeroNonNeg1 : ImmLeafgetTargetConstant(N->getSExtValue() + 1, SDLoc(N), N->getValuePtrVTpe(0));}]>; - -def GINegImm : GICustomOperandRenderer<"renderNegImm">, - GISDNodeXFormEquiv; - -def GIImmSubFromXLen : GICustomOperandRenderer<"renderImmSubFromXLen">, - GISDNodeXFormEquiv; -def GIImmSubFrom32 : GICustomOperandRenderer<"renderImmSubFrom32">, - GISDNodeXFormEquiv; - def GIImmPlus1 : GICustomOperandRenderer<"renderImmPlus1">, GISDNodeXFormEquiv; -def GIAddrRegImm : - GIComplexOperandMatcher, - GIComplexPatternEquiv; - -// FIXME: This is labelled as handling 's32', however the ComplexPattern it -// refers to handles both i32 and i64 based on the HwMode. Currently this LLT -// parameter appears to be ignored so this pattern works for both, however we -// should add a LowLevelTypeByHwMode, and use that to define our XLenLLT instead -// here. -def GIVLOp : GIComplexOperandMatcher, - GIComplexPatternEquiv; - -def gi_trailing_zero : GICustomOperandRenderer<"renderTrailingZeros">, - GISDNodeXFormEquiv; - -// FIXME: This is labelled as handling 's32', however the ComplexPattern it -// refers to handles both i32 and i64 based on the HwMode. Currently this LLT -// parameter appears to be ignored so this pattern works for both, however we -// should add a LowLevelTypeByHwMode, and use that to define our XLenLLT instead -// here. -def GIShiftMaskXLen : - GIComplexOperandMatcher, - GIComplexPatternEquiv; -def GIShiftMask32 : - GIComplexOperandMatcher, - GIComplexPatternEquiv; - -def gi_sh1add_op : GIComplexOperandMatcher">, - GIComplexPatternEquiv; -def gi_sh2add_op : GIComplexOperandMatcher">, - GIComplexPatternEquiv; -def gi_sh3add_op : GIComplexOperandMatcher">, - GIComplexPatternEquiv; - -def gi_sh1add_uw_op : GIComplexOperandMatcher">, - GIComplexPatternEquiv; -def gi_sh2add_uw_op : GIComplexOperandMatcher">, - GIComplexPatternEquiv; -def gi_sh3add_uw_op : GIComplexOperandMatcher">, - GIComplexPatternEquiv; - -def gi_sexti32 : GIComplexOperandMatcher">, - GIComplexPatternEquiv; - -def gi_zexti32 : GIComplexOperandMatcher">, - GIComplexPatternEquiv; -def gi_zexti16 : GIComplexOperandMatcher">, - GIComplexPatternEquiv; -def gi_zexti8 : GIComplexOperandMatcher">, - GIComplexPatternEquiv; - // Ptr type used in patterns with GlobalISelEmitter def PtrVT : PtrValueTypeByHwMode; diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td index 78682f2609dba..2f0d9de42b486 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td @@ -418,6 +418,8 @@ def NegImm : SDNodeXFormgetSignedTargetConstant(-N->getSExtValue(), SDLoc(N), N->getValueType(0)); }]>; +def GINegImm : GICustomOperandRenderer<"renderNegImm">, + GISDNodeXFormEquiv; // Return an immediate value minus 32. def ImmSub32 : SDNodeXFormgetTargetConstant(XLen - N->getZExtValue(), SDLoc(N), N->getValueType(0)); }]>; +def GIImmSubFromXLen : GICustomOperandRenderer<"renderImmSubFromXLen">, + GISDNodeXFormEquiv; // Return an immediate subtracted from 32. def ImmSubFrom32 : SDNodeXFormgetTargetConstant(32 - N->getZExtValue(), SDLoc(N), N->getValueType(0)); }]>; +def GIImmSubFrom32 : GICustomOperandRenderer<"renderImmSubFrom32">, + GISDNodeXFormEquiv; // Check if (add r, imm) can be optimized to (ADDI (ADDI r, imm0), imm1), // in which imm = imm0 + imm1 and both imm0 and imm1 are simm12. We make imm0 @@ -469,6 +475,8 @@ def TrailingZeros : SDNodeXFormgetTargetConstant(llvm::countr_zero(N->getZExtValue()), SDLoc(N), N->getValueType(0)); }]>; +def GITrailingZeros : GICustomOperandRenderer<"renderTrailingZeros">, + GISDNodeXFormEquiv; def XLenSubTrailingOnes : SDNodeXFormgetXLen(); @@ -1267,13 +1275,26 @@ def assertsexti32 : PatFrag<(ops node:$src), (assertsext node:$src), [{ return cast(N->getOperand(1))->getVT().bitsLE(MVT::i32); }]>; def sexti16 : ComplexPattern">; + def sexti32 : ComplexPattern">; +def gi_sexti32 : GIComplexOperandMatcher">, + GIComplexPatternEquiv; + def assertzexti32 : PatFrag<(ops node:$src), (assertzext node:$src), [{ return cast(N->getOperand(1))->getVT().bitsLE(MVT::i32); }]>; + def zexti32 : ComplexPattern">; +def gi_zexti32 : GIComplexOperandMatcher">, + GIComplexPatternEquiv; + def zexti16 : ComplexPattern">; +def gi_zexti16 : GIComplexOperandMatcher">, + GIComplexPatternEquiv; + def zexti8 : ComplexPattern">; +def gi_zexti8 : GIComplexOperandMatcher">, + GIComplexPatternEquiv; def ext : PatFrags<(ops node:$A), [(sext node:$A), (zext node:$A)]>; @@ -1357,6 +1378,17 @@ def : Pat<(XLenVT (and GPR:$rs, TrailingOnesMask:$mask)), // ISA only read the least significant 5 bits (RV32I) or 6 bits (RV64I). def shiftMaskXLen : ComplexPattern; def shiftMask32 : ComplexPattern; +// FIXME: This is labelled as handling 's32', however the ComplexPattern it +// refers to handles both i32 and i64 based on the HwMode. Currently this LLT +// parameter appears to be ignored so this pattern works for both, however we +// should add a LowLevelTypeByHwMode, and use that to define our XLenLLT instead +// here. +def GIShiftMaskXLen : + GIComplexOperandMatcher, + GIComplexPatternEquiv; +def GIShiftMask32 : + GIComplexOperandMatcher, + GIComplexPatternEquiv; class shiftop : PatFrag<(ops node:$val, node:$count), @@ -1382,6 +1414,9 @@ def PseudoAddTPRel : Pseudo<(outs GPR:$rd), def : Pat<(FrameAddrRegImm (iPTR GPR:$rs1), simm12:$imm12), (ADDI GPR:$rs1, simm12:$imm12)>; +def GIAddrRegImm : + GIComplexOperandMatcher, + GIComplexPatternEquiv; /// Stack probing diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td index 6c4e41711440e..d4770de44aef4 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td @@ -102,6 +102,13 @@ def vec_rm : RISCVOp { // !X0 | X0 | VLMAX | Set vl to VLMAX // X0 | X0 | Value in vl | Keep current vl, just change vtype. def VLOp : ComplexPattern; +// FIXME: This is labelled as handling 's32', however the ComplexPattern it +// refers to handles both i32 and i64 based on the HwMode. Currently this LLT +// parameter appears to be ignored so this pattern works for both, however we +// should add a LowLevelTypeByHwMode, and use that to define our XLenLLT instead +// here. +def GIVLOp : GIComplexOperandMatcher, + GIComplexPatternEquiv; def DecImm : SDNodeXFormgetSignedTargetConstant(N->getSExtValue() - 1, SDLoc(N), diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td index 8cefceab43e56..a78091cd02a35 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td @@ -213,10 +213,23 @@ def Shifted32OnesMask : IntImmLeaf", [], [], 6>; def sh2add_op : ComplexPattern", [], [], 6>; def sh3add_op : ComplexPattern", [], [], 6>; +def gi_sh1add_op : GIComplexOperandMatcher">, + GIComplexPatternEquiv; +def gi_sh2add_op : GIComplexOperandMatcher">, + GIComplexPatternEquiv; +def gi_sh3add_op : GIComplexOperandMatcher">, + GIComplexPatternEquiv; + def sh1add_uw_op : ComplexPattern", [], [], 6>; def sh2add_uw_op : ComplexPattern", [], [], 6>; def sh3add_uw_op : ComplexPattern", [], [], 6>; +def gi_sh1add_uw_op : GIComplexOperandMatcher">, + GIComplexPatternEquiv; +def gi_sh2add_uw_op : GIComplexOperandMatcher">, + GIComplexPatternEquiv; +def gi_sh3add_uw_op : GIComplexOperandMatcher">, + GIComplexPatternEquiv; //===----------------------------------------------------------------------===// // Instruction class templates