Skip to content

Commit 4b04e11

Browse files
committed
[DAGCombiner] Sub/SUBSAT - use general SelectionDAG::FoldConstantArithmetic
This handles all the constant splat / opaque testing for us.
1 parent 48bd6a0 commit 4b04e11

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2976,11 +2976,10 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
29762976
// FIXME: Refactor this and xor and other similar operations together.
29772977
if (N0 == N1)
29782978
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;
29842983

29852984
if (SDValue NewSel = foldBinOpIntoSelect(N))
29862985
return NewSel;
@@ -3300,11 +3299,9 @@ SDValue DAGCombiner::visitSUBSAT(SDNode *N) {
33003299
if (N0 == N1)
33013300
return DAG.getConstant(0, DL, VT);
33023301

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;
33083305

33093306
// fold (sub_sat x, 0) -> x
33103307
if (isNullConstant(N1))

0 commit comments

Comments
 (0)