@@ -1613,8 +1613,8 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op,
1613
1613
// If this is BSWAP rather than BITREVERSE, clear the lower 3 bits.
1614
1614
if (Op.getOpcode () == ISD::BSWAP)
1615
1615
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 ));
1618
1618
}
1619
1619
case ISD::FSHL:
1620
1620
case ISD::FSHR: {
@@ -2898,8 +2898,8 @@ SDValue RISCVTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
2898
2898
}
2899
2899
case Intrinsic::riscv_orc_b:
2900
2900
// 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));
2903
2903
case Intrinsic::riscv_vmv_x_s:
2904
2904
assert (Op.getValueType () == XLenVT && " Unexpected VT!" );
2905
2905
return DAG.getNode (RISCVISD::VMV_X_S, DL, Op.getValueType (),
@@ -4018,10 +4018,10 @@ static RISCVISD::NodeType getRISCVWOpcode(unsigned Opcode) {
4018
4018
return RISCVISD::ROLW;
4019
4019
case ISD::ROTR:
4020
4020
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 ;
4025
4025
}
4026
4026
}
4027
4027
@@ -4279,18 +4279,20 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
4279
4279
}
4280
4280
break ;
4281
4281
}
4282
- case RISCVISD::GREVI :
4283
- case RISCVISD::GORCI : {
4282
+ case RISCVISD::GREV :
4283
+ case RISCVISD::GORC : {
4284
4284
assert (N->getValueType (0 ) == MVT::i32 && Subtarget.is64Bit () &&
4285
4285
" Unexpected custom legalisation" );
4286
+ assert (isa<ConstantSDNode>(N->getOperand (1 )) && " Expected constant" );
4286
4287
// This is similar to customLegalizeToWOp, except that we pass the second
4287
4288
// operand (a TargetConstant) straight through: it is already of type
4288
4289
// XLenVT.
4289
4290
RISCVISD::NodeType WOpcode = getRISCVWOpcode (N->getOpcode ());
4290
4291
SDValue NewOp0 =
4291
4292
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);
4294
4296
// ReplaceNodeResults requires we maintain the same type for the return
4295
4297
// value.
4296
4298
Results.push_back (DAG.getNode (ISD::TRUNCATE, DL, MVT::i32, NewRes));
@@ -4318,9 +4320,8 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
4318
4320
SDValue NewOp0 = DAG.getNode (ISD::ANY_EXTEND, DL, MVT::i64,
4319
4321
N->getOperand (0 ));
4320
4322
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));
4324
4325
// ReplaceNodeResults requires we maintain the same type for the return
4325
4326
// value.
4326
4327
Results.push_back (DAG.getNode (ISD::TRUNCATE, DL, MVT::i32, GREVIW));
@@ -4416,9 +4417,9 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
4416
4417
DAG.getNode (ISD::ANY_EXTEND, DL, MVT::i64, N->getOperand (1 ));
4417
4418
// If Zbp is enabled, use GORCIW which will sign extend the result.
4418
4419
unsigned Opc =
4419
- Subtarget.hasStdExtZbp () ? RISCVISD::GORCIW : RISCVISD::GORCI ;
4420
+ Subtarget.hasStdExtZbp () ? RISCVISD::GORCW : RISCVISD::GORC ;
4420
4421
SDValue Res = DAG.getNode (Opc, DL, MVT::i64, NewOp,
4421
- DAG.getTargetConstant (7 , DL, MVT::i64));
4422
+ DAG.getConstant (7 , DL, MVT::i64));
4422
4423
Results.push_back (DAG.getNode (ISD::TRUNCATE, DL, MVT::i32, Res));
4423
4424
return ;
4424
4425
}
@@ -4599,9 +4600,8 @@ static SDValue combineORToGREV(SDValue Op, SelectionDAG &DAG,
4599
4600
auto RHS = matchGREVIPat (Op.getOperand (1 ));
4600
4601
if (LHS && RHS && LHS->formsPairWith (*RHS)) {
4601
4602
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));
4605
4605
}
4606
4606
}
4607
4607
return SDValue ();
@@ -4627,19 +4627,19 @@ static SDValue combineORToGORC(SDValue Op, SelectionDAG &DAG,
4627
4627
SDValue Op1 = Op.getOperand (1 );
4628
4628
4629
4629
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 )) &&
4631
4632
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 ));
4633
4634
// We can also form GORCI from ROTL/ROTR by half the bitwidth.
4634
4635
if ((Reverse.getOpcode () == ISD::ROTL ||
4635
4636
Reverse.getOpcode () == ISD::ROTR) &&
4636
4637
Reverse.getOperand (0 ) == X &&
4637
4638
isa<ConstantSDNode>(Reverse.getOperand (1 ))) {
4638
4639
uint64_t RotAmt = Reverse.getConstantOperandVal (1 );
4639
4640
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));
4643
4643
}
4644
4644
return SDValue ();
4645
4645
};
@@ -4666,9 +4666,8 @@ static SDValue combineORToGORC(SDValue Op, SelectionDAG &DAG,
4666
4666
}
4667
4667
auto RHS = matchGREVIPat (Op1);
4668
4668
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));
4672
4671
}
4673
4672
}
4674
4673
return SDValue ();
@@ -4774,17 +4773,21 @@ static SDValue combineORToSHFL(SDValue Op, SelectionDAG &DAG,
4774
4773
// Combine (GORCI (GORCI x, C2), C1) -> (GORCI x, C1|C2). Repeated stage does
4775
4774
// not undo itself, but they are redundant.
4776
4775
static SDValue combineGREVI_GORCI (SDNode *N, SelectionDAG &DAG) {
4777
- unsigned ShAmt1 = N->getConstantOperandVal (1 );
4778
4776
SDValue Src = N->getOperand (0 );
4779
4777
4780
4778
if (Src.getOpcode () != N->getOpcode ())
4781
4779
return SDValue ();
4782
4780
4781
+ if (!isa<ConstantSDNode>(N->getOperand (1 )) ||
4782
+ !isa<ConstantSDNode>(Src.getOperand (1 )))
4783
+ return SDValue ();
4784
+
4785
+ unsigned ShAmt1 = N->getConstantOperandVal (1 );
4783
4786
unsigned ShAmt2 = Src.getConstantOperandVal (1 );
4784
4787
Src = Src.getOperand (0 );
4785
4788
4786
4789
unsigned CombinedShAmt;
4787
- if (N->getOpcode () == RISCVISD::GORCI || N->getOpcode () == RISCVISD::GORCIW )
4790
+ if (N->getOpcode () == RISCVISD::GORC || N->getOpcode () == RISCVISD::GORCW )
4788
4791
CombinedShAmt = ShAmt1 | ShAmt2;
4789
4792
else
4790
4793
CombinedShAmt = ShAmt1 ^ ShAmt2;
@@ -4793,9 +4796,9 @@ static SDValue combineGREVI_GORCI(SDNode *N, SelectionDAG &DAG) {
4793
4796
return Src;
4794
4797
4795
4798
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 ()));
4799
4802
}
4800
4803
4801
4804
SDValue RISCVTargetLowering::PerformDAGCombine (SDNode *N,
@@ -4909,8 +4912,8 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
4909
4912
}
4910
4913
break ;
4911
4914
}
4912
- case RISCVISD::GREVIW :
4913
- case RISCVISD::GORCIW : {
4915
+ case RISCVISD::GREVW :
4916
+ case RISCVISD::GORCW : {
4914
4917
// Only the lower 32 bits of the first operand are read
4915
4918
SDValue Op0 = N->getOperand (0 );
4916
4919
APInt Mask = APInt::getLowBitsSet (Op0.getValueSizeInBits (), 32 );
@@ -4952,8 +4955,8 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
4952
4955
return DAG.getNode (ISD::AND, DL, MVT::i64, NewFMV,
4953
4956
DAG.getConstant (~SignBit, DL, MVT::i64));
4954
4957
}
4955
- case RISCVISD::GREVI :
4956
- case RISCVISD::GORCI :
4958
+ case RISCVISD::GREV :
4959
+ case RISCVISD::GORC :
4957
4960
return combineGREVI_GORCI (N, DCI.DAG );
4958
4961
case ISD::OR:
4959
4962
if (auto GREV = combineORToGREV (SDValue (N, 0 ), DCI.DAG , Subtarget))
@@ -5360,8 +5363,8 @@ unsigned RISCVTargetLowering::ComputeNumSignBitsForTargetNode(
5360
5363
case RISCVISD::REMUW:
5361
5364
case RISCVISD::ROLW:
5362
5365
case RISCVISD::RORW:
5363
- case RISCVISD::GREVIW :
5364
- case RISCVISD::GORCIW :
5366
+ case RISCVISD::GREVW :
5367
+ case RISCVISD::GORCW :
5365
5368
case RISCVISD::FSLW:
5366
5369
case RISCVISD::FSRW:
5367
5370
// TODO: As the result is sign-extended, this is conservatively correct. A
@@ -7105,10 +7108,10 @@ const char *RISCVTargetLowering::getTargetNodeName(unsigned Opcode) const {
7105
7108
NODE_NAME_CASE (FMV_W_X_RV64)
7106
7109
NODE_NAME_CASE (FMV_X_ANYEXTW_RV64)
7107
7110
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 )
7112
7115
NODE_NAME_CASE (SHFL)
7113
7116
NODE_NAME_CASE (VMV_V_X_VL)
7114
7117
NODE_NAME_CASE (VFMV_V_F_VL)
0 commit comments