[PATCH] D105789: [SelectionDAG] Check use before combining into USUBSAT
Qiu Chaofan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 11 21:25:46 PDT 2021
qiucf created this revision.
qiucf added reviewers: RKSimon, craig.topper, efriedma, nemanjai, jsji, PowerPC.
Herald added a subscriber: hiraditya.
qiucf requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
(The test part in this patch is not applicable since it's not pre-committed yet)
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D105789
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/PowerPC/sat-add.ll
Index: llvm/test/CodeGen/PowerPC/sat-add.ll
===================================================================
--- llvm/test/CodeGen/PowerPC/sat-add.ll
+++ llvm/test/CodeGen/PowerPC/sat-add.ll
@@ -881,10 +881,8 @@
; CHECK: # %bb.0:
; CHECK-NEXT: li 5, 4
; CHECK-NEXT: cmpldi 3, 4
-; CHECK-NEXT: addi 6, 3, -4
; CHECK-NEXT: isellt 5, 3, 5
-; CHECK-NEXT: cmpld 6, 3
-; CHECK-NEXT: iselgt 3, 0, 6
+; CHECK-NEXT: sub 3, 3, 5
; CHECK-NEXT: add 4, 4, 5
; CHECK-NEXT: mulld 3, 3, 4
; CHECK-NEXT: blr
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -3209,7 +3209,7 @@
// Try to find umax(a,b) - b or a - umin(a,b) patterns
// they may be converted to usubsat(a,b).
- if (Op0.getOpcode() == ISD::UMAX) {
+ if (Op0.getOpcode() == ISD::UMAX && Op0.hasOneUse()) {
SDValue MaxLHS = Op0.getOperand(0);
SDValue MaxRHS = Op0.getOperand(1);
if (MaxLHS == Op1)
@@ -3218,7 +3218,7 @@
return getTruncatedUSUBSAT(DstVT, SubVT, MaxLHS, Op1, DAG, SDLoc(N));
}
- if (Op1.getOpcode() == ISD::UMIN) {
+ if (Op1.getOpcode() == ISD::UMIN && Op1.hasOneUse()) {
SDValue MinLHS = Op1.getOperand(0);
SDValue MinRHS = Op1.getOperand(1);
if (MinLHS == Op0)
@@ -3229,7 +3229,8 @@
// sub(a,trunc(umin(zext(a),b))) -> usubsat(a,trunc(umin(b,SatLimit)))
if (Op1.getOpcode() == ISD::TRUNCATE &&
- Op1.getOperand(0).getOpcode() == ISD::UMIN) {
+ Op1.getOperand(0).getOpcode() == ISD::UMIN &&
+ Op1.getOperand(0).hasOneUse()) {
SDValue MinLHS = Op1.getOperand(0).getOperand(0);
SDValue MinRHS = Op1.getOperand(0).getOperand(1);
if (MinLHS.getOpcode() == ISD::ZERO_EXTEND && MinLHS.getOperand(0) == Op0)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105789.357838.patch
Type: text/x-patch
Size: 1874 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210712/b1895ced/attachment.bin>
More information about the llvm-commits
mailing list