[Mlir-commits] [mlir] [mlir] Extend affine.min/max ValueBoundsOpInterfaceImpls (PR #118840)
Matthias Springer
llvmlistbot at llvm.org
Tue Jan 21 00:04:08 PST 2025
================
@@ -67,6 +67,27 @@ struct AffineMinOpInterface
expr.replaceDimsAndSymbols(dimReplacements, symReplacements);
cstr.bound(value) <= bound;
}
+ // Get all constant lower bounds, choose minimum, and set lower bound to it.
+ MLIRContext *ctx = op->getContext();
+ AffineMap map = minOp.getAffineMap();
+ SmallVector<Value> mapOperands = minOp.getOperands();
+ std::optional<int64_t> minBound;
+ for (AffineExpr expr : map.getResults()) {
+ auto exprMap =
+ AffineMap::get(map.getNumDims(), map.getNumSymbols(), expr, ctx);
+ ValueBoundsConstraintSet::Variable exprVar(exprMap, mapOperands);
+ FailureOr<int64_t> exprBound =
+ cstr.computeConstantBound(presburger::BoundType::LB, exprVar,
----------------
matthias-springer wrote:
This is a bit misleading: You're actually calling a static function `ValueBoundsConstraintSet::computeConstantBound` here. That means building a brand new constraint set, which can be expensive because the same IR may be re-analyzed.
Can you try using `cstr.populateAndCompare` instead? And keep track of which AffineExpr result is the current minimum one. Keep comparing against that one to find the overall smallest one. That should also work with non-constant bounds then.
https://github.com/llvm/llvm-project/pull/118840
More information about the Mlir-commits
mailing list