Skip to content

Commit 9e975e5

Browse files
ZCBingbenshi001
authored andcommitted
[RISCV][NFC] Move some combine patterns to DAG combine.
Move some combine patterns to DAG combine,and it dealt with fixme left in RISCVInstrInfoZb.td. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D119527
1 parent bfc6fbf commit 9e975e5

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,8 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
10681068
setTargetDAGCombine(ISD::AND);
10691069
setTargetDAGCombine(ISD::OR);
10701070
setTargetDAGCombine(ISD::XOR);
1071+
setTargetDAGCombine(ISD::ROTL);
1072+
setTargetDAGCombine(ISD::ROTR);
10711073
setTargetDAGCombine(ISD::ANY_EXTEND);
10721074
if (Subtarget.hasStdExtF()) {
10731075
setTargetDAGCombine(ISD::ZERO_EXTEND);
@@ -7269,6 +7271,40 @@ static SDValue transformAddShlImm(SDNode *N, SelectionDAG &DAG,
72697271
return DAG.getNode(ISD::SHL, DL, VT, NA1, DAG.getConstant(Bits, DL, VT));
72707272
}
72717273

7274+
// Combine
7275+
// ROTR ((GREV x, 24), 16) -> (GREVI x, 8)
7276+
// ROTL ((GREV x, 24), 16) -> (GREVI x, 8)
7277+
// RORW ((GREVW x, 24), 16) -> (GREVIW x, 8)
7278+
// ROLW ((GREVW x, 24), 16) -> (GREVIW x, 8)
7279+
static SDValue combineROTR_ROTL_RORW_ROLW(SDNode *N, SelectionDAG &DAG) {
7280+
SDValue Src = N->getOperand(0);
7281+
SDLoc DL(N);
7282+
unsigned Opc;
7283+
7284+
if ((N->getOpcode() == ISD::ROTR || N->getOpcode() == ISD::ROTL) &&
7285+
Src.getOpcode() == RISCVISD::GREV)
7286+
Opc = RISCVISD::GREV;
7287+
else if ((N->getOpcode() == RISCVISD::RORW ||
7288+
N->getOpcode() == RISCVISD::ROLW) &&
7289+
Src.getOpcode() == RISCVISD::GREVW)
7290+
Opc = RISCVISD::GREVW;
7291+
else
7292+
return SDValue();
7293+
7294+
if (!isa<ConstantSDNode>(N->getOperand(1)) ||
7295+
!isa<ConstantSDNode>(Src.getOperand(1)))
7296+
return SDValue();
7297+
7298+
unsigned ShAmt1 = N->getConstantOperandVal(1);
7299+
unsigned ShAmt2 = Src.getConstantOperandVal(1);
7300+
if (ShAmt1 != 16 && ShAmt2 != 24)
7301+
return SDValue();
7302+
7303+
Src = Src.getOperand(0);
7304+
return DAG.getNode(Opc, DL, N->getValueType(0), Src,
7305+
DAG.getConstant(8, DL, N->getOperand(1).getValueType()));
7306+
}
7307+
72727308
// Combine (GREVI (GREVI x, C2), C1) -> (GREVI x, C1^C2) when C1^C2 is
72737309
// non-zero, and to x when it is. Any repeated GREVI stage undoes itself.
72747310
// Combine (GORCI (GORCI x, C2), C1) -> (GORCI x, C1|C2). Repeated stage does
@@ -7973,8 +8009,12 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
79738009
if (SimplifyDemandedLowBitsHelper(0, 32) ||
79748010
SimplifyDemandedLowBitsHelper(1, 5))
79758011
return SDValue(N, 0);
7976-
break;
8012+
8013+
return combineROTR_ROTL_RORW_ROLW(N, DAG);
79778014
}
8015+
case ISD::ROTR:
8016+
case ISD::ROTL:
8017+
return combineROTR_ROTL_RORW_ROLW(N, DAG);
79788018
case RISCVISD::CLZW:
79798019
case RISCVISD::CTZW: {
79808020
// Only the lower 32 bits of the first operand are read

llvm/lib/Target/RISCV/RISCVInstrInfoZb.td

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -880,10 +880,6 @@ def : PatGprGpr<riscv_gorcw, GORCW>;
880880
def : PatGprImm<riscv_grevw, GREVIW, uimm5>;
881881
def : PatGprImm<riscv_gorcw, GORCIW, uimm5>;
882882

883-
// FIXME: Move to DAG combine.
884-
def : Pat<(riscv_rorw (riscv_grevw GPR:$rs1, 24), 16), (GREVIW GPR:$rs1, 8)>;
885-
def : Pat<(riscv_rolw (riscv_grevw GPR:$rs1, 24), 16), (GREVIW GPR:$rs1, 8)>;
886-
887883
def : PatGprGpr<riscv_shflw, SHFLW>;
888884
def : PatGprGpr<riscv_unshflw, UNSHFLW>;
889885
} // Predicates = [HasStdExtZbp, IsRV64]
@@ -892,10 +888,6 @@ let Predicates = [HasStdExtZbp, IsRV64] in
892888
def : PatGprGpr<int_riscv_xperm_w, XPERM_W>;
893889

894890
let Predicates = [HasStdExtZbp, IsRV32] in {
895-
// FIXME : Move to DAG combine.
896-
def : Pat<(i32 (rotr (riscv_grev GPR:$rs1, 24), (i32 16))), (GREVI GPR:$rs1, 8)>;
897-
def : Pat<(i32 (rotl (riscv_grev GPR:$rs1, 24), (i32 16))), (GREVI GPR:$rs1, 8)>;
898-
899891
// We treat rev8 as a separate instruction, so match it directly.
900892
def : Pat<(i32 (riscv_grev GPR:$rs1, 24)), (REV8_RV32 GPR:$rs1)>;
901893
} // Predicates = [HasStdExtZbp, IsRV32]

0 commit comments

Comments
 (0)