[llvm] [InstCombine] Fold zext-add/sub-min/max-trunc to uadd.sat or usub.sat (PR #185259)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 27 03:40:42 PDT 2026
================
@@ -1086,6 +1086,28 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
Value *A, *B;
Constant *C;
+
+ // trunc(u/smin(zext(a) + zext(b), MAX)) --> uadd.sat(a, b)
+ if (match(Src,
+ m_OneUse(m_CombineOr(
+ m_UMin(m_OneUse(m_Add(m_ZExt(m_Value(A)), m_ZExt(m_Value(B)))),
+ m_SpecificInt(APInt::getMaxValue(DestWidth))),
+ m_SMin(m_OneUse(m_Add(m_ZExt(m_Value(A)), m_ZExt(m_Value(B)))),
+ m_SpecificInt(APInt::getMaxValue(DestWidth)))))) &&
----------------
nikic wrote:
I'm kind of surprised this is necessary. I would have thought we have a smin->umin canonicalization for non-negative operands, but apparently we don't.
https://github.com/llvm/llvm-project/pull/185259
More information about the llvm-commits
mailing list