[Mlir-commits] [mlir] 4883f11 - [mlir][affine] Add early exit to getLowerBound/getUpperBound function (NFC) (#212047)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Aug 15 03:59:26 PDT 2026
Author: lonely eagle
Date: 2026-08-15T18:59:21+08:00
New Revision: 4883f1131203981da6fa4573fe55d0ae6cf1c301
URL: https://github.com/llvm/llvm-project/commit/4883f1131203981da6fa4573fe55d0ae6cf1c301
DIFF: https://github.com/llvm/llvm-project/commit/4883f1131203981da6fa4573fe55d0ae6cf1c301.diff
LOG: [mlir][affine] Add early exit to getLowerBound/getUpperBound function (NFC) (#212047)
When an AffineExpr is an AffineConstantExpr, its bound can be directly
returned without computing the lower/upper bounds for all operand
values. This avoids redundant bound evaluations on operands and speeds
up static bound computation.
Added:
Modified:
mlir/lib/Dialect/Affine/IR/AffineOps.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index 8523c902d0a6f..b1f7b987703a5 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -775,6 +775,9 @@ static std::optional<int64_t> getUpperBound(Value iv) {
static std::optional<int64_t> getUpperBound(AffineExpr expr, unsigned numDims,
unsigned numSymbols,
ArrayRef<Value> operands) {
+ if (auto constExpr = dyn_cast<AffineConstantExpr>(expr))
+ return constExpr.getValue();
+
// Get the constant lower or upper bounds on the operands.
SmallVector<std::optional<int64_t>> constLowerBounds, constUpperBounds;
constLowerBounds.reserve(operands.size());
@@ -784,9 +787,6 @@ static std::optional<int64_t> getUpperBound(AffineExpr expr, unsigned numDims,
constUpperBounds.push_back(getUpperBound(operand));
}
- if (auto constExpr = dyn_cast<AffineConstantExpr>(expr))
- return constExpr.getValue();
-
return getBoundForAffineExpr(expr, numDims, numSymbols, constLowerBounds,
constUpperBounds,
/*isUpper=*/true);
@@ -798,6 +798,9 @@ static std::optional<int64_t> getUpperBound(AffineExpr expr, unsigned numDims,
static std::optional<int64_t> getLowerBound(AffineExpr expr, unsigned numDims,
unsigned numSymbols,
ArrayRef<Value> operands) {
+ if (auto constExpr = dyn_cast<AffineConstantExpr>(expr))
+ return constExpr.getValue();
+
// Get the constant lower or upper bounds on the operands.
SmallVector<std::optional<int64_t>> constLowerBounds, constUpperBounds;
constLowerBounds.reserve(operands.size());
@@ -807,15 +810,9 @@ static std::optional<int64_t> getLowerBound(AffineExpr expr, unsigned numDims,
constUpperBounds.push_back(getUpperBound(operand));
}
- std::optional<int64_t> lowerBound;
- if (auto constExpr = dyn_cast<AffineConstantExpr>(expr)) {
- lowerBound = constExpr.getValue();
- } else {
- lowerBound = getBoundForAffineExpr(expr, numDims, numSymbols,
- constLowerBounds, constUpperBounds,
- /*isUpper=*/false);
- }
- return lowerBound;
+ return getBoundForAffineExpr(expr, numDims, numSymbols, constLowerBounds,
+ constUpperBounds,
+ /*isUpper=*/false);
}
/// Simplify `expr` while exploiting information from the values in `operands`.
More information about the Mlir-commits
mailing list