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

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun May 3 04:33:26 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)
----------------
dtcxzyw wrote:

> For the intrinsic declarations, update_test_checks.py keeps them in the output

It is a bit weird. `update_test_checks.py` should only touch check lines. You can drop these declarations and existing check lines, then re-run the update script.

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


More information about the llvm-commits mailing list