[llvm] r297416 - [DAGCombiner] Do various combine on uaddo.
Amaury Sechet via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 9 14:47:00 PST 2017
Author: deadalnix
Date: Thu Mar 9 16:47:00 2017
New Revision: 297416
URL: http://llvm.org/viewvc/llvm-project?rev=297416&view=rev
Log:
[DAGCombiner] Do various combine on uaddo.
Summary: This essentially does the same transform as for ADC.
Reviewers: jyknight, nemanjai, mkuper, spatel, RKSimon, zvi, bkramer
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D30417
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/trunk/test/CodeGen/X86/xaluo.ll
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=297416&r1=297415&r2=297416&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Thu Mar 9 16:47:00 2017
@@ -235,6 +235,7 @@ namespace {
SDValue visitADDLike(SDValue N0, SDValue N1, SDNode *LocReference);
SDValue visitSUB(SDNode *N);
SDValue visitADDC(SDNode *N);
+ SDValue visitUADDO(SDNode *N);
SDValue visitSUBC(SDNode *N);
SDValue visitUSUBO(SDNode *N);
SDValue visitADDE(SDNode *N);
@@ -1400,6 +1401,7 @@ SDValue DAGCombiner::visit(SDNode *N) {
case ISD::ADD: return visitADD(N);
case ISD::SUB: return visitSUB(N);
case ISD::ADDC: return visitADDC(N);
+ case ISD::UADDO: return visitUADDO(N);
case ISD::SUBC: return visitSUBC(N);
case ISD::USUBO: return visitUSUBO(N);
case ISD::ADDE: return visitADDE(N);
@@ -1927,6 +1929,39 @@ SDValue DAGCombiner::visitADDC(SDNode *N
return SDValue();
}
+
+SDValue DAGCombiner::visitUADDO(SDNode *N) {
+ SDValue N0 = N->getOperand(0);
+ SDValue N1 = N->getOperand(1);
+ EVT VT = N0.getValueType();
+ if (VT.isVector())
+ return SDValue();
+
+ 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.
+ ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
+ ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
+ if (N0C && !N1C)
+ return DAG.getNode(ISD::UADDO, DL, N->getVTList(), N1, N0);
+
+ // fold (uaddo x, 0) -> x + no carry out
+ if (isNullConstant(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));
+
+ return SDValue();
+}
SDValue DAGCombiner::visitADDE(SDNode *N) {
SDValue N0 = N->getOperand(0);
Modified: llvm/trunk/test/CodeGen/X86/xaluo.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/xaluo.ll?rev=297416&r1=297415&r2=297416&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/xaluo.ll (original)
+++ llvm/trunk/test/CodeGen/X86/xaluo.ll Thu Mar 9 16:47:00 2017
@@ -1345,7 +1345,7 @@ define {i64, i1} @uaddoovf(i64 %a, i64 %
; SDAG-NEXT: movzbl %dil, %ecx
; SDAG-NEXT: movzbl %sil, %eax
; SDAG-NEXT: addq %rcx, %rax
-; SDAG-NEXT: setb %dl
+; SDAG-NEXT: xorl %edx, %edx
; SDAG-NEXT: retq
;
; FAST-LABEL: uaddoovf:
@@ -1353,7 +1353,7 @@ define {i64, i1} @uaddoovf(i64 %a, i64 %
; FAST-NEXT: movzbl %dil, %ecx
; FAST-NEXT: movzbl %sil, %eax
; FAST-NEXT: addq %rcx, %rax
-; FAST-NEXT: setb %dl
+; FAST-NEXT: xorl %edx, %edx
; FAST-NEXT: retq
;
; KNL-LABEL: uaddoovf:
@@ -1361,7 +1361,7 @@ define {i64, i1} @uaddoovf(i64 %a, i64 %
; KNL-NEXT: movzbl %dil, %ecx
; KNL-NEXT: movzbl %sil, %eax
; KNL-NEXT: addq %rcx, %rax
-; KNL-NEXT: setb %dl
+; KNL-NEXT: xorl %edx, %edx
; KNL-NEXT: retq
%1 = and i64 %a, 255
%2 = and i64 %b, 255
More information about the llvm-commits
mailing list