[llvm] [InstCombine] Fold redundant select guards for ctpop (PR #195443)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Sun May 3 06:19:48 PDT 2026
================
@@ -4317,6 +4317,16 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
if (Instruction *I = canonicalizeScalarSelectOfVecs(SI, *this))
return I;
+ // Fold: select (icmp ult X, 2), X, ctpop(X) --> ctpop(X)
+ // ctpop(0)==0 and ctpop(1)==1, so the guard is always redundant.
+ if (match(FalseVal, m_Intrinsic<Intrinsic::ctpop>(m_Specific(TrueVal))) &&
----------------
RKSimon wrote:
If you update to trunk latest you should be able to use the m_ Ctpop matcher now
https://github.com/llvm/llvm-project/pull/195443
More information about the llvm-commits
mailing list