[Mlir-commits] [mlir] [mlir][spirv] Implement SPIR-V lowering for `vector.deinterleave` (PR #95313)
Jakub Kuderski
llvmlistbot at llvm.org
Thu Jun 13 07:33:31 PDT 2024
================
@@ -618,6 +618,66 @@ struct VectorInterleaveOpConvert final
}
};
+struct VectorDeinterleaveOpConvert final
+ : public OpConversionPattern<vector::DeinterleaveOp> {
+ using OpConversionPattern::OpConversionPattern;
+
+ LogicalResult
+ matchAndRewrite(vector::DeinterleaveOp deinterleaveOp, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+
+ // Check the result vector type.
+ VectorType oldResultType = deinterleaveOp.getResultVectorType();
+ Type newResultType = getTypeConverter()->convertType(oldResultType);
+ if (!newResultType)
+ return rewriter.notifyMatchFailure(deinterleaveOp,
+ "unsupported result vector type");
+
+ Location loc = deinterleaveOp->getLoc();
+
+ // Deinterleave the indices.
+ Value sourceVector = adaptor.getSource();
+ VectorType sourceType = deinterleaveOp.getSourceVectorType();
+ int n = sourceType.getNumElements();
+
+ // Output vectors of size 1 are converted to scalars by the type converter.
+ // We cannot use `spirv::VectorShuffleOp` directly in this case, and need to
+ // use `spirv::CompositeExtractOp`.
+ if (n == 2) {
+ auto elem0 = rewriter.create<spirv::CompositeExtractOp>(
+ loc, newResultType, sourceVector, rewriter.getI32ArrayAttr({0}));
+
+ auto elem1 = rewriter.create<spirv::CompositeExtractOp>(
+ loc, newResultType, sourceVector, rewriter.getI32ArrayAttr({1}));
+
+ rewriter.replaceOp(deinterleaveOp, {elem0, elem1});
+ return success();
+ }
+
+ // Indices for `res1`.
+ auto seqEven = llvm::seq<int64_t>(n / 2);
+ auto indicesEven =
+ llvm::map_to_vector(seqEven, [](int i) { return i * 2; });
+
+ // Indices for `res2`.
----------------
kuhar wrote:
```suggestion
// Indices for `shuffleOdd` (result 1).
```
https://github.com/llvm/llvm-project/pull/95313
More information about the Mlir-commits
mailing list