[llvm] [InstCombine] Match a new form of truncating saturation (PR #189703)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 2 07:55:16 PDT 2026
================
@@ -1171,6 +1171,33 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
}
}
+ // trunc (select(icmp_ult(A, DestTy_umax+1), A, sext(icmp_sgt(A, 0)))) -->
+ // trunc (smin(smax(0, A), DestTy_umax))
+ if (SrcTy->isIntegerTy() && isPowerOf2_64(SrcTy->getPrimitiveSizeInBits()) &&
+ DestTy->isIntegerTy() &&
+ isPowerOf2_64(DestTy->getPrimitiveSizeInBits()) &&
+ match(Src,
+ m_OneUse(m_Select(
+ m_SpecificICmp(ICmpInst::ICMP_ULT, m_Value(A), m_Constant(C)),
----------------
david-arm wrote:
Should we also be checking for one use of both compares? Not sure if the transformation is worth it for multiple uses.
https://github.com/llvm/llvm-project/pull/189703
More information about the llvm-commits
mailing list