[Mlir-commits] [mlir] [mlir][Arith] ValueBoundsInterface: speedup arith.select (PR #113531)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Oct 23 23:56:03 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-arith
@llvm/pr-subscribers-mlir
Author: donald chen (cxy-1993)
<details>
<summary>Changes</summary>
When calculating value bounds in the arith.select op , the compare function is invoked to compare trueValue and falseValue. This function rebuilds constraints, resulting in repeated computations of value bounds.
In large-scale programs, this redundancy significantly impacts compilation time.
---
Full diff: https://github.com/llvm/llvm-project/pull/113531.diff
1 Files Affected:
- (modified) mlir/lib/Dialect/Arith/IR/ValueBoundsOpInterfaceImpl.cpp (+8-6)
``````````diff
diff --git a/mlir/lib/Dialect/Arith/IR/ValueBoundsOpInterfaceImpl.cpp b/mlir/lib/Dialect/Arith/IR/ValueBoundsOpInterfaceImpl.cpp
index 7cfcc4180539c2..6de151594e3e9c 100644
--- a/mlir/lib/Dialect/Arith/IR/ValueBoundsOpInterfaceImpl.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ValueBoundsOpInterfaceImpl.cpp
@@ -107,9 +107,10 @@ struct SelectOpInterface
// If trueValue <= falseValue:
// * result <= falseValue
// * result >= trueValue
- if (cstr.compare(/*lhs=*/{trueValue, dim},
- ValueBoundsConstraintSet::ComparisonOperator::LE,
- /*rhs=*/{falseValue, dim})) {
+ if (cstr.populateAndCompare(
+ /*lhs=*/{trueValue, dim},
+ ValueBoundsConstraintSet::ComparisonOperator::LE,
+ /*rhs=*/{falseValue, dim})) {
if (dim) {
cstr.bound(value)[*dim] >= cstr.getExpr(trueValue, dim);
cstr.bound(value)[*dim] <= cstr.getExpr(falseValue, dim);
@@ -121,9 +122,10 @@ struct SelectOpInterface
// If falseValue <= trueValue:
// * result <= trueValue
// * result >= falseValue
- if (cstr.compare(/*lhs=*/{falseValue, dim},
- ValueBoundsConstraintSet::ComparisonOperator::LE,
- /*rhs=*/{trueValue, dim})) {
+ if (cstr.populateAndCompare(
+ /*lhs=*/{falseValue, dim},
+ ValueBoundsConstraintSet::ComparisonOperator::LE,
+ /*rhs=*/{trueValue, dim})) {
if (dim) {
cstr.bound(value)[*dim] >= cstr.getExpr(falseValue, dim);
cstr.bound(value)[*dim] <= cstr.getExpr(trueValue, dim);
``````````
</details>
https://github.com/llvm/llvm-project/pull/113531
More information about the Mlir-commits
mailing list