[Mlir-commits] [mlir] [MLIR] VectorEmulateNarrowType to support loading of unaligned vectors (PR #113411)
Han-Chung Wang
llvmlistbot at llvm.org
Thu Oct 24 12:57:32 PDT 2024
================
@@ -102,6 +124,41 @@ static FailureOr<Operation *> getCompressedMaskOp(OpBuilder &rewriter,
return newMask;
}
+static std::optional<int64_t>
+getFrontPaddingSize(ConversionPatternRewriter &rewriter, Location loc,
+ const memref::LinearizedMemRefInfo linearizedInfo,
+ bool isUnalignedEmulation) {
+ if (!isUnalignedEmulation)
+ return 0;
+ auto foldedFrontPaddingSize = getValueOrCreateConstantIndexOp(
+ rewriter, loc, linearizedInfo.frontPaddingSize);
+ // try to fold the front padding size into a constant
+ if (auto frontPadding = dyn_cast_or_null<arith::ConstantIndexOp>(
+ foldedFrontPaddingSize.getDefiningOp())) {
+ return frontPadding.value();
+ }
+ return std::nullopt;
+}
+
+static Value extractSubvectorFrom(ConversionPatternRewriter &rewriter,
+ Location loc, VectorType extractType,
+ Value vector, int64_t frontOffset,
+ int64_t subvecSize) {
+ return rewriter
+ .create<vector::ExtractStridedSliceOp>(
+ loc, extractType, vector, rewriter.getI64ArrayAttr({frontOffset}),
+ rewriter.getI64ArrayAttr({subvecSize}), rewriter.getI64ArrayAttr({1}))
+ ->getResult(0);
----------------
hanhanW wrote:
optional: I'd declare few variables to make readability better. E.g.,
```mlir
auto offsets = rewriter.getI64ArrayAttr({frontOffset};
auto sizes = ...;
auto strides = ...;
return rewriter.create...; // without ->getResult(0).
```
https://github.com/llvm/llvm-project/pull/113411
More information about the Mlir-commits
mailing list