[clang] [CIR] Upstream splat op for VectorType (PR #139827)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Thu May 15 10:31:38 PDT 2025


================
@@ -1773,6 +1774,38 @@ mlir::LogicalResult CIRToLLVMVecInsertOpLowering::matchAndRewrite(
   return mlir::success();
 }
 
+mlir::LogicalResult CIRToLLVMVecSplatOpLowering::matchAndRewrite(
+    cir::VecSplatOp op, OpAdaptor adaptor,
+    mlir::ConversionPatternRewriter &rewriter) const {
+  // Vector splat can be implemented with an `insertelement` and a
+  // `shufflevector`, which is better than an `insertelement` for each
+  // element in the vector. Start with an undef vector. Insert the value into
+  // the first element. Then use a `shufflevector` with a mask of all 0 to
+  // fill out the entire vector with that value.
+  const auto vecTy = mlir::cast<cir::VectorType>(op.getType());
+  const mlir::Type llvmTy = typeConverter->convertType(vecTy);
+  const mlir::Location loc = op.getLoc();
+  const mlir::Value poison = rewriter.create<mlir::LLVM::PoisonOp>(loc, llvmTy);
----------------
andykaylor wrote:

Because of the way MLIR value semantics work, using `const` here doesn't really make sense. This applies throughout this function for mlir::Value.

See https://mlir.llvm.org/docs/Rationale/UsageOfConst/

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


More information about the cfe-commits mailing list