[llvm] [DAGCombiner] Fold subtraction if above threshold to `umin` (PR #134235)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 8 06:45:27 PDT 2025
================
@@ -4251,6 +4251,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)) {
----------------
lukel97 wrote:
Does this work if you just do
```suggestion
// Allow types that will eventually be made legal
if (TLI.isOperationLegal(ISD::UMIN, TLI.getTypeToTransformTo(*DAG.getContext(), VT)) {
```
I feel like TLI.getTypeToTransformTo is more common in DAGCombiner than TLI.getTypeConversion. Or does that regress the i64 on rv32 tests which are expanded?
https://github.com/llvm/llvm-project/pull/134235
More information about the llvm-commits
mailing list