[Mlir-commits] [mlir] [mlir][int-range] `IntRangeNarrowingPass` was missing `SparseConstantPropagation` analysis (PR #174088)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Dec 31 05:24:03 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Ivan Butygin (Hardcode84)

<details>
<summary>Changes</summary>

This was causing it to skip nested scf ops in some cases (see `scf.for` test). Use convenience `loadBaselineAnalyses` func.

---
Full diff: https://github.com/llvm/llvm-project/pull/174088.diff


2 Files Affected:

- (modified) mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp (+3-3) 
- (modified) mlir/test/Dialect/Arith/int-range-narrowing.mlir (+30) 


``````````diff
diff --git a/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp b/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp
index 2017905587b26..a85d3bb43a372 100644
--- a/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp
+++ b/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp
@@ -9,6 +9,7 @@
 #include <utility>
 
 #include "mlir/Analysis/DataFlow/ConstantPropagationAnalysis.h"
+#include "mlir/Analysis/DataFlow/Utils.h"
 #include "mlir/Analysis/DataFlowFramework.h"
 #include "mlir/Dialect/Arith/Transforms/Passes.h"
 
@@ -485,8 +486,7 @@ struct IntRangeOptimizationsPass final
     Operation *op = getOperation();
     MLIRContext *ctx = op->getContext();
     DataFlowSolver solver;
-    solver.load<DeadCodeAnalysis>();
-    solver.load<SparseConstantPropagation>();
+    loadBaselineAnalyses(solver);
     solver.load<IntegerRangeAnalysis>();
     if (failed(solver.initializeAndRun(op)))
       return signalPassFailure();
@@ -511,7 +511,7 @@ struct IntRangeNarrowingPass final
     Operation *op = getOperation();
     MLIRContext *ctx = op->getContext();
     DataFlowSolver solver;
-    solver.load<DeadCodeAnalysis>();
+    loadBaselineAnalyses(solver);
     solver.load<IntegerRangeAnalysis>();
     if (failed(solver.initializeAndRun(op)))
       return signalPassFailure();
diff --git a/mlir/test/Dialect/Arith/int-range-narrowing.mlir b/mlir/test/Dialect/Arith/int-range-narrowing.mlir
index e16db6293560e..42dd4294b86e9 100644
--- a/mlir/test/Dialect/Arith/int-range-narrowing.mlir
+++ b/mlir/test/Dialect/Arith/int-range-narrowing.mlir
@@ -347,3 +347,33 @@ func.func @clamp_to_loop_bound_and_id() {
   }
   return
 }
+
+func.func private @use(index)
+
+// CHECK-LABEL: func.func @loop_with_iter_arg
+func.func @loop_with_iter_arg() {
+  %c0 = arith.constant 0 : index
+  %c1 = arith.constant 0 : index
+  %c16 = arith.constant 16 : index
+
+  %cst = arith.constant dense<0.000000e+00> : vector<4xf32>
+
+//       CHECK:  %[[POS:.*]] = test.with_bounds {smax = 1 : index, smin = 0 : index, umax = 1 : index, umin = 0 : index} : index
+//       CHECK:  %[[NEG:.*]] = test.with_bounds {smax = 0 : index, smin = -1 : index, umax = -1 : index, umin = 0 : index} : index
+// Check iter args are still present
+//       CHECK:  scf.for {{.*}} iter_args({{.*}})
+//       CHECK:  %[[POS_I8:.*]] = arith.index_castui %[[POS]] : index to i8
+//       CHECK:  %[[NEG_I8:.*]] = arith.index_cast %[[NEG]] : index to i8
+//       CHECK:  %[[RES_I8:.*]] = arith.addi %[[POS_I8]], %[[NEG_I8]] : i8
+//       CHECK:  %[[RES:.*]] = arith.index_cast %[[RES_I8]] : i8 to index
+//       CHECK:  call @use(%[[RES]])
+
+  %0 = test.with_bounds { umin = 0 : index, umax = 1 : index, smin = 0 : index, smax = 1 : index } : index
+  %1 = test.with_bounds { umin = 0 : index, umax = -1 : index, smin = -1 : index, smax = 0 : index } : index
+  %res = scf.for %arg0 = %c0 to %c16 step %c1 iter_args(%arg1 = %cst) -> (vector<4xf32>) {
+    %2 = arith.addi %0, %1 : index
+    func.call @use(%2) : (index) -> ()
+    scf.yield %arg1 : vector<4xf32>
+  }
+  return
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/174088


More information about the Mlir-commits mailing list