[llvm] [TargetLowering] Don't do abdu(lhs, rhs) -> sub(xor(sub(lhs, rhs), uo…f(lhs, rhs)), uof(lhs, rhs)) if it is not custom lowered (PR #156188)

via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 30 09:19:24 PDT 2025


https://github.com/AZero13 updated https://github.com/llvm/llvm-project/pull/156188

>From 6000cd78271aab3e440b26b82bddd2da63af14e9 Mon Sep 17 00:00:00 2001
From: AZero13 <gfunni234 at gmail.com>
Date: Sat, 30 Aug 2025 12:18:09 -0400
Subject: [PATCH 1/2] [TargetLowering] Don't do abdu(lhs, rhs) ->
 sub(xor(sub(lhs, rhs), uof(lhs, rhs)), uof(lhs, rhs)) if it is not custom
 lowered

Otherwise we deal with a lot of crazy expansions that could be handled by a select.
---
 llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 402a012e8e555..9a7379032766a 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -9792,7 +9792,8 @@ SDValue TargetLowering::expandABD(SDNode *N, SelectionDAG &DAG) const {
   // flag if the (scalar) type is illegal as this is more likely to legalize
   // cleanly:
   // abdu(lhs, rhs) -> sub(xor(sub(lhs, rhs), uof(lhs, rhs)), uof(lhs, rhs))
-  if (!IsSigned && VT.isScalarInteger() && !isTypeLegal(VT)) {
+  if (!IsSigned && VT.isScalarInteger() && !isTypeLegal(VT) &&
+      isOperationCustom(ISD::USUBO, VT)) {
     SDValue USubO =
         DAG.getNode(ISD::USUBO, dl, DAG.getVTList(VT, MVT::i1), {LHS, RHS});
     SDValue Cmp = DAG.getNode(ISD::SIGN_EXTEND, dl, VT, USubO.getValue(1));

>From b114733119bd5e51ff1b89f2f7b2e02e491ec3d2 Mon Sep 17 00:00:00 2001
From: AZero13 <gfunni234 at gmail.com>
Date: Sat, 30 Aug 2025 12:19:14 -0400
Subject: [PATCH 2/2] Update TargetLowering.cpp

---
 llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 9a7379032766a..3685c1c6dad3c 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -9793,7 +9793,7 @@ SDValue TargetLowering::expandABD(SDNode *N, SelectionDAG &DAG) const {
   // cleanly:
   // abdu(lhs, rhs) -> sub(xor(sub(lhs, rhs), uof(lhs, rhs)), uof(lhs, rhs))
   if (!IsSigned && VT.isScalarInteger() && !isTypeLegal(VT) &&
-      isOperationCustom(ISD::USUBO, VT)) {
+      !isOperationExpand(ISD::USUBO, VT)) {
     SDValue USubO =
         DAG.getNode(ISD::USUBO, dl, DAG.getVTList(VT, MVT::i1), {LHS, RHS});
     SDValue Cmp = DAG.getNode(ISD::SIGN_EXTEND, dl, VT, USubO.getValue(1));



More information about the llvm-commits mailing list