[Mlir-commits] [mlir] [mlir][vector] Add more patterns to Vector Linearize transformation (PR #136193)
Charitha Saumya
llvmlistbot at llvm.org
Wed Apr 23 12:12:17 PDT 2025
================
@@ -273,6 +280,84 @@ struct LinearizeVectorExtractStridedSlice final
unsigned targetVectorBitWidth;
};
+// clang-format off
+/// This pattern linearizes the InsertStridedSliceOp by extracting rows from the
+/// source vector using ExtractStridedSliceOp and inserting them into the
+/// destination vector using InsertStridedSliceOp.
+/// Following,
+/// vector.insert_strided_slice %s, %d {offsets=[0, 0]}: vector<2x4xf32> into
+/// vector<4x4xf32>
+/// is converted to :
+/// %0 = vector.extract_strided_slice %s {offsets=[0], sizes=[4], strides=[1]}
+/// : vector<4xf32> from vector<8xf32>
+/// %1 = vector.insert_strided_slice %0, %d {offsets=[0], strides=[1]}
+/// : vector<4xf32> into vector<16xf32>
+/// %2 = vector.extract_strided_slice %s {offsets=[4], sizes=[4], strides=[1]}
+/// : vector<4xf32> from vector<8xf32>
+/// %3 = vector.insert_strided_slice %2, %1 {offsets=[4], strides=[1]}
+/// : vector<4xf32> into vector<16xf32>
+// clang-format on
+struct LinearizeVectorInsertStridedSlice final
+ : public OpConversionPattern<vector::InsertStridedSliceOp> {
+ using OpConversionPattern<vector::InsertStridedSliceOp>::OpConversionPattern;
+ LinearizeVectorInsertStridedSlice(
+ const TypeConverter &typeConverter, MLIRContext *context,
+ unsigned targetVectBitWidth = defaultTargetVectorBitWidth,
+ PatternBenefit benefit = 1)
+ : OpConversionPattern(typeConverter, context, benefit),
+ targetVectorBitWidth(targetVectBitWidth) {}
+
+ LogicalResult
+ matchAndRewrite(vector::InsertStridedSliceOp insertOp, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+ auto loc = insertOp.getLoc();
+ auto srcTy = insertOp.getSourceVectorType();
+ auto dstTy = insertOp.getDestVectorType();
+
+ if (insertOp.hasNonUnitStrides())
+ return rewriter.notifyMatchFailure(
+ insertOp,
+ "InsertStridedSliceOp linearization only supports unit strides.");
+
+ if (srcTy.getRank() != 2)
+ return rewriter.notifyMatchFailure(
+ insertOp,
+ "InsertStridedSliceOp linearization only supports 2D source.");
----------------
charithaintc wrote:
any reason for supporting only 2D?
https://github.com/llvm/llvm-project/pull/136193
More information about the Mlir-commits
mailing list