[Mlir-commits] [mlir] [mlir][vector] Implement lowering for 1D vector.deinterleave operations (PR #93042)
Benjamin Maxwell
llvmlistbot at llvm.org
Thu May 23 07:40:37 PDT 2024
================
@@ -1761,6 +1761,66 @@ struct VectorInterleaveOpLowering
}
};
+/// Conversion pattern for a `vector.deinterleave`.
+/// Support available 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();
+
+ 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 resultOne = rewriter.create<LLVM::ExtractValueOp>(
+ loc, intrinsic->getResult(0), 0);
+ auto resultTwo = rewriter.create<LLVM::ExtractValueOp>(
+ loc, intrinsic->getResult(0), 1);
+
+ rewriter.replaceOp(deinterleaveOp, ValueRange{resultOne, resultTwo});
+ return success();
+ }
+
+ int64_t resultVectorSize = resultType.getNumElements();
+ auto poison = rewriter.create<LLVM::PoisonOp>(loc, sourceType);
+ SmallVector<int32_t> shuffleMaskOne;
+ SmallVector<int32_t> shuffleMaskTwo;
+
+ shuffleMaskOne.reserve(resultVectorSize);
+ shuffleMaskTwo.reserve(resultVectorSize);
+
+ for (int i = 0; i < sourceType.getNumElements(); ++i) {
+ if (i % 2 == 0)
+ shuffleMaskOne.push_back(i);
+ else
+ shuffleMaskTwo.push_back(i);
+ }
+
+ auto evenShuffle = rewriter.create<LLVM::ShuffleVectorOp>(
+ loc, adaptor.getSource(), poison, shuffleMaskOne);
+ auto oddShuffle = rewriter.create<LLVM::ShuffleVectorOp>(
+ loc, adaptor.getSource(), poison, shuffleMaskTwo);
+
+ rewriter.replaceOp(deinterleaveOp, ValueRange{evenShuffle, oddShuffle});
+ return ::success();
----------------
MacDue wrote:
nit: remove `::`
```suggestion
return success();
```
https://github.com/llvm/llvm-project/pull/93042
More information about the Mlir-commits
mailing list