[Mlir-commits] [mlir] 24a8092 - [MLIR] Avoid `vector.extract_strided_slice` when not needed (#115941)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Nov 12 13:59:01 PST 2024


Author: lialan
Date: 2024-11-12T13:58:58-08:00
New Revision: 24a8092be7c1700e9bcdb15c114e9a738f0a2a6b

URL: https://github.com/llvm/llvm-project/commit/24a8092be7c1700e9bcdb15c114e9a738f0a2a6b
DIFF: https://github.com/llvm/llvm-project/commit/24a8092be7c1700e9bcdb15c114e9a738f0a2a6b.diff

LOG: [MLIR] Avoid `vector.extract_strided_slice` when not needed (#115941)

In `staticallyExtractSubvector`, When the extracting slice is the same
as source vector, do not need to emit `vector.extract_strided_slice`.

This fixes the lit test case `@vector_store_i4` in
`mlir\test\Dialect\Vector\vector-emulate-narrow-type.mlir`, where
converting from `vector<8xi4>` to `vector<4xi8>` does not need slice
extraction.

The issue was introduced in #113411 and #115070, CI failure link:
https://buildkite.com/llvm-project/github-pull-requests/builds/118845

This PR does not include a lit test case because it is a fix and the
above mentioned `@vector_store_i4` test actually tests the mechanism.

Signed-off-by: Alan Li <me at alanli.org>

Added: 
    

Modified: 
    mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp
index bb0731d768dfa7..eb4ce24548e603 100644
--- a/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp
@@ -150,6 +150,13 @@ static Value staticallyExtractSubvector(OpBuilder &rewriter, Location loc,
   assert((vectorType.getRank() == 1 && extractType.getRank() == 1) &&
          "expected 1-D source and destination types");
   (void)vectorType;
+  assert(frontOffset + subvecSize <= vectorType.getNumElements() &&
+         "subvector out of bounds");
+
+  // do not need extraction if the subvector size is the same as the source
+  if (vectorType.getNumElements() == subvecSize)
+    return source;
+
   auto offsets = rewriter.getI64ArrayAttr({frontOffset});
   auto sizes = rewriter.getI64ArrayAttr({subvecSize});
   auto strides = rewriter.getI64ArrayAttr({1});


        


More information about the Mlir-commits mailing list