@@ -2976,11 +2976,10 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
2976
2976
// FIXME: Refactor this and xor and other similar operations together.
2977
2977
if (N0 == N1)
2978
2978
return tryFoldToZero(DL, TLI, VT, DAG, LegalOperations);
2979
- if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
2980
- DAG.isConstantIntBuildVectorOrConstantInt(N1)) {
2981
- // fold (sub c1, c2) -> c1-c2
2982
- return DAG.FoldConstantArithmetic(ISD::SUB, DL, VT, {N0, N1});
2983
- }
2979
+
2980
+ // fold (sub c1, c2) -> c3
2981
+ if (SDValue C = DAG.FoldConstantArithmetic(ISD::SUB, DL, VT, {N0, N1}))
2982
+ return C;
2984
2983
2985
2984
if (SDValue NewSel = foldBinOpIntoSelect(N))
2986
2985
return NewSel;
@@ -3300,11 +3299,9 @@ SDValue DAGCombiner::visitSUBSAT(SDNode *N) {
3300
3299
if (N0 == N1)
3301
3300
return DAG.getConstant(0, DL, VT);
3302
3301
3303
- if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
3304
- DAG.isConstantIntBuildVectorOrConstantInt(N1)) {
3305
- // fold (sub_sat c1, c2) -> c3
3306
- return DAG.FoldConstantArithmetic(N->getOpcode(), DL, VT, {N0, N1});
3307
- }
3302
+ // fold (sub_sat c1, c2) -> c3
3303
+ if (SDValue C = DAG.FoldConstantArithmetic(N->getOpcode(), DL, VT, {N0, N1}))
3304
+ return C;
3308
3305
3309
3306
// fold (sub_sat x, 0) -> x
3310
3307
if (isNullConstant(N1))
0 commit comments