[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);
+
+ const mlir::Value elementValue = adaptor.getValue();
----------------
andykaylor wrote:
Can we use something like `llvm.mlir.constant(dense<1.0> : vector<4xf32>) : vector<4xf32>` if elementValue is a constant?
I see that this will end up getting lowered to the correct `splat` constant in LLVM IR, but it seems like we should be representing that somehow in the LLVM dialect also.
https://github.com/llvm/llvm-project/pull/139827
More information about the cfe-commits
mailing list