[PATCH] D57317: [DAGCombine] Deduplicate addcarry node using commutativity.
Paweł Bylica via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 1 10:34:22 PDT 2022
chfast updated this revision to Diff 464508.
chfast added a comment.
Herald added a subscriber: pengfei.
Rebased.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57317/new/
https://reviews.llvm.org/D57317
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/X86/addcarry.ll
Index: llvm/test/CodeGen/X86/addcarry.ll
===================================================================
--- llvm/test/CodeGen/X86/addcarry.ll
+++ llvm/test/CodeGen/X86/addcarry.ll
@@ -1397,13 +1397,10 @@
define { i64, i64 } @addcarry_commutative_1(i64 %x0, i64 %x1, i64 %y0, i64 %y1) nounwind {
; CHECK-LABEL: addcarry_commutative_1:
; CHECK: # %bb.0:
-; CHECK-NEXT: movq %rdi, %rax
-; CHECK-NEXT: addq %rdx, %rax
; CHECK-NEXT: movq %rsi, %rax
-; CHECK-NEXT: adcq %rcx, %rax
; CHECK-NEXT: addq %rdx, %rdi
-; CHECK-NEXT: adcq %rcx, %rsi
-; CHECK-NEXT: movq %rsi, %rdx
+; CHECK-NEXT: adcq %rcx, %rax
+; CHECK-NEXT: movq %rax, %rdx
; CHECK-NEXT: retq
%z0 = call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %x0, i64 %y0)
%k0 = extractvalue { i64, i1 } %z0, 1
@@ -1424,13 +1421,10 @@
define { i64, i64 } @addcarry_commutative_2(i64 %x0, i64 %x1, i64 %y0, i64 %y1) nounwind {
; CHECK-LABEL: addcarry_commutative_2:
; CHECK: # %bb.0:
-; CHECK-NEXT: movq %rdi, %rax
-; CHECK-NEXT: addq %rdx, %rax
; CHECK-NEXT: movq %rsi, %rax
-; CHECK-NEXT: adcq %rcx, %rax
; CHECK-NEXT: addq %rdx, %rdi
-; CHECK-NEXT: adcq %rcx, %rsi
-; CHECK-NEXT: movq %rsi, %rdx
+; CHECK-NEXT: adcq %rcx, %rax
+; CHECK-NEXT: movq %rax, %rdx
; CHECK-NEXT: retq
%z0 = call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %x0, i64 %y0)
%k0 = extractvalue { i64, i1 } %z0, 1
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -3056,6 +3056,17 @@
if (SDValue Combined = visitADDCARRYLike(N1, N0, CarryIn, N))
return Combined;
+ // We want to avoid useless duplication.
+ // TODO: This is done automatically for binary operations. As ADDCARRY is
+ // not a binary operation, this is not really possible to leverage this
+ // existing mechanism for it. However, if more operations require the same
+ // deduplication logic, then it may be worth generalize.
+ SDValue Ops[] = {N1, N0, CarryIn};
+ SDNode *CSENode =
+ DAG.getNodeIfExists(ISD::ADDCARRY, N->getVTList(), Ops, N->getFlags());
+ if (CSENode)
+ return SDValue(CSENode, 0);
+
return SDValue();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57317.464508.patch
Type: text/x-patch
Size: 2315 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221001/688d30e2/attachment.bin>
More information about the llvm-commits
mailing list