[Mlir-commits] [mlir] [mlir][affine] Add early exit to getLowerBound/getUpperBound function (NFC) (PR #212047)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Jul 25 10:49:40 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-affine
Author: lonely eagle (linuxlonelyeagle)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/212047.diff
1 Files Affected:
- (modified) mlir/lib/Dialect/Affine/IR/AffineOps.cpp (+9-12)
``````````diff
diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index defb029865835..fa5266affbd20 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`.
``````````
</details>
https://github.com/llvm/llvm-project/pull/212047
More information about the Mlir-commits
mailing list