Skip to content

Commit

Permalink
[mlir][Arith] ValueBoundsInterface: speedup arith.select (#113531)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cxy-1993 authored Oct 28, 2024
1 parent 7ad63c0 commit 39ac64c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions mlir/lib/Dialect/Arith/IR/ValueBoundsOpInterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 39ac64c

Please sign in to comment.