[llvm] [LLVM][CodeGen][AArch64] Improve lowering of boolean vector popcount operations. (PR #166401)

Graham Hunter via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 4 09:10:26 PST 2025


================
@@ -27878,6 +27881,34 @@ static SDValue performRNDRCombine(SDNode *N, SelectionDAG &DAG) {
       {A, DAG.getZExtOrTrunc(B, DL, MVT::i1), A.getValue(2)}, DL);
 }
 
+static SDValue performCTPOPCombine(SDNode *N,
+                                   TargetLowering::DAGCombinerInfo &DCI,
+                                   SelectionDAG &DAG) {
+  using namespace llvm::SDPatternMatch;
+  if (!DCI.isBeforeLegalize())
+    return SDValue();
+
+  // ctpop(zext(bitcast(vector_mask))) -> neg(signed_reduce_add(vector_mask))
+  SDValue Mask;
+  if (sd_match(N->getOperand(0), m_ZExt(m_BitCast(m_Value(Mask))))) {
----------------
huntergr-arm wrote:

Perhaps better as an early exit with !sd_match.

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


More information about the llvm-commits mailing list