@@ -517,7 +517,8 @@ MipsTargetLowering::MipsTargetLowering(const MipsTargetMachine &TM,
517
517
setOperationAction (ISD::TRAP, MVT::Other, Legal);
518
518
519
519
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});
521
522
522
523
if (Subtarget.isGP64bit ())
523
524
setMaxAtomicSizeInBitsSupported (64 );
@@ -1210,6 +1211,30 @@ static SDValue performSHLCombine(SDNode *N, SelectionDAG &DAG,
1210
1211
DAG.getConstant (SMSize, DL, MVT::i32));
1211
1212
}
1212
1213
1214
+ static SDValue performSignExtendCombine (SDNode *N, SelectionDAG &DAG,
1215
+ TargetLowering::DAGCombinerInfo &DCI,
1216
+ const MipsSubtarget &Subtarget) {
1217
+ SDValue N0 = N->getOperand (0 );
1218
+ EVT VT = N->getValueType (0 );
1219
+
1220
+ // $dst = sign_extend (xor (trunc $src), imm)
1221
+ // => $dst = sign_extend (trunc (xor $src, imm))
1222
+ if (N0.getOpcode () == ISD::XOR &&
1223
+ N0.getOperand (0 ).getOpcode () == ISD::TRUNCATE &&
1224
+ N0.getOperand (1 ).getOpcode () == ISD::Constant) {
1225
+ SDValue TruncateOperand = N0.getOperand (0 ).getOperand (0 );
1226
+ APInt Mask = N0.getConstantOperandAPInt (1 ).zext (VT.getSizeInBits ());
1227
+
1228
+ SDValue Xor = DAG.getNode (ISD::XOR, SDLoc (N), VT, TruncateOperand,
1229
+ DAG.getTargetConstant (Mask, SDLoc (N), VT));
1230
+ SDValue Truncate =
1231
+ DAG.getNode (ISD::TRUNCATE, SDLoc (N), N0->getValueType (0 ), Xor);
1232
+ return DAG.getNode (ISD::SIGN_EXTEND, SDLoc (N), VT, Truncate);
1233
+ }
1234
+
1235
+ return SDValue ();
1236
+ }
1237
+
1213
1238
SDValue MipsTargetLowering::PerformDAGCombine (SDNode *N, DAGCombinerInfo &DCI)
1214
1239
const {
1215
1240
SelectionDAG &DAG = DCI.DAG ;
@@ -1235,6 +1260,8 @@ SDValue MipsTargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI)
1235
1260
return performSHLCombine (N, DAG, DCI, Subtarget);
1236
1261
case ISD::SUB:
1237
1262
return performSUBCombine (N, DAG, DCI, Subtarget);
1263
+ case ISD::SIGN_EXTEND:
1264
+ return performSignExtendCombine (N, DAG, DCI, Subtarget);
1238
1265
}
1239
1266
1240
1267
return SDValue ();
0 commit comments