[clang] [Clang] Support generic bit counting builtins on fixed boolean vectors (PR #154203)

John McCall via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 21 11:05:20 PDT 2025


================
@@ -1693,6 +1693,22 @@ getBitTestAtomicOrdering(BitTest::InterlockingKind I) {
   llvm_unreachable("invalid interlocking");
 }
 
+static llvm::Value *EmitIntegerExpr(CodeGenFunction &CGF, const Expr *E) {
+  llvm::Value *ArgValue = CGF.EmitScalarExpr(E);
+  llvm::Type *ArgType = ArgValue->getType();
+
+  if (auto *VT = dyn_cast<llvm::FixedVectorType>(ArgType);
+      VT && VT->getElementType()->isIntegerTy(1)) {
+    llvm::Type *StorageType = CGF.ConvertTypeForMem(E->getType());
+    ArgValue = CGF.emitBoolVecConversion(
+        ArgValue, StorageType->getPrimitiveSizeInBits(), "insertvec");
+    ArgValue = CGF.Builder.CreateBitCast(ArgValue, StorageType);
----------------
rjmccall wrote:

LLVM may let you just `bitcast` directly to `iN`, which would both avoid the poison problem and let you avoid making any adjustments. Otherwise yeah, you'll need to extend with an actual zero and then  subtract off the excess.

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


More information about the cfe-commits mailing list