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

Henrich Lauko via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 5 06:58:46 PDT 2025


================
@@ -1883,6 +1884,60 @@ mlir::LogicalResult CIRToLLVMVecCmpOpLowering::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());
----------------
xlauko wrote:

I believe the cast is no longer needed:
```suggestion
  const cir::VectorType vecTy = op.getType();
```

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


More information about the cfe-commits mailing list