[clang] [CIR] Lower bitwise vector reduce builtins (PR #201164)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 22 10:53:05 PDT 2026


================
@@ -1704,6 +1701,27 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
   case Builtin::BI__builtin_masked_compress_store:
   case Builtin::BI__builtin_masked_scatter:
     return errorBuiltinNYI(*this, e, builtinID);
+  case Builtin::BI__builtin_reduce_xor: {
+    mlir::Value arg = emitScalarExpr(e->getArg(0));
+    cir::VectorType vecTy = cast<cir::VectorType>(arg.getType());
+    return RValue::get(builder.emitIntrinsicCallOp(
----------------
adams381 wrote:

Done, all three go through the helper now.

On `convertType`: it's not doing anything surprising, it just hands back the vector type (`!cir.vector<4 x !s32i>`). The catch is the helper uses that as the result type, and the reduce intrinsics return the element type, not the vector. Classic gets away without an explicit type because `getIntrinsic(ID, argTy)` reads the result off the intrinsic signature, and we don't have an intrinsic registry to do that. So I gave the helper an optional result type (defaults to `convertType(arg0)`, so the existing callers don't change) and pass the element type from the reduce cases. Helper's used and the nested switch is gone.


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


More information about the cfe-commits mailing list