[Mlir-commits] [mlir] f1ad1f0 - [mlir][ValueBounds] Skip analysis for identical slice components (#226894)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Sep 30 17:06:10 PDT 2026
Author: Ziliang Zhang
Date: 2026-10-01T09:06:03+09:00
New Revision: f1ad1f04e39a0f49ff9d9b78fba895a7102ef765
URL: https://github.com/llvm/llvm-project/commit/f1ad1f04e39a0f49ff9d9b78fba895a7102ef765
DIFF: https://github.com/llvm/llvm-project/commit/f1ad1f04e39a0f49ff9d9b78fba895a7102ef765.diff
LOG: [mlir][ValueBounds] Skip analysis for identical slice components (#226894)
One-Shot Bufferize repeatedly compares subset slices whose offsets,
sizes, and strides often reuse the same SSA values and attributes. Avoid
constructing a ValueBounds constraint set when the two OpFoldResults are
already identical, while preserving the existing solver fallback for
distinct values.
Added:
Modified:
mlir/lib/Interfaces/ValueBoundsOpInterface.cpp
mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-analysis.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Interfaces/ValueBoundsOpInterface.cpp b/mlir/lib/Interfaces/ValueBoundsOpInterface.cpp
index d6d3b4d43cb55..d998104e99f4a 100644
--- a/mlir/lib/Interfaces/ValueBoundsOpInterface.cpp
+++ b/mlir/lib/Interfaces/ValueBoundsOpInterface.cpp
@@ -872,6 +872,10 @@ FailureOr<bool> ValueBoundsConstraintSet::strongCompare(const Variable &lhs,
FailureOr<bool> ValueBoundsConstraintSet::areEqual(const Variable &var1,
const Variable &var2) {
+ // Avoid constructing a constraint set for variables that are already known
+ // to be identical.
+ if (var1.map == var2.map && var1.mapOperands == var2.mapOperands)
+ return true;
return strongCompare(var1, ComparisonOperator::EQ, var2);
}
diff --git a/mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-analysis.mlir b/mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-analysis.mlir
index c947407c63e74..4e64161aa8030 100644
--- a/mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-analysis.mlir
+++ b/mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-analysis.mlir
@@ -250,6 +250,29 @@ func.func @extract_slice_matching_insert_slice(
// -----
+// CHECK-LABEL: func @extract_slice_matching_insert_slice_dynamic
+func.func @extract_slice_matching_insert_slice_dynamic(
+ %tensor: tensor<?xf32> {bufferization.writable = true},
+ %offset: index, %size: index) -> tensor<?xf32> {
+ // Identical dynamic offsets/sizes and static strides should be recognized
+ // without constructing a ValueBounds constraint set.
+ // CHECK: tensor.extract_slice
+ // CHECK-SAME: {__inplace_operands_attr__ = ["true", "none", "none"]}
+ %slice = tensor.extract_slice %tensor[%offset][%size][1]
+ : tensor<?xf32> to tensor<?xf32>
+
+ // CHECK: tensor.insert_slice
+ // CHECK-SAME: {__inplace_operands_attr__ = ["true", "true", "none", "none"]}
+ %result = tensor.insert_slice %slice into %tensor[%offset][%size][1]
+ : tensor<?xf32> into tensor<?xf32>
+
+ // CHECK: return
+ // CHECK-SAME: __equivalent_func_args__ = [0]
+ return %result : tensor<?xf32>
+}
+
+// -----
+
// CHECK-LABEL: @read_of_matching_insert_slice_source
func.func @read_of_matching_insert_slice_source(
%A : tensor<?xf32> {bufferization.writable = true},
More information about the Mlir-commits
mailing list