@@ -6103,14 +6103,19 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
6103
6103
6104
6104
break ;
6105
6105
}
6106
+ case RISCVISD::FMV_X_ANYEXTH:
6106
6107
case RISCVISD::FMV_X_ANYEXTW_RV64: {
6107
6108
SDLoc DL (N);
6108
6109
SDValue Op0 = N->getOperand (0 );
6110
+ MVT VT = N->getSimpleValueType (0 );
6109
6111
// If the input to FMV_X_ANYEXTW_RV64 is just FMV_W_X_RV64 then the
6110
- // conversion is unnecessary and can be replaced with an ANY_EXTEND
6111
- // of the FMV_W_X_RV64 operand.
6112
- if (Op0->getOpcode () == RISCVISD::FMV_W_X_RV64) {
6113
- assert (Op0.getOperand (0 ).getValueType () == MVT::i64 &&
6112
+ // conversion is unnecessary and can be replaced with the FMV_W_X_RV64
6113
+ // operand. Similar for FMV_X_ANYEXTH and FMV_H_X.
6114
+ if ((N->getOpcode () == RISCVISD::FMV_X_ANYEXTW_RV64 &&
6115
+ Op0->getOpcode () == RISCVISD::FMV_W_X_RV64) ||
6116
+ (N->getOpcode () == RISCVISD::FMV_X_ANYEXTH &&
6117
+ Op0->getOpcode () == RISCVISD::FMV_H_X)) {
6118
+ assert (Op0.getOperand (0 ).getValueType () == VT &&
6114
6119
" Unexpected value type!" );
6115
6120
return Op0.getOperand (0 );
6116
6121
}
@@ -6122,16 +6127,16 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
6122
6127
if (!(Op0.getOpcode () == ISD::FNEG || Op0.getOpcode () == ISD::FABS) ||
6123
6128
!Op0.getNode ()->hasOneUse ())
6124
6129
break ;
6125
- SDValue NewFMV = DAG.getNode (RISCVISD::FMV_X_ANYEXTW_RV64 , DL, MVT:: i64 ,
6126
- Op0. getOperand ( 0 )) ;
6127
- APInt SignBit = APInt::getSignMask (32 ). sext ( 64 );
6130
+ SDValue NewFMV = DAG.getNode (N-> getOpcode () , DL, VT, Op0. getOperand ( 0 ));
6131
+ unsigned FPBits = N-> getOpcode () == RISCVISD::FMV_X_ANYEXTW_RV64 ? 32 : 16 ;
6132
+ APInt SignBit = APInt::getSignMask (FPBits). sextOrSelf (VT. getSizeInBits () );
6128
6133
if (Op0.getOpcode () == ISD::FNEG)
6129
- return DAG.getNode (ISD::XOR, DL, MVT:: i64 , NewFMV,
6130
- DAG.getConstant (SignBit, DL, MVT:: i64 ));
6134
+ return DAG.getNode (ISD::XOR, DL, VT , NewFMV,
6135
+ DAG.getConstant (SignBit, DL, VT ));
6131
6136
6132
6137
assert (Op0.getOpcode () == ISD::FABS);
6133
- return DAG.getNode (ISD::AND, DL, MVT:: i64 , NewFMV,
6134
- DAG.getConstant (~SignBit, DL, MVT:: i64 ));
6138
+ return DAG.getNode (ISD::AND, DL, VT , NewFMV,
6139
+ DAG.getConstant (~SignBit, DL, VT ));
6135
6140
}
6136
6141
case ISD::AND:
6137
6142
return performANDCombine (N, DCI, Subtarget);
0 commit comments