[llvm] r355689 - [DAGCombine] Merge visitSADDO+visitUADDO into visitADDO. NFCI.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 8 03:30:33 PST 2019
Author: rksimon
Date: Fri Mar 8 03:30:33 2019
New Revision: 355689
URL: http://llvm.org/viewvc/llvm-project?rev=355689&view=rev
Log:
[DAGCombine] Merge visitSADDO+visitUADDO into visitADDO. NFCI.
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=355689&r1=355688&r2=355689&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Fri Mar 8 03:30:33 2019
@@ -295,8 +295,7 @@ namespace {
SDValue visitADDSAT(SDNode *N);
SDValue visitSUBSAT(SDNode *N);
SDValue visitADDC(SDNode *N);
- SDValue visitSADDO(SDNode *N);
- SDValue visitUADDO(SDNode *N);
+ SDValue visitADDO(SDNode *N);
SDValue visitUADDOLike(SDValue N0, SDValue N1, SDNode *N);
SDValue visitSUBC(SDNode *N);
SDValue visitSUBO(SDNode *N);
@@ -1493,8 +1492,8 @@ SDValue DAGCombiner::visit(SDNode *N) {
case ISD::SSUBSAT:
case ISD::USUBSAT: return visitSUBSAT(N);
case ISD::ADDC: return visitADDC(N);
- case ISD::SADDO: return visitSADDO(N);
- case ISD::UADDO: return visitUADDO(N);
+ case ISD::SADDO:
+ case ISD::UADDO: return visitADDO(N);
case ISD::SUBC: return visitSUBC(N);
case ISD::SSUBO:
case ISD::USUBO: return visitSUBO(N);
@@ -2416,35 +2415,11 @@ static bool isBooleanFlip(SDValue V, EVT
llvm_unreachable("Unsupported boolean content");
}
-// TODO: merge this with DAGCombiner::visitUADDO
-SDValue DAGCombiner::visitSADDO(SDNode *N) {
- SDValue N0 = N->getOperand(0);
- SDValue N1 = N->getOperand(1);
- EVT VT = N0.getValueType();
- EVT CarryVT = N->getValueType(1);
- SDLoc DL(N);
-
- // If the flag result is dead, turn this into an ADD.
- if (!N->hasAnyUseOfValue(1))
- return CombineTo(N, DAG.getNode(ISD::ADD, DL, VT, N0, N1),
- DAG.getUNDEF(CarryVT));
-
- // canonicalize constant to RHS.
- if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
- !DAG.isConstantIntBuildVectorOrConstantInt(N1))
- return DAG.getNode(ISD::SADDO, DL, N->getVTList(), N1, N0);
-
- // fold (saddo x, 0) -> x + no carry out
- if (isNullOrNullSplat(N1))
- return CombineTo(N, N0, DAG.getConstant(0, DL, CarryVT));
-
- return SDValue();
-}
-
-SDValue DAGCombiner::visitUADDO(SDNode *N) {
+SDValue DAGCombiner::visitADDO(SDNode *N) {
SDValue N0 = N->getOperand(0);
SDValue N1 = N->getOperand(1);
EVT VT = N0.getValueType();
+ bool IsSigned = (ISD::SADDO == N->getOpcode());
EVT CarryVT = N->getValueType(1);
SDLoc DL(N);
@@ -2457,31 +2432,32 @@ SDValue DAGCombiner::visitUADDO(SDNode *
// canonicalize constant to RHS.
if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
!DAG.isConstantIntBuildVectorOrConstantInt(N1))
- return DAG.getNode(ISD::UADDO, DL, N->getVTList(), N1, N0);
+ return DAG.getNode(N->getOpcode(), DL, N->getVTList(), N1, N0);
- // fold (uaddo x, 0) -> x + no carry out
+ // fold (addo x, 0) -> x + no carry out
if (isNullOrNullSplat(N1))
return CombineTo(N, N0, DAG.getConstant(0, DL, CarryVT));
- // If it cannot overflow, transform into an add.
- if (DAG.computeOverflowKind(N0, N1) == SelectionDAG::OFK_Never)
- return CombineTo(N, DAG.getNode(ISD::ADD, DL, VT, N0, N1),
- DAG.getConstant(0, DL, CarryVT));
+ if (!IsSigned) {
+ // If it cannot overflow, transform into an add.
+ if (DAG.computeOverflowKind(N0, N1) == SelectionDAG::OFK_Never)
+ return CombineTo(N, DAG.getNode(ISD::ADD, DL, VT, N0, N1),
+ DAG.getConstant(0, DL, CarryVT));
- // fold (uaddo (xor a, -1), 1) -> (usub 0, a) and flip carry.
- if (isBitwiseNot(N0) && isOneOrOneSplat(N1)) {
- SDValue Sub = DAG.getNode(ISD::USUBO, DL, N->getVTList(),
- DAG.getConstant(0, DL, VT),
- N0.getOperand(0));
- return CombineTo(N, Sub,
- flipBoolean(Sub.getValue(1), DL, CarryVT, DAG, TLI));
- }
+ // fold (uaddo (xor a, -1), 1) -> (usub 0, a) and flip carry.
+ if (isBitwiseNot(N0) && isOneOrOneSplat(N1)) {
+ SDValue Sub = DAG.getNode(ISD::USUBO, DL, N->getVTList(),
+ DAG.getConstant(0, DL, VT), N0.getOperand(0));
+ return CombineTo(N, Sub,
+ flipBoolean(Sub.getValue(1), DL, CarryVT, DAG, TLI));
+ }
- if (SDValue Combined = visitUADDOLike(N0, N1, N))
- return Combined;
+ if (SDValue Combined = visitUADDOLike(N0, N1, N))
+ return Combined;
- if (SDValue Combined = visitUADDOLike(N1, N0, N))
- return Combined;
+ if (SDValue Combined = visitUADDOLike(N1, N0, N))
+ return Combined;
+ }
return SDValue();
}
More information about the llvm-commits
mailing list