[Mlir-commits] [mlir] [mlir][vector] Add 1D vector.deinterleave lowering (PR #93042)
Cullen Rhodes
llvmlistbot at llvm.org
Wed May 29 02:39:46 PDT 2024
================
@@ -1761,6 +1761,70 @@ struct VectorInterleaveOpLowering
}
};
+/// Conversion pattern for a `vector.deinterleave`.
+/// This supports for fixed-sized vectors and scalable vectors.
+struct VectorDeinterleaveOpLowering
+ : public ConvertOpToLLVMPattern<vector::DeinterleaveOp> {
+ using ConvertOpToLLVMPattern::ConvertOpToLLVMPattern;
+
+ LogicalResult
+ matchAndRewrite(vector::DeinterleaveOp deinterleaveOp, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+ VectorType resultType = deinterleaveOp.getResultVectorType();
+ VectorType sourceType = deinterleaveOp.getSourceVectorType();
+ auto loc = deinterleaveOp.getLoc();
+
+ // Note: n-D deinterleave operations should be lowered to the 1-D before
+ // converting to LLVM.
+ if (resultType.getRank() != 1)
+ return rewriter.notifyMatchFailure(deinterleaveOp,
+ "DeinterleaveOp not rank 1");
+
+ if (resultType.isScalable()) {
+ auto llvmTypeConverter = this->getTypeConverter();
+ auto deinterleaveResults = deinterleaveOp.getResultTypes();
+ auto packedOpResults =
+ llvmTypeConverter->packOperationResults(deinterleaveResults);
+ auto intrinsic = rewriter.create<LLVM::vector_deinterleave2>(
+ loc, packedOpResults, adaptor.getSource());
+
+ auto evenResult = rewriter.create<LLVM::ExtractValueOp>(
+ loc, intrinsic->getResult(0), 0);
+ auto oddResult = rewriter.create<LLVM::ExtractValueOp>(
+ loc, intrinsic->getResult(0), 1);
+
+ rewriter.replaceOp(deinterleaveOp, ValueRange{evenResult, oddResult});
+ return success();
+ }
+ // Lower fixed-size deinterleave to two shufflevectors. While the
+ // vector.deinterleave2 intrinsic supports fixed and scalable vectors, the
+ // langref still recommends fixed-vectors use shufflevector, see:
+ // https://llvm.org/docs/LangRef.html#id889.
+ int64_t resultVectorSize = resultType.getNumElements();
+ SmallVector<int32_t> evenShuffleMask;
+ SmallVector<int32_t> oddShuffleMask;
+
+ evenShuffleMask.reserve(resultVectorSize);
+ oddShuffleMask.reserve(resultVectorSize);
----------------
c-rhodes wrote:
this should be half width?
```suggestion
evenShuffleMask.reserve(resultVectorSize / 2);
oddShuffleMask.reserve(resultVectorSize / 2);
```
https://github.com/llvm/llvm-project/pull/93042
More information about the Mlir-commits
mailing list