From 524545317c8d7ba049e7a91d8fa7a131f506e2b5 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sat, 29 Jan 2022 22:19:15 -0800 Subject: [PATCH] [RISCV] Remove RISCVISD::BREV8 and use RISCVISD::GREV instead. We already have an ISD opcode for the more general GREV/GREVI instructon. We can just use it with the encoding that corresponds to the behavior of brev8. This is similar to what we do for orc.b where we use the GORC ISD opcode. --- llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 6 ++++-- llvm/lib/Target/RISCV/RISCVISelLowering.h | 2 -- llvm/lib/Target/RISCV/RISCVInstrInfoZb.td | 11 ++++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp index 9d1bd7b..54b909e 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -2974,7 +2974,10 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op, assert(Op.getOpcode() == ISD::BITREVERSE && "Unexpected opcode"); // Expand bitreverse to a bswap(rev8) followed by brev8. SDValue BSwap = DAG.getNode(ISD::BSWAP, DL, VT, Op.getOperand(0)); - return DAG.getNode(RISCVISD::BREV8, DL, VT, BSwap); + // We use the Zbp grevi encoding for rev.b/brev8 which will be recognized + // as brev8 by an isel pattern. + return DAG.getNode(RISCVISD::GREV, DL, VT, BSwap, + DAG.getConstant(7, DL, VT)); } case ISD::FSHL: case ISD::FSHR: { @@ -10106,7 +10109,6 @@ const char *RISCVTargetLowering::getTargetNodeName(unsigned Opcode) const { NODE_NAME_CASE(STRICT_FCVT_W_RV64) NODE_NAME_CASE(STRICT_FCVT_WU_RV64) NODE_NAME_CASE(READ_CYCLE_WIDE) - NODE_NAME_CASE(BREV8) NODE_NAME_CASE(GREV) NODE_NAME_CASE(GREVW) NODE_NAME_CASE(GORC) diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.h b/llvm/lib/Target/RISCV/RISCVISelLowering.h index 74988a0..840a821 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.h +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.h @@ -99,8 +99,6 @@ enum NodeType : unsigned { // READ_CYCLE_WIDE - A read of the 64-bit cycle CSR on a 32-bit target // (returns (Lo, Hi)). It takes a chain operand. READ_CYCLE_WIDE, - // Reverse bits in each byte. - BREV8, // Generalized Reverse and Generalized Or-Combine - directly matching the // semantics of the named RISC-V instructions. Lowered as custom nodes as // TableGen chokes when faced with commutative permutations in deeply-nested diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td index 32f1f34..c60f31a 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td @@ -43,7 +43,6 @@ def riscv_fslw : SDNode<"RISCVISD::FSLW", SDT_RISCVIntShiftDOpW>; def riscv_fsrw : SDNode<"RISCVISD::FSRW", SDT_RISCVIntShiftDOpW>; def riscv_fsl : SDNode<"RISCVISD::FSL", SDTIntShiftDOp>; def riscv_fsr : SDNode<"RISCVISD::FSR", SDTIntShiftDOp>; -def riscv_brev8 : SDNode<"RISCVISD::BREV8", SDTIntUnaryOp>; def riscv_grev : SDNode<"RISCVISD::GREV", SDTIntBinOp>; def riscv_grevw : SDNode<"RISCVISD::GREVW", SDT_RISCVIntBinOpW>; def riscv_gorc : SDNode<"RISCVISD::GORC", SDTIntBinOp>; @@ -852,15 +851,18 @@ let Predicates = [HasStdExtZbbOrZbp] in { def : Pat<(riscv_gorc GPR:$rs1, 7), (ORC_B GPR:$rs1)>; } +let Predicates = [HasStdExtZbpOrZbkb] in { +// We treat brev8 as a separate instruction, so match it directly. We also +// use this for brev8 when lowering bitreverse with Zbkb. +def : Pat<(riscv_grev GPR:$rs1, 7), (BREV8 GPR:$rs1)>; +} + let Predicates = [HasStdExtZbp] in { def : PatGprGpr; def : PatGprGpr; def : PatGprImm; def : PatGprImm; -// We treat brev8 as a separate instruction, so match it directly. -def : Pat<(riscv_grev GPR:$rs1, 7), (BREV8 GPR:$rs1)>; - def : PatGprGpr; def : PatGprGpr; def : PatGprImm; @@ -1171,7 +1173,6 @@ let Predicates = [HasStdExtZbf, IsRV64] in def : PatGprGpr; let Predicates = [HasStdExtZbkb] in { -def : PatGpr; def : PatGpr; } // Predicates = [HasStdExtZbkb] -- 2.7.4