[Mlir-commits] [mlir] [mlir][Arith] ValueBoundsInterface: speedup arith.select (PR #113531)
donald chen
llvmlistbot at llvm.org
Wed Oct 23 23:55:24 PDT 2024
https://github.com/cxy-1993 created https://github.com/llvm/llvm-project/pull/113531
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.
>From 91bc140b11f7f13da0f9d23656abfe8717df3401 Mon Sep 17 00:00:00 2001
From: donald chen <chenxunyu1993 at gmail.com>
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);
More information about the Mlir-commits
mailing list