aboutsummaryrefslogtreecommitdiff
path: root/mlir
diff options
context:
space:
mode:
authorMatthias Springer <me@m-sp.org>2024-06-18 14:54:31 +0200
committerGitHub <noreply@github.com>2024-06-18 14:54:31 +0200
commit55d5c032fc9fd3aeba82cdc5dfc82b2a32f34d4f (patch)
tree13cf0b46fe034941e95d4aafdf51b32554b5d42e /mlir
parente42a4c70a112c1c0f07ccb8b57b4fda4cfa11b49 (diff)
downloadllvm-55d5c032fc9fd3aeba82cdc5dfc82b2a32f34d4f.zip
llvm-55d5c032fc9fd3aeba82cdc5dfc82b2a32f34d4f.tar.gz
llvm-55d5c032fc9fd3aeba82cdc5dfc82b2a32f34d4f.tar.bz2
[mlir][vector] Fix crash in `vector.extract` folder (#95912)
Fix a bug in the `vector.extract` folder when the vector type is 0-d.
Diffstat (limited to 'mlir')
-rw-r--r--mlir/lib/Dialect/Vector/IR/VectorOps.cpp5
-rw-r--r--mlir/test/Dialect/Vector/canonicalize.mlir11
2 files changed, 15 insertions, 1 deletions
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index 5895164..5e5d3e0 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 22af91e..61269e3 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
+}