[PATCH] D30417: [DAGCombiner] Do various combine on uaddo.
Amaury SECHET via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 9 14:59:05 PST 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL297416: [DAGCombiner] Do various combine on uaddo. (authored by deadalnix).
Changed prior to commit:
https://reviews.llvm.org/D30417?vs=91205&id=91224#toc
Repository:
rL LLVM
https://reviews.llvm.org/D30417
Files:
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/trunk/test/CodeGen/X86/xaluo.ll
Index: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -235,6 +235,7 @@
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 @@
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);
@@ -1928,6 +1930,39 @@
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);
SDValue N1 = N->getOperand(1);
Index: llvm/trunk/test/CodeGen/X86/xaluo.ll
===================================================================
--- llvm/trunk/test/CodeGen/X86/xaluo.ll
+++ llvm/trunk/test/CodeGen/X86/xaluo.ll
@@ -1345,23 +1345,23 @@
; 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:
; FAST: ## BB#0:
; 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:
; KNL: ## BB#0:
; 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30417.91224.patch
Type: text/x-patch
Size: 3103 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170309/ae8fc559/attachment.bin>
More information about the llvm-commits
mailing list