[Mlir-commits] [mlir] [mlir][vector][spirv] Lower `vector.to_elements` to SPIR-V (PR #146618)
Eric Feng
llvmlistbot at llvm.org
Wed Jul 2 11:35:14 PDT 2025
================
@@ -1022,6 +1022,49 @@ struct VectorStepOpConvert final : OpConversionPattern<vector::StepOp> {
}
};
+struct VectorToElementOpConvert final
+ : OpConversionPattern<vector::ToElementsOp> {
+ using OpConversionPattern::OpConversionPattern;
+
+ LogicalResult
+ matchAndRewrite(vector::ToElementsOp toElementsOp, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+
+ SmallVector<Value> results(toElementsOp->getNumResults());
+ Location loc = toElementsOp.getLoc();
+
+ // Input vectors of size 1 are converted to scalars by the type converter.
+ // We cannot use `spirv::CompositeExtractOp` directly in this case.
+ // For a scalar source, the result is just the scalar itself.
+ if (isa<spirv::ScalarType>(adaptor.getSource().getType())) {
+ results[0] = adaptor.getSource();
+ rewriter.replaceOp(toElementsOp, results);
+ return success();
+ }
+
+ Type srcElementType = toElementsOp.getElements().getType().front();
+ Type elementType = getTypeConverter()->convertType(srcElementType);
+ if (!elementType)
+ return rewriter.notifyMatchFailure(
+ toElementsOp, "unsupported element type in source vector");
----------------
efric wrote:
That's right, though technically they are the same right. I was thinking something along the lines of "the type of elements from the source vector was not able to be converted" but it does seem confusing in hindsight. Changed it to be more specific.
https://github.com/llvm/llvm-project/pull/146618
More information about the Mlir-commits
mailing list