[PATCH] D133471: [DAGCombiner][X86] Fold (sub (subcarry X, 0, Carry), Y) -> (subcarry X, Y, Carry)
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 7 22:09:33 PDT 2022
craig.topper created this revision.
craig.topper added reviewers: RKSimon, spatel.
Herald added subscribers: StephenFan, ecnelises, pengfei, hiraditya.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added a project: LLVM.
Fixes PR57576.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D133471
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/X86/pr57576.ll
Index: llvm/test/CodeGen/X86/pr57576.ll
===================================================================
--- llvm/test/CodeGen/X86/pr57576.ll
+++ llvm/test/CodeGen/X86/pr57576.ll
@@ -6,8 +6,7 @@
; CHECK: # %bb.0:
; CHECK-NEXT: movq %rdi, %rax
; CHECK-NEXT: subq %rdx, %rax
-; CHECK-NEXT: sbbq $0, %rsi
-; CHECK-NEXT: subq %rcx, %rsi
+; CHECK-NEXT: sbbq %rcx, %rsi
; CHECK-NEXT: movq %rsi, %rdx
; CHECK-NEXT: retq
%5 = zext i64 %1 to i128
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -3753,6 +3753,12 @@
return DAG.getNode(ISD::ADD, DL, VT, N1, N0);
}
+ // (sub (subcarry X, 0, Carry), Y) -> (subcarry X, Y, Carry)
+ if (N0.getOpcode() == ISD::SUBCARRY && isNullConstant(N0.getOperand(1)) &&
+ N0.getResNo() == 0)
+ return DAG.getNode(ISD::SUBCARRY, DL, N0->getVTList(),
+ N0.getOperand(0), N1, N0.getOperand(2));
+
if (TLI.isOperationLegalOrCustom(ISD::ADDCARRY, VT)) {
// (sub Carry, X) -> (addcarry (sub 0, X), 0, Carry)
if (SDValue Carry = getAsCarry(TLI, N0)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133471.458643.patch
Type: text/x-patch
Size: 1242 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220908/c5044ce2/attachment.bin>
More information about the llvm-commits
mailing list