[Mlir-commits] [mlir] [mlir][vector] Fix crash in `vector.extract` folder (PR #95912)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Jun 18 05:24:28 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-vector
@llvm/pr-subscribers-mlir
Author: Matthias Springer (matthias-springer)
<details>
<summary>Changes</summary>
Fix a bug in the `vector.extract` folder when the vector type is 0-d.
---
Full diff: https://github.com/llvm/llvm-project/pull/95912.diff
2 Files Affected:
- (modified) mlir/lib/Dialect/Vector/IR/VectorOps.cpp (+4-1)
- (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 58951641d33ce..5e5d3e002086a 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -1883,7 +1883,10 @@ static Value foldExtractStridedOpFromInsertChain(ExtractOp extractOp) {
}
OpFoldResult ExtractOp::fold(FoldAdaptor) {
- if (getNumIndices() == 0)
+ // Fold "vector.extract %v[] : vector<2x2xf32> from vector<2x2xf32>" to %v.
+ // Note: Do not fold "vector.extract %v[] : f32 from vector<f32>" (type
+ // mismatch).
+ if (getNumIndices() == 0 && getVector().getType() == getResult().getType())
return getVector();
if (succeeded(foldExtractOpFromExtractChain(*this)))
return getResult();
diff --git a/mlir/test/Dialect/Vector/canonicalize.mlir b/mlir/test/Dialect/Vector/canonicalize.mlir
index 22af91e0eb327..61269e3687ab3 100644
--- a/mlir/test/Dialect/Vector/canonicalize.mlir
+++ b/mlir/test/Dialect/Vector/canonicalize.mlir
@@ -2593,3 +2593,14 @@ func.func @rank_1_shuffle_to_interleave(%arg0: vector<6xi32>, %arg1: vector<6xi3
%0 = vector.shuffle %arg0, %arg1 [0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11] : vector<6xi32>, vector<6xi32>
return %0 : vector<12xi32>
}
+
+// -----
+
+// CHECK-LABEL: func @extract_from_0d_regression(
+// CHECK-SAME: %[[v:.*]]: vector<f32>)
+// CHECK: %[[extract:.*]] = vector.extract %[[v]][] : f32 from vector<f32>
+// CHECK: return %[[extract]]
+func.func @extract_from_0d_regression(%v: vector<f32>) -> f32 {
+ %0 = vector.extract %v[] : f32 from vector<f32>
+ return %0 : f32
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/95912
More information about the Mlir-commits
mailing list