[Mlir-commits] [mlir] [mlir][IntegerRangeAnalysis] expose maybeReplaceWithConstant (PR #133151)

Maksim Levental llvmlistbot at llvm.org
Wed Mar 26 13:25:16 PDT 2025


https://github.com/makslevental updated https://github.com/llvm/llvm-project/pull/133151

>From 936c0237d84e27a25c4b43878c3861d4f4c396b9 Mon Sep 17 00:00:00 2001
From: Maksim Levental <maksim.levental at gmail.com>
Date: Wed, 26 Mar 2025 16:19:09 -0400
Subject: [PATCH] [mlir][IntegerRangeAnalysis] expose maybeReplaceWithConstant

---
 mlir/include/mlir/Analysis/DataFlow/IntegerRangeAnalysis.h | 4 ++++
 .../lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp | 7 ++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/mlir/include/mlir/Analysis/DataFlow/IntegerRangeAnalysis.h b/mlir/include/mlir/Analysis/DataFlow/IntegerRangeAnalysis.h
index b9e5573d6ad40..72ec6061cbb62 100644
--- a/mlir/include/mlir/Analysis/DataFlow/IntegerRangeAnalysis.h
+++ b/mlir/include/mlir/Analysis/DataFlow/IntegerRangeAnalysis.h
@@ -22,6 +22,7 @@
 #include "mlir/Interfaces/InferIntRangeInterface.h"
 
 namespace mlir {
+class RewriterBase;
 namespace dataflow {
 
 /// This lattice element represents the integer value range of an SSA value.
@@ -83,6 +84,9 @@ LogicalResult staticallyNonNegative(DataFlowSolver &solver, Operation *op);
 /// to use a non-64-bit index.
 LogicalResult staticallyNonNegative(DataFlowSolver &solver, Value v);
 
+LogicalResult maybeReplaceWithConstant(DataFlowSolver &solver,
+                                       RewriterBase &rewriter, Value value);
+
 } // end namespace dataflow
 } // end namespace mlir
 
diff --git a/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp b/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp
index f866c91ef6e39..1cb9453ccf3c9 100644
--- a/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp
+++ b/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp
@@ -57,10 +57,10 @@ static void copyIntegerRange(DataFlowSolver &solver, Value oldVal,
       *oldState);
 }
 
+namespace mlir::dataflow {
 /// Patterned after SCCP
-static LogicalResult maybeReplaceWithConstant(DataFlowSolver &solver,
-                                              PatternRewriter &rewriter,
-                                              Value value) {
+LogicalResult maybeReplaceWithConstant(DataFlowSolver &solver,
+                                       RewriterBase &rewriter, Value value) {
   if (value.use_empty())
     return failure();
   std::optional<APInt> maybeConstValue = getMaybeConstantValue(solver, value);
@@ -95,6 +95,7 @@ static LogicalResult maybeReplaceWithConstant(DataFlowSolver &solver,
   rewriter.replaceAllUsesWith(value, constOp->getResult(0));
   return success();
 }
+} // namespace mlir::dataflow
 
 namespace {
 class DataFlowListener : public RewriterBase::Listener {



More information about the Mlir-commits mailing list