[Mlir-commits] [mlir] [mlir] IntegerRangeAnalysis: return initialized state for noninteger values (PR #133541)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Mar 28 16:13:30 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Jeff Niu (Mogball)

<details>
<summary>Changes</summary>

Otherwise, the state for noninteger values remains uninitialized, causing the analysis to return bogus results.

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


2 Files Affected:

- (modified) mlir/lib/Interfaces/InferIntRangeInterface.cpp (-3) 
- (modified) mlir/test/Dialect/Arith/int-range-interface.mlir (+17-1) 


``````````diff
diff --git a/mlir/lib/Interfaces/InferIntRangeInterface.cpp b/mlir/lib/Interfaces/InferIntRangeInterface.cpp
index 1801e3f7c52fd..9f3e97d051c85 100644
--- a/mlir/lib/Interfaces/InferIntRangeInterface.cpp
+++ b/mlir/lib/Interfaces/InferIntRangeInterface.cpp
@@ -134,9 +134,6 @@ raw_ostream &mlir::operator<<(raw_ostream &os, const ConstantIntRanges &range) {
 
 IntegerValueRange IntegerValueRange::getMaxRange(Value value) {
   unsigned width = ConstantIntRanges::getStorageBitwidth(value.getType());
-  if (width == 0)
-    return {};
-
   APInt umin = APInt::getMinValue(width);
   APInt umax = APInt::getMaxValue(width);
   APInt smin = width != 0 ? APInt::getSignedMinValue(width) : umin;
diff --git a/mlir/test/Dialect/Arith/int-range-interface.mlir b/mlir/test/Dialect/Arith/int-range-interface.mlir
index 090af3e79f4a1..e729397a5b512 100644
--- a/mlir/test/Dialect/Arith/int-range-interface.mlir
+++ b/mlir/test/Dialect/Arith/int-range-interface.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -int-range-optimizations -canonicalize %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -int-range-optimizations -canonicalize %s | FileCheck %s
 
 // CHECK-LABEL: func @add_min_max
 // CHECK: %[[c3:.*]] = arith.constant 3 : index
@@ -1013,3 +1013,19 @@ func.func @zero_trip_loop2() {
   }
   return
 }
+
+// CHECK-LABEL: @noninteger_operation_result
+func.func @noninteger_operation_result(%lb: index, %ub: index, %step: index, %cond: i1) {
+  %c1_i32 = arith.constant 1 : i32
+
+  %0 = "some_fp_op"() : () -> f32
+  // CHECK: [[OUTS:%.*]]:2 = scf.for
+  %outs:2 = scf.for %i = %lb to %ub step %step iter_args(%a = %c1_i32, %b = %0) -> (i32, f32) {
+    %1 = "some_int_op"() : () -> i32
+    scf.yield %1, %0 : i32, f32
+  }
+
+  %result = arith.select %cond, %c1_i32, %outs#0 : i32
+  "use"(%result) : (i32) -> ()
+  return
+}

``````````

</details>


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


More information about the Mlir-commits mailing list