[llvm] [InstCombine] Fold redundant select guards for ctpop (PR #195443)

Sai Sanjay Chikne via llvm-commits llvm-commits at lists.llvm.org
Sun May 3 08:42:50 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))) &&
----------------
sai18022001 wrote:

updated to 'if (match(FalseVal, m_Ctpop(m_Specific(TrueVal))) &&'

https://github.com/llvm/llvm-project/pull/195443


More information about the llvm-commits mailing list