@@ -517,7 +517,8 @@ MipsTargetLowering::MipsTargetLowering(const MipsTargetMachine &TM,
517517 setOperationAction (ISD::TRAP, MVT::Other, Legal);
518518
519519 setTargetDAGCombine ({ISD::SDIVREM, ISD::UDIVREM, ISD::SELECT, ISD::AND,
520- ISD::OR, ISD::ADD, ISD::SUB, ISD::AssertZext, ISD::SHL});
520+ ISD::OR, ISD::ADD, ISD::SUB, ISD::AssertZext, ISD::SHL,
521+ ISD::SIGN_EXTEND});
521522
522523 if (Subtarget.isGP64bit ())
523524 setMaxAtomicSizeInBitsSupported (64 );
@@ -1210,6 +1211,41 @@ static SDValue performSHLCombine(SDNode *N, SelectionDAG &DAG,
12101211 DAG.getConstant (SMSize, DL, MVT::i32 ));
12111212}
12121213
1214+ static SDValue performSignExtendCombine (SDNode *N, SelectionDAG &DAG, TargetLowering::DAGCombinerInfo &DCI,const MipsSubtarget &Subtarget) {
1215+ if (DCI.Level != AfterLegalizeDAG) {
1216+ return SDValue ();
1217+ }
1218+
1219+ if (!Subtarget.isGP64bit ()) {
1220+ return SDValue ();
1221+ }
1222+
1223+ SDValue N0 = N->getOperand (0 );
1224+ EVT VT = N->getValueType (0 );
1225+
1226+ if (N0->getNumOperands () != 2 ) {
1227+ return SDValue ();
1228+ }
1229+
1230+ // Pattern match XOR.
1231+ // $dst = (sign_extend (xor (trunc $src, i32), -1), i64)
1232+ // => $dst = (xor ($src, -1), i64)
1233+ if (N0.getOpcode () == ISD::XOR &&
1234+ N0.getOperand (0 ).getOpcode () == ISD::TRUNCATE &&
1235+ N0.getOperand (1 ).getOpcode () == ISD::Constant) {
1236+ SDValue TruncateOperand = N0.getOperand (0 ).getOperand (0 );
1237+ if (VT == MVT::i64 && VT == TruncateOperand->getValueType (0 )) {
1238+ APInt MinusOne (32 , -1 , true );
1239+ if (N0.getConstantOperandAPInt (1 ) == MinusOne) {
1240+ return DAG.getNode (ISD::XOR, SDLoc (N0), VT, TruncateOperand,
1241+ DAG.getTargetConstant (-1 , SDLoc (N0), VT));
1242+ }
1243+ }
1244+ }
1245+
1246+ return SDValue ();
1247+ }
1248+
12131249SDValue MipsTargetLowering::PerformDAGCombine (SDNode *N, DAGCombinerInfo &DCI)
12141250 const {
12151251 SelectionDAG &DAG = DCI.DAG ;
@@ -1235,6 +1271,8 @@ SDValue MipsTargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI)
12351271 return performSHLCombine (N, DAG, DCI, Subtarget);
12361272 case ISD::SUB:
12371273 return performSUBCombine (N, DAG, DCI, Subtarget);
1274+ case ISD::SIGN_EXTEND:
1275+ return performSignExtendCombine (N, DAG, DCI, Subtarget);
12381276 }
12391277
12401278 return SDValue ();
0 commit comments