[Mlir-commits] [mlir] [mlir][spirv][vector] Support converting vector.from_elements to SPIR-V (PR #118540)
Jakub Kuderski
llvmlistbot at llvm.org
Tue Dec 3 14:21:52 PST 2024
================
@@ -220,6 +220,34 @@ struct VectorFmaOpConvert final : public OpConversionPattern<vector::FMAOp> {
}
};
+struct VectorFromElementsOpConvert final
+ : public OpConversionPattern<vector::FromElementsOp> {
+ using OpConversionPattern::OpConversionPattern;
+
+ LogicalResult
+ matchAndRewrite(vector::FromElementsOp op, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+ Type resultType = getTypeConverter()->convertType(op.getType());
+ auto elements = op.getElements();
+ if (!resultType)
+ return failure();
+ if (isa<spirv::ScalarType>(resultType)) {
+ // In the case with a single scalar operand / single-element result,
+ // pass through the scalar.
+ rewriter.replaceOp(op, elements[0]);
+ return success();
+ } else if (cast<VectorType>(resultType).getRank() == 1) {
+ // SPIRVTypeConverter rejects vectors with rank > 1, so the
+ // multi-dimensional vector.from_elements cases do not need to be handled,
+ // only a simple flat vector.
+ rewriter.replaceOpWithNewOp<spirv::CompositeConstructOp>(op, resultType,
+ elements);
+ return success();
+ }
+ return failure();
----------------
kuhar wrote:
I don't think we need this `return` -- this code seems unreachable to me
https://github.com/llvm/llvm-project/pull/118540
More information about the Mlir-commits
mailing list