From 91bc140b11f7f13da0f9d23656abfe8717df3401 Mon Sep 17 00:00:00 2001 From: donald chen Date: Thu, 24 Oct 2024 06:51:11 +0000 Subject: [PATCH] [mlir][Arith] ValueBoundsInterface: speedup arith.select 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. --- .../Arith/IR/ValueBoundsOpInterfaceImpl.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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);