Skip to content

Commit 1afdfc6

Browse files
committed
[RISCV] Rename RISCVISD::GREVI(W)/GORCI(W) to RISCVISD::GREV(W)/GORC(W). Don't require second operand to be a constant.
Prep work for adding intrinsics for these instructions in the future.
1 parent 516d093 commit 1afdfc6

File tree

3 files changed

+69
-65
lines changed

3 files changed

+69
-65
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

+46-43
Original file line numberDiff line numberDiff line change
@@ -1613,8 +1613,8 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op,
16131613
// If this is BSWAP rather than BITREVERSE, clear the lower 3 bits.
16141614
if (Op.getOpcode() == ISD::BSWAP)
16151615
Imm &= ~0x7U;
1616-
return DAG.getNode(RISCVISD::GREVI, DL, VT, Op.getOperand(0),
1617-
DAG.getTargetConstant(Imm, DL, Subtarget.getXLenVT()));
1616+
return DAG.getNode(RISCVISD::GREV, DL, VT, Op.getOperand(0),
1617+
DAG.getConstant(Imm, DL, VT));
16181618
}
16191619
case ISD::FSHL:
16201620
case ISD::FSHR: {
@@ -2898,8 +2898,8 @@ SDValue RISCVTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
28982898
}
28992899
case Intrinsic::riscv_orc_b:
29002900
// Lower to the GORCI encoding for orc.b.
2901-
return DAG.getNode(RISCVISD::GORCI, DL, XLenVT, Op.getOperand(1),
2902-
DAG.getTargetConstant(7, DL, XLenVT));
2901+
return DAG.getNode(RISCVISD::GORC, DL, XLenVT, Op.getOperand(1),
2902+
DAG.getConstant(7, DL, XLenVT));
29032903
case Intrinsic::riscv_vmv_x_s:
29042904
assert(Op.getValueType() == XLenVT && "Unexpected VT!");
29052905
return DAG.getNode(RISCVISD::VMV_X_S, DL, Op.getValueType(),
@@ -4018,10 +4018,10 @@ static RISCVISD::NodeType getRISCVWOpcode(unsigned Opcode) {
40184018
return RISCVISD::ROLW;
40194019
case ISD::ROTR:
40204020
return RISCVISD::RORW;
4021-
case RISCVISD::GREVI:
4022-
return RISCVISD::GREVIW;
4023-
case RISCVISD::GORCI:
4024-
return RISCVISD::GORCIW;
4021+
case RISCVISD::GREV:
4022+
return RISCVISD::GREVW;
4023+
case RISCVISD::GORC:
4024+
return RISCVISD::GORCW;
40254025
}
40264026
}
40274027

@@ -4279,18 +4279,20 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
42794279
}
42804280
break;
42814281
}
4282-
case RISCVISD::GREVI:
4283-
case RISCVISD::GORCI: {
4282+
case RISCVISD::GREV:
4283+
case RISCVISD::GORC: {
42844284
assert(N->getValueType(0) == MVT::i32 && Subtarget.is64Bit() &&
42854285
"Unexpected custom legalisation");
4286+
assert(isa<ConstantSDNode>(N->getOperand(1)) && "Expected constant");
42864287
// This is similar to customLegalizeToWOp, except that we pass the second
42874288
// operand (a TargetConstant) straight through: it is already of type
42884289
// XLenVT.
42894290
RISCVISD::NodeType WOpcode = getRISCVWOpcode(N->getOpcode());
42904291
SDValue NewOp0 =
42914292
DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, N->getOperand(0));
4292-
SDValue NewRes =
4293-
DAG.getNode(WOpcode, DL, MVT::i64, NewOp0, N->getOperand(1));
4293+
SDValue NewOp1 =
4294+
DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, N->getOperand(1));
4295+
SDValue NewRes = DAG.getNode(WOpcode, DL, MVT::i64, NewOp0, NewOp1);
42944296
// ReplaceNodeResults requires we maintain the same type for the return
42954297
// value.
42964298
Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, NewRes));
@@ -4318,9 +4320,8 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
43184320
SDValue NewOp0 = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64,
43194321
N->getOperand(0));
43204322
unsigned Imm = N->getOpcode() == ISD::BITREVERSE ? 31 : 24;
4321-
SDValue GREVIW = DAG.getNode(RISCVISD::GREVIW, DL, MVT::i64, NewOp0,
4322-
DAG.getTargetConstant(Imm, DL,
4323-
Subtarget.getXLenVT()));
4323+
SDValue GREVIW = DAG.getNode(RISCVISD::GREVW, DL, MVT::i64, NewOp0,
4324+
DAG.getConstant(Imm, DL, MVT::i64));
43244325
// ReplaceNodeResults requires we maintain the same type for the return
43254326
// value.
43264327
Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, GREVIW));
@@ -4416,9 +4417,9 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
44164417
DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, N->getOperand(1));
44174418
// If Zbp is enabled, use GORCIW which will sign extend the result.
44184419
unsigned Opc =
4419-
Subtarget.hasStdExtZbp() ? RISCVISD::GORCIW : RISCVISD::GORCI;
4420+
Subtarget.hasStdExtZbp() ? RISCVISD::GORCW : RISCVISD::GORC;
44204421
SDValue Res = DAG.getNode(Opc, DL, MVT::i64, NewOp,
4421-
DAG.getTargetConstant(7, DL, MVT::i64));
4422+
DAG.getConstant(7, DL, MVT::i64));
44224423
Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, Res));
44234424
return;
44244425
}
@@ -4599,9 +4600,8 @@ static SDValue combineORToGREV(SDValue Op, SelectionDAG &DAG,
45994600
auto RHS = matchGREVIPat(Op.getOperand(1));
46004601
if (LHS && RHS && LHS->formsPairWith(*RHS)) {
46014602
SDLoc DL(Op);
4602-
return DAG.getNode(
4603-
RISCVISD::GREVI, DL, VT, LHS->Op,
4604-
DAG.getTargetConstant(LHS->ShAmt, DL, Subtarget.getXLenVT()));
4603+
return DAG.getNode(RISCVISD::GREV, DL, VT, LHS->Op,
4604+
DAG.getConstant(LHS->ShAmt, DL, VT));
46054605
}
46064606
}
46074607
return SDValue();
@@ -4627,19 +4627,19 @@ static SDValue combineORToGORC(SDValue Op, SelectionDAG &DAG,
46274627
SDValue Op1 = Op.getOperand(1);
46284628

46294629
auto MatchOROfReverse = [&](SDValue Reverse, SDValue X) {
4630-
if (Reverse.getOpcode() == RISCVISD::GREVI && Reverse.getOperand(0) == X &&
4630+
if (Reverse.getOpcode() == RISCVISD::GREV && Reverse.getOperand(0) == X &&
4631+
isa<ConstantSDNode>(Reverse.getOperand(1)) &&
46314632
isPowerOf2_32(Reverse.getConstantOperandVal(1)))
4632-
return DAG.getNode(RISCVISD::GORCI, DL, VT, X, Reverse.getOperand(1));
4633+
return DAG.getNode(RISCVISD::GORC, DL, VT, X, Reverse.getOperand(1));
46334634
// We can also form GORCI from ROTL/ROTR by half the bitwidth.
46344635
if ((Reverse.getOpcode() == ISD::ROTL ||
46354636
Reverse.getOpcode() == ISD::ROTR) &&
46364637
Reverse.getOperand(0) == X &&
46374638
isa<ConstantSDNode>(Reverse.getOperand(1))) {
46384639
uint64_t RotAmt = Reverse.getConstantOperandVal(1);
46394640
if (RotAmt == (VT.getSizeInBits() / 2))
4640-
return DAG.getNode(
4641-
RISCVISD::GORCI, DL, VT, X,
4642-
DAG.getTargetConstant(RotAmt, DL, Subtarget.getXLenVT()));
4641+
return DAG.getNode(RISCVISD::GORC, DL, VT, X,
4642+
DAG.getConstant(RotAmt, DL, VT));
46434643
}
46444644
return SDValue();
46454645
};
@@ -4666,9 +4666,8 @@ static SDValue combineORToGORC(SDValue Op, SelectionDAG &DAG,
46664666
}
46674667
auto RHS = matchGREVIPat(Op1);
46684668
if (LHS && RHS && LHS->formsPairWith(*RHS) && LHS->Op == OrOp1) {
4669-
return DAG.getNode(
4670-
RISCVISD::GORCI, DL, VT, LHS->Op,
4671-
DAG.getTargetConstant(LHS->ShAmt, DL, Subtarget.getXLenVT()));
4669+
return DAG.getNode(RISCVISD::GORC, DL, VT, LHS->Op,
4670+
DAG.getConstant(LHS->ShAmt, DL, VT));
46724671
}
46734672
}
46744673
return SDValue();
@@ -4774,17 +4773,21 @@ static SDValue combineORToSHFL(SDValue Op, SelectionDAG &DAG,
47744773
// Combine (GORCI (GORCI x, C2), C1) -> (GORCI x, C1|C2). Repeated stage does
47754774
// not undo itself, but they are redundant.
47764775
static SDValue combineGREVI_GORCI(SDNode *N, SelectionDAG &DAG) {
4777-
unsigned ShAmt1 = N->getConstantOperandVal(1);
47784776
SDValue Src = N->getOperand(0);
47794777

47804778
if (Src.getOpcode() != N->getOpcode())
47814779
return SDValue();
47824780

4781+
if (!isa<ConstantSDNode>(N->getOperand(1)) ||
4782+
!isa<ConstantSDNode>(Src.getOperand(1)))
4783+
return SDValue();
4784+
4785+
unsigned ShAmt1 = N->getConstantOperandVal(1);
47834786
unsigned ShAmt2 = Src.getConstantOperandVal(1);
47844787
Src = Src.getOperand(0);
47854788

47864789
unsigned CombinedShAmt;
4787-
if (N->getOpcode() == RISCVISD::GORCI || N->getOpcode() == RISCVISD::GORCIW)
4790+
if (N->getOpcode() == RISCVISD::GORC || N->getOpcode() == RISCVISD::GORCW)
47884791
CombinedShAmt = ShAmt1 | ShAmt2;
47894792
else
47904793
CombinedShAmt = ShAmt1 ^ ShAmt2;
@@ -4793,9 +4796,9 @@ static SDValue combineGREVI_GORCI(SDNode *N, SelectionDAG &DAG) {
47934796
return Src;
47944797

47954798
SDLoc DL(N);
4796-
return DAG.getNode(N->getOpcode(), DL, N->getValueType(0), Src,
4797-
DAG.getTargetConstant(CombinedShAmt, DL,
4798-
N->getOperand(1).getValueType()));
4799+
return DAG.getNode(
4800+
N->getOpcode(), DL, N->getValueType(0), Src,
4801+
DAG.getConstant(CombinedShAmt, DL, N->getOperand(1).getValueType()));
47994802
}
48004803

48014804
SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
@@ -4909,8 +4912,8 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
49094912
}
49104913
break;
49114914
}
4912-
case RISCVISD::GREVIW:
4913-
case RISCVISD::GORCIW: {
4915+
case RISCVISD::GREVW:
4916+
case RISCVISD::GORCW: {
49144917
// Only the lower 32 bits of the first operand are read
49154918
SDValue Op0 = N->getOperand(0);
49164919
APInt Mask = APInt::getLowBitsSet(Op0.getValueSizeInBits(), 32);
@@ -4952,8 +4955,8 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
49524955
return DAG.getNode(ISD::AND, DL, MVT::i64, NewFMV,
49534956
DAG.getConstant(~SignBit, DL, MVT::i64));
49544957
}
4955-
case RISCVISD::GREVI:
4956-
case RISCVISD::GORCI:
4958+
case RISCVISD::GREV:
4959+
case RISCVISD::GORC:
49574960
return combineGREVI_GORCI(N, DCI.DAG);
49584961
case ISD::OR:
49594962
if (auto GREV = combineORToGREV(SDValue(N, 0), DCI.DAG, Subtarget))
@@ -5360,8 +5363,8 @@ unsigned RISCVTargetLowering::ComputeNumSignBitsForTargetNode(
53605363
case RISCVISD::REMUW:
53615364
case RISCVISD::ROLW:
53625365
case RISCVISD::RORW:
5363-
case RISCVISD::GREVIW:
5364-
case RISCVISD::GORCIW:
5366+
case RISCVISD::GREVW:
5367+
case RISCVISD::GORCW:
53655368
case RISCVISD::FSLW:
53665369
case RISCVISD::FSRW:
53675370
// TODO: As the result is sign-extended, this is conservatively correct. A
@@ -7105,10 +7108,10 @@ const char *RISCVTargetLowering::getTargetNodeName(unsigned Opcode) const {
71057108
NODE_NAME_CASE(FMV_W_X_RV64)
71067109
NODE_NAME_CASE(FMV_X_ANYEXTW_RV64)
71077110
NODE_NAME_CASE(READ_CYCLE_WIDE)
7108-
NODE_NAME_CASE(GREVI)
7109-
NODE_NAME_CASE(GREVIW)
7110-
NODE_NAME_CASE(GORCI)
7111-
NODE_NAME_CASE(GORCIW)
7111+
NODE_NAME_CASE(GREV)
7112+
NODE_NAME_CASE(GREVW)
7113+
NODE_NAME_CASE(GORC)
7114+
NODE_NAME_CASE(GORCW)
71127115
NODE_NAME_CASE(SHFL)
71137116
NODE_NAME_CASE(VMV_V_X_VL)
71147117
NODE_NAME_CASE(VFMV_V_F_VL)

llvm/lib/Target/RISCV/RISCVISelLowering.h

+6-7
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,12 @@ enum NodeType : unsigned {
8989
// Generalized Reverse and Generalized Or-Combine - directly matching the
9090
// semantics of the named RISC-V instructions. Lowered as custom nodes as
9191
// TableGen chokes when faced with commutative permutations in deeply-nested
92-
// DAGs. Each node takes an input operand and a TargetConstant immediate
93-
// shift amount, and outputs a bit-manipulated version of input. All operands
94-
// are of type XLenVT.
95-
GREVI,
96-
GREVIW,
97-
GORCI,
98-
GORCIW,
92+
// DAGs. Each node takes an input operand and a control operand and outputs a
93+
// bit-manipulated version of input. All operands are i32 or XLenVT.
94+
GREV,
95+
GREVW,
96+
GORC,
97+
GORCW,
9998
SHFL,
10099
// Vector Extension
101100
// VMV_V_X_VL matches the semantics of vmv.v.x but includes an extra operand

llvm/lib/Target/RISCV/RISCVInstrInfoB.td

+17-15
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ def riscv_fslw : SDNode<"RISCVISD::FSLW", SDT_RISCVIntShiftDOpW>;
2525
def riscv_fsrw : SDNode<"RISCVISD::FSRW", SDT_RISCVIntShiftDOpW>;
2626
def riscv_fsl : SDNode<"RISCVISD::FSL", SDTIntShiftDOp>;
2727
def riscv_fsr : SDNode<"RISCVISD::FSR", SDTIntShiftDOp>;
28-
def riscv_grevi : SDNode<"RISCVISD::GREVI", SDTIntBinOp>;
29-
def riscv_greviw : SDNode<"RISCVISD::GREVIW", SDT_RISCVIntBinOpW>;
30-
def riscv_gorci : SDNode<"RISCVISD::GORCI", SDTIntBinOp>;
31-
def riscv_gorciw : SDNode<"RISCVISD::GORCIW", SDT_RISCVIntBinOpW>;
28+
def riscv_grev : SDNode<"RISCVISD::GREV", SDTIntBinOp>;
29+
def riscv_grevw : SDNode<"RISCVISD::GREVW", SDT_RISCVIntBinOpW>;
30+
def riscv_gorc : SDNode<"RISCVISD::GORC", SDTIntBinOp>;
31+
def riscv_gorcw : SDNode<"RISCVISD::GORCW", SDT_RISCVIntBinOpW>;
3232
def riscv_shfl : SDNode<"RISCVISD::SHFL", SDTIntBinOp>;
3333

3434
def UImmLog2XLenHalfAsmOperand : AsmOperandClass {
@@ -719,27 +719,29 @@ def : Pat<(rotl GPR:$rs1, uimmlog2xlen:$shamt),
719719

720720
// We treat orc.b as a separate instruction, so match it directly. We also
721721
// lower the Zbb orc.b intrinsic to this.
722-
def : Pat<(riscv_gorci GPR:$rs1, 7), (ORCB GPR:$rs1)>;
722+
def : Pat<(riscv_gorc GPR:$rs1, 7), (ORCB GPR:$rs1)>;
723723
}
724724

725725
let Predicates = [HasStdExtZbp] in {
726726
def : Pat<(riscv_shfl GPR:$rs1, shfl_uimm:$shamt),
727727
(SHFLI GPR:$rs1, shfl_uimm:$shamt)>;
728-
def : Pat<(riscv_grevi GPR:$rs1, timm:$shamt), (GREVI GPR:$rs1, timm:$shamt)>;
729-
def : Pat<(riscv_gorci GPR:$rs1, timm:$shamt), (GORCI GPR:$rs1, timm:$shamt)>;
728+
def : Pat<(riscv_grev GPR:$rs1, uimmlog2xlen:$shamt),
729+
(GREVI GPR:$rs1, uimmlog2xlen:$shamt)>;
730+
def : Pat<(riscv_gorc GPR:$rs1, uimmlog2xlen:$shamt),
731+
(GORCI GPR:$rs1, uimmlog2xlen:$shamt)>;
730732
} // Predicates = [HasStdExtZbp]
731733

732734
let Predicates = [HasStdExtZbp, IsRV32] in {
733-
def : Pat<(i32 (rotr (riscv_grevi GPR:$rs1, 24), (i32 16))), (GREVI GPR:$rs1, 8)>;
734-
def : Pat<(i32 (rotl (riscv_grevi GPR:$rs1, 24), (i32 16))), (GREVI GPR:$rs1, 8)>;
735+
def : Pat<(i32 (rotr (riscv_grev GPR:$rs1, 24), (i32 16))), (GREVI GPR:$rs1, 8)>;
736+
def : Pat<(i32 (rotl (riscv_grev GPR:$rs1, 24), (i32 16))), (GREVI GPR:$rs1, 8)>;
735737

736738
// We treat rev8 as a separate instruction, so match it directly.
737-
def : Pat<(i32 (riscv_grevi GPR:$rs1, 24)), (REV8_RV32 GPR:$rs1)>;
739+
def : Pat<(i32 (riscv_grev GPR:$rs1, 24)), (REV8_RV32 GPR:$rs1)>;
738740
} // Predicates = [HasStdExtZbp, IsRV32]
739741

740742
let Predicates = [HasStdExtZbp, IsRV64] in {
741743
// We treat rev8 as a separate instruction, so match it directly.
742-
def : Pat<(i64 (riscv_grevi GPR:$rs1, 56)), (REV8_RV64 GPR:$rs1)>;
744+
def : Pat<(i64 (riscv_grev GPR:$rs1, 56)), (REV8_RV64 GPR:$rs1)>;
743745
} // Predicates = [HasStdExtZbp, IsRV64]
744746

745747
let Predicates = [HasStdExtZbt] in {
@@ -883,10 +885,10 @@ def : Pat<(riscv_rolw GPR:$rs1, uimm5:$rs2),
883885
} // Predicates = [HasStdExtZbbOrZbp, IsRV64]
884886

885887
let Predicates = [HasStdExtZbp, IsRV64] in {
886-
def : Pat<(riscv_rorw (riscv_greviw GPR:$rs1, 24), 16), (GREVIW GPR:$rs1, 8)>;
887-
def : Pat<(riscv_rolw (riscv_greviw GPR:$rs1, 24), 16), (GREVIW GPR:$rs1, 8)>;
888-
def : Pat<(riscv_greviw GPR:$rs1, timm:$shamt), (GREVIW GPR:$rs1, timm:$shamt)>;
889-
def : Pat<(riscv_gorciw GPR:$rs1, timm:$shamt), (GORCIW GPR:$rs1, timm:$shamt)>;
888+
def : Pat<(riscv_rorw (riscv_grevw GPR:$rs1, 24), 16), (GREVIW GPR:$rs1, 8)>;
889+
def : Pat<(riscv_rolw (riscv_grevw GPR:$rs1, 24), 16), (GREVIW GPR:$rs1, 8)>;
890+
def : Pat<(riscv_grevw GPR:$rs1, uimm5:$shamt), (GREVIW GPR:$rs1, uimm5:$shamt)>;
891+
def : Pat<(riscv_gorcw GPR:$rs1, uimm5:$shamt), (GORCIW GPR:$rs1, uimm5:$shamt)>;
890892
} // Predicates = [HasStdExtZbp, IsRV64]
891893

892894
let Predicates = [HasStdExtZbt, IsRV64] in {

0 commit comments

Comments
 (0)