[Mlir-commits] [mlir] [mlir][vector] Fix out-of-bounds access (PR #126734)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Feb 11 06:17:52 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-vector
Author: Longsheng Mou (CoTinker)
<details>
<summary>Changes</summary>
This PR fixes an out-of-bounds bug that occurs when there are no unit dimensions in the source of `vector.extract_strided_slice`, causing access to `sizes` to go out of bounds. Fixes #<!-- -->126196.
---
Full diff: https://github.com/llvm/llvm-project/pull/126734.diff
2 Files Affected:
- (modified) mlir/lib/Dialect/Vector/IR/VectorOps.cpp (+2-2)
- (modified) mlir/test/Dialect/Vector/canonicalize.mlir (+11)
``````````diff
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index 30ff2df7c38fc3..f3f20b46add783 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -3968,8 +3968,8 @@ class ContiguousExtractStridedSliceToExtract final
// Avoid generating slices that have leading unit dimensions. The shape_cast
// op that we create below would take bad generic fallback patterns
// (ShapeCastOpRewritePattern).
- while (sizes[numOffsets] == 1 &&
- numOffsets < static_cast<int>(sizes.size()) - 1) {
+ while (numOffsets < static_cast<int>(sizes.size()) - 1 &&
+ sizes[numOffsets] == 1) {
++numOffsets;
}
diff --git a/mlir/test/Dialect/Vector/canonicalize.mlir b/mlir/test/Dialect/Vector/canonicalize.mlir
index 61e858f5f226a1..0fc0140666696f 100644
--- a/mlir/test/Dialect/Vector/canonicalize.mlir
+++ b/mlir/test/Dialect/Vector/canonicalize.mlir
@@ -2932,6 +2932,17 @@ func.func @contiguous_extract_strided_slices_to_extract(%arg0 : vector<8x1x2x1x1
// -----
+// CHECK-LABEL: @contiguous_extract_strided_slices_to_extract_no_unit_dims
+// CHECK: %[[EXTRACT:.+]] = vector.extract {{.*}}[0, 0] : vector<4xi32> from vector<8x2x4xi32>
+// CHECK-NEXT: return %[[EXTRACT]] : vector<4xi32>
+func.func @contiguous_extract_strided_slices_to_extract_no_unit_dims(%arg0 : vector<8x2x4xi32>) -> vector<4xi32> {
+ %1 = vector.extract_strided_slice %arg0 {offsets = [0, 0], sizes = [1, 1], strides = [1, 1]} : vector<8x2x4xi32> to vector<1x1x4xi32>
+ %2 = vector.shape_cast %1 : vector<1x1x4xi32> to vector<4xi32>
+ return %2 : vector<4xi32>
+}
+
+// -----
+
// CHECK-LABEL: @contiguous_extract_strided_slices_to_extract_shorter_size_list
// CHECK: %[[EXTRACT:.+]] = vector.extract {{.*}}[0, 0, 0, 0] : vector<1x4xi32> from vector<8x1x2x1x1x4xi32>
// CHECK-NEXT: return %[[EXTRACT]] : vector<1x4xi32>
``````````
</details>
https://github.com/llvm/llvm-project/pull/126734
More information about the Mlir-commits
mailing list