Skip to content

Commit 98d5db3

Browse files
committed
[RISCV] Lower orc.b intrinsic to RISCVISD::GORCI.
This will allow us to share any future known bits, demaned bits, or sign bits improvements.
1 parent 292726b commit 98d5db3

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2810,6 +2810,10 @@ SDValue RISCVTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
28102810
EVT PtrVT = getPointerTy(DAG.getDataLayout());
28112811
return DAG.getRegister(RISCV::X4, PtrVT);
28122812
}
2813+
case Intrinsic::riscv_orc_b:
2814+
// Lower to the GORCI encoding for orc.b.
2815+
return DAG.getNode(RISCVISD::GORCI, DL, XLenVT, Op.getOperand(1),
2816+
DAG.getTargetConstant(7, DL, XLenVT));
28132817
case Intrinsic::riscv_vmv_x_s:
28142818
assert(Op.getValueType() == XLenVT && "Unexpected VT!");
28152819
return DAG.getNode(RISCVISD::VMV_X_S, DL, Op.getValueType(),
@@ -4204,10 +4208,11 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
42044208
llvm_unreachable(
42054209
"Don't know how to custom type legalize this intrinsic!");
42064210
case Intrinsic::riscv_orc_b: {
4207-
SDValue Newop1 =
4211+
// Lower to the GORCI encoding for orc.b with the operand extended.
4212+
SDValue NewOp =
42084213
DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, N->getOperand(1));
4209-
SDValue Res =
4210-
DAG.getNode(N->getOpcode(), DL, MVT::i64, N->getOperand(0), Newop1);
4214+
SDValue Res = DAG.getNode(RISCVISD::GORCI, DL, MVT::i64, NewOp,
4215+
DAG.getTargetConstant(7, DL, MVT::i64));
42114216
Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, Res));
42124217
return;
42134218
}

llvm/lib/Target/RISCV/RISCVInstrInfoB.td

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@
1717
// Operand and SDNode transformation definitions.
1818
//===----------------------------------------------------------------------===//
1919

20-
def riscv_clzw : SDNode<"RISCVISD::CLZW", SDTIntUnaryOp>;
21-
def riscv_ctzw : SDNode<"RISCVISD::CTZW", SDTIntUnaryOp>;
22-
def riscv_rolw : SDNode<"RISCVISD::ROLW", SDTIntShiftOp>;
23-
def riscv_rorw : SDNode<"RISCVISD::RORW", SDTIntShiftOp>;
24-
def riscv_fslw : SDNode<"RISCVISD::FSLW", SDTIntShiftDOp>;
25-
def riscv_fsrw : SDNode<"RISCVISD::FSRW", SDTIntShiftDOp>;
26-
def riscv_fsl : SDNode<"RISCVISD::FSL", SDTIntShiftDOp>;
27-
def riscv_fsr : SDNode<"RISCVISD::FSR", SDTIntShiftDOp>;
20+
def riscv_clzw : SDNode<"RISCVISD::CLZW", SDTIntUnaryOp>;
21+
def riscv_ctzw : SDNode<"RISCVISD::CTZW", SDTIntUnaryOp>;
22+
def riscv_rolw : SDNode<"RISCVISD::ROLW", SDTIntShiftOp>;
23+
def riscv_rorw : SDNode<"RISCVISD::RORW", SDTIntShiftOp>;
24+
def riscv_fslw : SDNode<"RISCVISD::FSLW", SDTIntShiftDOp>;
25+
def riscv_fsrw : SDNode<"RISCVISD::FSRW", SDTIntShiftDOp>;
26+
def riscv_fsl : SDNode<"RISCVISD::FSL", SDTIntShiftDOp>;
27+
def riscv_fsr : SDNode<"RISCVISD::FSR", SDTIntShiftDOp>;
28+
def riscv_grevi : SDNode<"RISCVISD::GREVI", SDTIntBinOp>;
29+
def riscv_greviw : SDNode<"RISCVISD::GREVIW", SDTIntBinOp>;
30+
def riscv_gorci : SDNode<"RISCVISD::GORCI", SDTIntBinOp>;
31+
def riscv_gorciw : SDNode<"RISCVISD::GORCIW", SDTIntBinOp>;
32+
def riscv_shfli : SDNode<"RISCVISD::SHFLI", SDTIntBinOp>;
2833

2934
def UImmLog2XLenHalfAsmOperand : AsmOperandClass {
3035
let Name = "UImmLog2XLenHalf";
@@ -690,21 +695,16 @@ def : Pat<(rotr GPR:$rs1, uimmlog2xlen:$shamt),
690695
(RORI GPR:$rs1, uimmlog2xlen:$shamt)>;
691696
def : Pat<(rotl GPR:$rs1, uimmlog2xlen:$shamt),
692697
(RORI GPR:$rs1, (ImmSubFromXLen uimmlog2xlen:$shamt))>;
693-
}
694698

695-
def riscv_grevi : SDNode<"RISCVISD::GREVI", SDTIntBinOp, []>;
696-
def riscv_greviw : SDNode<"RISCVISD::GREVIW", SDTIntBinOp, []>;
697-
def riscv_gorci : SDNode<"RISCVISD::GORCI", SDTIntBinOp, []>;
698-
def riscv_gorciw : SDNode<"RISCVISD::GORCIW", SDTIntBinOp, []>;
699-
def riscv_shfli : SDNode<"RISCVISD::SHFLI", SDTIntBinOp, []>;
699+
// We treat orc.b as a separate instruction, so match it directly. We also
700+
// lower the Zbb orc.b intrinsic to this.
701+
def : Pat<(riscv_gorci GPR:$rs1, 7), (ORCB GPR:$rs1)>;
702+
}
700703

701704
let Predicates = [HasStdExtZbp] in {
702705
def : Pat<(riscv_shfli GPR:$rs1, timm:$shamt), (SHFLI GPR:$rs1, timm:$shamt)>;
703706
def : Pat<(riscv_grevi GPR:$rs1, timm:$shamt), (GREVI GPR:$rs1, timm:$shamt)>;
704707
def : Pat<(riscv_gorci GPR:$rs1, timm:$shamt), (GORCI GPR:$rs1, timm:$shamt)>;
705-
706-
// We treat orc.b as a separate instruction, so match it directly.
707-
def : Pat<(riscv_gorci GPR:$rs1, 7), (ORCB GPR:$rs1)>;
708708
} // Predicates = [HasStdExtZbp]
709709

710710
let Predicates = [HasStdExtZbp, IsRV32] in {
@@ -894,10 +894,6 @@ def : Pat<(i64 (or (and (assertsexti32 GPR:$rs2), 0xFFFFFFFFFFFF0000),
894894
(PACKUW GPR:$rs1, GPR:$rs2)>;
895895
} // Predicates = [HasStdExtZbp, IsRV64]
896896

897-
let Predicates = [HasStdExtZbb] in {
898-
def : PatGpr<int_riscv_orc_b, ORCB>;
899-
} // Predicates = [HasStdExtZbb]
900-
901897
let Predicates = [HasStdExtZbc] in {
902898
def : PatGprGpr<int_riscv_clmul, CLMUL>;
903899
def : PatGprGpr<int_riscv_clmulh, CLMULH>;

0 commit comments

Comments
 (0)