[llvm] [DAGCombiner] Fold subtraction if above threshold to `umin` (PR #134235)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 9 12:35:31 PDT 2025
================
@@ -4247,6 +4247,19 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
sd_match(N1, m_UMaxLike(m_Specific(A), m_Specific(B))))
return DAG.getNegative(DAG.getNode(ISD::ABDU, DL, VT, A, B), DL, VT);
+ // (sub x, (select (ult x, y), 0, y)) -> (umin x, (sub x, y))
+ auto LK = TLI.getTypeConversion(*DAG.getContext(), VT);
+ if ((LK.first == TargetLoweringBase::TypeLegal ||
+ LK.first == TargetLoweringBase::TypePromoteInteger) &&
+ TLI.isOperationLegal(ISD::UMIN, LK.second)) {
+ SDValue Y;
+ if (sd_match(N1, m_OneUse(m_Select(m_SetCC(m_Specific(N0), m_Value(Y),
+ m_SpecificCondCode(ISD::SETULT)),
----------------
topperc wrote:
Here is a test where InstCombine doesn't change the uge to ult https://godbolt.org/z/oTafcozaG
https://github.com/llvm/llvm-project/pull/134235
More information about the llvm-commits
mailing list