@@ -220,6 +220,32 @@ struct VectorFmaOpConvert final : public OpConversionPattern<vector::FMAOp> {
220
220
}
221
221
};
222
222
223
+ struct VectorFromElementsOpConvert final
224
+ : public OpConversionPattern<vector::FromElementsOp> {
225
+ using OpConversionPattern::OpConversionPattern;
226
+
227
+ LogicalResult
228
+ matchAndRewrite (vector::FromElementsOp op, OpAdaptor adaptor,
229
+ ConversionPatternRewriter &rewriter) const override {
230
+ Type resultType = getTypeConverter ()->convertType (op.getType ());
231
+ if (!resultType)
232
+ return failure ();
233
+ OperandRange elements = op.getElements ();
234
+ if (isa<spirv::ScalarType>(resultType)) {
235
+ // In the case with a single scalar operand / single-element result,
236
+ // pass through the scalar.
237
+ rewriter.replaceOp (op, elements[0 ]);
238
+ return success ();
239
+ }
240
+ // SPIRVTypeConverter rejects vectors with rank > 1, so multi-dimensional
241
+ // vector.from_elements cases should not need to be handled, only 1d.
242
+ assert (cast<VectorType>(resultType).getRank () == 1 );
243
+ rewriter.replaceOpWithNewOp <spirv::CompositeConstructOp>(op, resultType,
244
+ elements);
245
+ return success ();
246
+ }
247
+ };
248
+
223
249
struct VectorInsertOpConvert final
224
250
: public OpConversionPattern<vector::InsertOp> {
225
251
using OpConversionPattern::OpConversionPattern;
@@ -952,8 +978,9 @@ void mlir::populateVectorToSPIRVPatterns(
952
978
VectorBitcastConvert, VectorBroadcastConvert,
953
979
VectorExtractElementOpConvert, VectorExtractOpConvert,
954
980
VectorExtractStridedSliceOpConvert, VectorFmaOpConvert<spirv::GLFmaOp>,
955
- VectorFmaOpConvert<spirv::CLFmaOp>, VectorInsertElementOpConvert,
956
- VectorInsertOpConvert, VectorReductionPattern<GL_INT_MAX_MIN_OPS>,
981
+ VectorFmaOpConvert<spirv::CLFmaOp>, VectorFromElementsOpConvert,
982
+ VectorInsertElementOpConvert, VectorInsertOpConvert,
983
+ VectorReductionPattern<GL_INT_MAX_MIN_OPS>,
957
984
VectorReductionPattern<CL_INT_MAX_MIN_OPS>,
958
985
VectorReductionFloatMinMax<CL_FLOAT_MAX_MIN_OPS>,
959
986
VectorReductionFloatMinMax<GL_FLOAT_MAX_MIN_OPS>, VectorShapeCast,
0 commit comments