@@ -519,7 +519,8 @@ MipsTargetLowering::MipsTargetLowering(const MipsTargetMachine &TM,
519
519
setOperationAction (ISD::TRAP, MVT::Other, Legal);
520
520
521
521
setTargetDAGCombine ({ISD::SDIVREM, ISD::UDIVREM, ISD::SELECT, ISD::AND,
522
- ISD::OR, ISD::ADD, ISD::SUB, ISD::AssertZext, ISD::SHL});
522
+ ISD::OR, ISD::ADD, ISD::SUB, ISD::AssertZext,
523
+ ISD::SHL, ISD::SIGN_EXTEND});
523
524
524
525
if (Subtarget.isGP64bit ())
525
526
setMaxAtomicSizeInBitsSupported (64 );
@@ -1213,6 +1214,23 @@ static SDValue performSHLCombine(SDNode *N, SelectionDAG &DAG,
1213
1214
DAG.getConstant (SMSize, DL, MVT::i32));
1214
1215
}
1215
1216
1217
+ static SDValue performSignExtendCombine (SDNode *N, SelectionDAG &DAG,
1218
+ TargetLowering::DAGCombinerInfo &DCI,
1219
+ const MipsSubtarget &Subtarget) {
1220
+ SDValue N0 = N->getOperand (0 );
1221
+ EVT VT = N->getValueType (0 );
1222
+
1223
+ // For MIPS64, xor instruction can use with 64 bit arithmetic.
1224
+ // (sext (xor (trunc X), imm)) => (xor (X, imm"))
1225
+ if (N0.getOpcode () == ISD::XOR &&
1226
+ N0.getOperand (0 ).getOpcode () == ISD::TRUNCATE &&
1227
+ N0.getOperand (1 ).getOpcode () == ISD::Constant) {
1228
+ SDValue X0 = N0.getOperand (0 ).getOperand (0 );
1229
+ return DAG.getNode (ISD::XOR, SDLoc (N0), VT, X0,
1230
+ DAG.getTargetConstant (-1 , SDLoc (N0), VT));
1231
+ }
1232
+ }
1233
+
1216
1234
SDValue MipsTargetLowering::PerformDAGCombine (SDNode *N, DAGCombinerInfo &DCI)
1217
1235
const {
1218
1236
SelectionDAG &DAG = DCI.DAG ;
@@ -1238,6 +1256,8 @@ SDValue MipsTargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI)
1238
1256
return performSHLCombine (N, DAG, DCI, Subtarget);
1239
1257
case ISD::SUB:
1240
1258
return performSUBCombine (N, DAG, DCI, Subtarget);
1259
+ case ISD::SIGN_EXTEND:
1260
+ return performSignExtendCombine (N, DAG, DCI, Subtarget);
1241
1261
}
1242
1262
1243
1263
return SDValue ();
0 commit comments