Skip to content

Commit 5252bb1

Browse files
authored
[mlir] IntegerRangeAnalysis: return initialized state for noninteger values (llvm#133541)
Otherwise, the state for noninteger values remains uninitialized, causing the analysis to return bogus results.
1 parent 4840895 commit 5252bb1

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

mlir/lib/Interfaces/InferIntRangeInterface.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ raw_ostream &mlir::operator<<(raw_ostream &os, const ConstantIntRanges &range) {
134134

135135
IntegerValueRange IntegerValueRange::getMaxRange(Value value) {
136136
unsigned width = ConstantIntRanges::getStorageBitwidth(value.getType());
137-
if (width == 0)
138-
return {};
139-
140137
APInt umin = APInt::getMinValue(width);
141138
APInt umax = APInt::getMaxValue(width);
142139
APInt smin = width != 0 ? APInt::getSignedMinValue(width) : umin;

mlir/test/Dialect/Arith/int-range-interface.mlir

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt -int-range-optimizations -canonicalize %s | FileCheck %s
1+
// RUN: mlir-opt -allow-unregistered-dialect -int-range-optimizations -canonicalize %s | FileCheck %s
22

33
// CHECK-LABEL: func @add_min_max
44
// CHECK: %[[c3:.*]] = arith.constant 3 : index
@@ -1013,3 +1013,19 @@ func.func @zero_trip_loop2() {
10131013
}
10141014
return
10151015
}
1016+
1017+
// CHECK-LABEL: @noninteger_operation_result
1018+
func.func @noninteger_operation_result(%lb: index, %ub: index, %step: index, %cond: i1) {
1019+
%c1_i32 = arith.constant 1 : i32
1020+
1021+
%0 = "some_fp_op"() : () -> f32
1022+
// CHECK: [[OUTS:%.*]]:2 = scf.for
1023+
%outs:2 = scf.for %i = %lb to %ub step %step iter_args(%a = %c1_i32, %b = %0) -> (i32, f32) {
1024+
%1 = "some_int_op"() : () -> i32
1025+
scf.yield %1, %0 : i32, f32
1026+
}
1027+
1028+
%result = arith.select %cond, %c1_i32, %outs#0 : i32
1029+
"use"(%result) : (i32) -> ()
1030+
return
1031+
}

0 commit comments

Comments
 (0)