Skip to content

Commit 6496824

Browse files
committed
[mlir][Arith] Fix bug in zero-extension range inference
D135089 extracted the extui code into a helper, but used fromSigned instead of fromUnsigned. Reviewed By: Mogball, ThomasRaoux Differential Revision: https://reviews.llvm.org/D141296
1 parent d414c2a commit 6496824

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,9 @@ void arith::MinUIOp::inferResultRanges(ArrayRef<ConstantIntRanges> argRanges,
469469
static ConstantIntRanges extUIRange(const ConstantIntRanges &range,
470470
Type destType) {
471471
unsigned destWidth = ConstantIntRanges::getStorageBitwidth(destType);
472-
APInt smin = range.umin().zext(destWidth);
473-
APInt smax = range.umax().zext(destWidth);
474-
return ConstantIntRanges::fromSigned(smin, smax);
472+
APInt umin = range.umin().zext(destWidth);
473+
APInt umax = range.umax().zext(destWidth);
474+
return ConstantIntRanges::fromUnsigned(umin, umax);
475475
}
476476

477477
void arith::ExtUIOp::inferResultRanges(ArrayRef<ConstantIntRanges> argRanges,

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,3 +712,21 @@ func.func @trunc_handles_small_signed_ranges(%arg0 : i16) -> i1 {
712712
%5 = arith.andi %3, %4 : i1
713713
func.return %5 : i1
714714
}
715+
716+
/// Catch a bug that crept in during an earlier refactoring that made unsigned
717+
/// extension use the signed ranges
718+
719+
// CHECK-LABEL: func.func @extui_uses_unsigned
720+
// CHECK: %[[true:.*]] = arith.constant true
721+
// CHECK: return %[[true]]
722+
func.func @extui_uses_unsigned(%arg0 : i32) -> i1 {
723+
%ci32_smin = arith.constant 0x80000000 : i32
724+
%ci32_smin_64 = arith.constant 0x80000000 : i64
725+
%c0_i64 = arith.constant 0 : i64
726+
%0 = arith.minui %arg0, %ci32_smin : i32
727+
%1 = arith.extui %0 : i32 to i64
728+
%2 = arith.cmpi sge, %1, %c0_i64 : i64
729+
%3 = arith.cmpi ule, %1, %ci32_smin_64 : i64
730+
%4 = arith.andi %2, %3 : i1
731+
func.return %4 : i1
732+
}

0 commit comments

Comments
 (0)