[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:51 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) {
----------------
kuhar wrote:
We don't put `else` after `return`: https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return
Also, I think we don't need this if because there are only two cases: scalar and 1d with 2 or more elements. Everything else should be rejected by the type converter.
https://github.com/llvm/llvm-project/pull/118540
More information about the Mlir-commits
mailing list