[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 04:18:53 PDT 2026


================
@@ -0,0 +1,74 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+;
+; Test folding of redundant early-exit guard around ctpop:
+;   select (icmp ule X, 1), X, ctpop(X)  --> ctpop(X)
+;
+; This fold is valid because ctpop(0)==0 and ctpop(1)==1, so the guard
+; is always redundant. The guard only existed to skip slow software emulation.
+
+; RUN: opt < %s -S -passes=instcombine | FileCheck %s
+
+declare i64 @llvm.ctpop.i64(i64)
----------------
sai18022001 wrote:

@dtcxzyw 
For the intrinsic declarations, `update_test_checks.py` keeps them in the output so I've left them for now. Should I remove them manually?

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


More information about the llvm-commits mailing list