-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir] IntegerRangeAnalysis: return initialized state for noninteger values #133541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…oninteger values Otherwise, the state for noninteger values remains uninitialized, causing the analysis to return bogus results.
@llvm/pr-subscribers-mlir-arith Author: Jeff Niu (Mogball) ChangesOtherwise, 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:
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
+}
|
@llvm/pr-subscribers-mlir Author: Jeff Niu (Mogball) ChangesOtherwise, 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:
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
+}
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/117/builds/8172 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/177/builds/15464 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/138/builds/12063 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/129/builds/17816 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/169/builds/9923 Here is the relevant piece of the build log for the reference
|
@Mogball did you intend to merge this without any review? |
I thought the bug was severe and the fix was self evident enough. I did forget to CTRL+S the lit test but I fixed that in a follow up 🤦 |
Otherwise, the state for noninteger values remains uninitialized, causing the analysis to return bogus results.