[MemRef] Implement value bounds interface for ExpandShapeOp#164438
Merged
Conversation
Member
|
@llvm/pr-subscribers-mlir-memref @llvm/pr-subscribers-mlir Author: Jorn Tuyls (jtuyls) ChangesFull diff: https://github.com/llvm/llvm-project/pull/164438.diff 2 Files Affected:
diff --git a/mlir/lib/Dialect/MemRef/IR/ValueBoundsOpInterfaceImpl.cpp b/mlir/lib/Dialect/MemRef/IR/ValueBoundsOpInterfaceImpl.cpp
index 11400de35e430..a15bf891dd596 100644
--- a/mlir/lib/Dialect/MemRef/IR/ValueBoundsOpInterfaceImpl.cpp
+++ b/mlir/lib/Dialect/MemRef/IR/ValueBoundsOpInterfaceImpl.cpp
@@ -59,6 +59,17 @@ struct DimOpInterface
}
};
+struct ExpandShapeOpInterface
+ : public ValueBoundsOpInterface::ExternalModel<ExpandShapeOpInterface,
+ memref::ExpandShapeOp> {
+ void populateBoundsForShapedValueDim(Operation *op, Value value, int64_t dim,
+ ValueBoundsConstraintSet &cstr) const {
+ auto expandOp = cast<memref::ExpandShapeOp>(op);
+ assert(value == expandOp.getResult() && "invalid value");
+ cstr.bound(value)[dim] == expandOp.getOutputShape()[dim];
+ }
+};
+
struct GetGlobalOpInterface
: public ValueBoundsOpInterface::ExternalModel<GetGlobalOpInterface,
GetGlobalOp> {
@@ -123,6 +134,8 @@ void mlir::memref::registerValueBoundsOpInterfaceExternalModels(
memref::AllocOpInterface<memref::AllocaOp>>(*ctx);
memref::CastOp::attachInterface<memref::CastOpInterface>(*ctx);
memref::DimOp::attachInterface<memref::DimOpInterface>(*ctx);
+ memref::ExpandShapeOp::attachInterface<memref::ExpandShapeOpInterface>(
+ *ctx);
memref::GetGlobalOp::attachInterface<memref::GetGlobalOpInterface>(*ctx);
memref::RankOp::attachInterface<memref::RankOpInterface>(*ctx);
memref::SubViewOp::attachInterface<memref::SubViewOpInterface>(*ctx);
diff --git a/mlir/test/Dialect/MemRef/value-bounds-op-interface-impl.mlir b/mlir/test/Dialect/MemRef/value-bounds-op-interface-impl.mlir
index 8bd7ae8df9049..ac1f22b68b1e1 100644
--- a/mlir/test/Dialect/MemRef/value-bounds-op-interface-impl.mlir
+++ b/mlir/test/Dialect/MemRef/value-bounds-op-interface-impl.mlir
@@ -63,6 +63,20 @@ func.func @memref_dim_all_positive(%m: memref<?xf32>, %x: index) {
// -----
+// CHECK-LABEL: func @memref_expand(
+// CHECK-SAME: %[[m:[a-zA-Z0-9]+]]: memref<?xf32>
+// CHECK-SAME: %[[sz:[a-zA-Z0-9]+]]: index
+// CHECK: %[[c4:.*]] = arith.constant 4 : index
+// CHECK: return %[[sz]], %[[c4]]
+func.func @memref_expand(%m: memref<?xf32>, %sz: index) -> (index, index) {
+ %0 = memref.expand_shape %m [[0, 1]] output_shape [%sz, 4]: memref<?xf32> into memref<?x4xf32>
+ %1 = "test.reify_bound"(%0) {dim = 0} : (memref<?x4xf32>) -> (index)
+ %2 = "test.reify_bound"(%0) {dim = 1} : (memref<?x4xf32>) -> (index)
+ return %1, %2 : index, index
+}
+
+// -----
+
// CHECK-LABEL: func @memref_get_global(
// CHECK: %[[c4:.*]] = arith.constant 4 : index
// CHECK: return %[[c4]]
|
matthias-springer
approved these changes
Oct 23, 2025
Member
matthias-springer
left a comment
There was a problem hiding this comment.
Thanks, it would be great to support collapse_shape as well.
Contributor
Author
Sure, I can implement |
dvbuka
pushed a commit
to dvbuka/llvm-project
that referenced
this pull request
Oct 27, 2025
Lukacma
pushed a commit
to Lukacma/llvm-project
that referenced
this pull request
Oct 29, 2025
matthias-springer
pushed a commit
that referenced
this pull request
Dec 24, 2025
…pseShapeOp (#173356) Mirroring #164438 and #164955 --------- Signed-off-by: Yu-Zhewen <[email protected]>
llvm-sync Bot
pushed a commit
to arm/arm-toolchain
that referenced
this pull request
Dec 24, 2025
…p and CollapseShapeOp (#173356) Mirroring llvm/llvm-project#164438 and llvm/llvm-project#164955 --------- Signed-off-by: Yu-Zhewen <[email protected]>
mahesh-attarde
pushed a commit
to mahesh-attarde/llvm-project
that referenced
this pull request
Jan 6, 2026
…pseShapeOp (llvm#173356) Mirroring llvm#164438 and llvm#164955 --------- Signed-off-by: Yu-Zhewen <[email protected]>
navaneethshan
pushed a commit
to qualcomm/cpullvm-toolchain
that referenced
this pull request
Jan 8, 2026
…pseShapeOp (#173356) Mirroring llvm/llvm-project#164438 and llvm/llvm-project#164955 --------- Signed-off-by: Yu-Zhewen <[email protected]>
navaneethshan
pushed a commit
to qualcomm/cpullvm-toolchain
that referenced
this pull request
Jan 9, 2026
…pseShapeOp (#173356) Mirroring llvm/llvm-project#164438 and llvm/llvm-project#164955 --------- Signed-off-by: Yu-Zhewen <[email protected]> (cherry picked from commit 5154a05)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.