[Mlir-commits] [mlir] [mlir] Add support for vector.store sub-byte emulation. (PR #70293)
Han-Chung Wang
llvmlistbot at llvm.org
Wed Nov 1 17:23:26 PDT 2023
================
@@ -34,6 +34,70 @@ using namespace mlir;
namespace {
+//===----------------------------------------------------------------------===//
+// ConvertVectorStore
+//===----------------------------------------------------------------------===//
+
+struct ConvertVectorStore final : OpConversionPattern<vector::StoreOp> {
+ using OpConversionPattern::OpConversionPattern;
+
+ LogicalResult
+ matchAndRewrite(vector::StoreOp op, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+
+ auto loc = op.getLoc();
+ auto convertedType = cast<MemRefType>(adaptor.getBase().getType());
+ Type oldElementType = op.getValueToStore().getType().getElementType();
+ Type newElementType = convertedType.getElementType();
+ int srcBits = oldElementType.getIntOrFloatBitWidth();
+ int dstBits = newElementType.getIntOrFloatBitWidth();
+
+ if (dstBits % srcBits != 0) {
+ return rewriter.notifyMatchFailure(
+ op, "only dstBits % srcBits == 0 supported");
+ }
+ int scale = dstBits / srcBits;
+
+ // Adjust the number of elements to store when emulating narrow types.
+ // Here only the 1-D vector load is considered, and the N-D memref types
+ // should be linearized.
+ // For example, to emulate i4 to i8, the following op:
+ //
+ // vector.store %arg1, %0[%arg2, %arg3] :memref<4x8xi4>, vector<8xi4>
+ //
+ // can be replaced with
+ //
+ // vector.store %bitcast_arg1, %alloc[%linear_index] : memref<16xi8>,
----------------
hanhanW wrote:
Can you add bitcast op to the comment? Is the comment correct? I thought it should be
```
// %bitcast = vector.bitcast ... vector<8xi4> to vector<4xi8>
// vector.store .... : memref<16xi8>, vector<4xi8>
```
https://github.com/llvm/llvm-project/pull/70293
More information about the Mlir-commits
mailing list