Skip to content

Commit 4636b66

Browse files
authored
[mlir][intrange] Represent bounds of ReflectBoundsOp as si/ui (#92641)
This patch adapts the `test.reflect_bounds` test Op to use explicitly signed and unsigned representation for signed and unsigned bounds of `IntegerType`s. This is mostly a cosmetic change as the internal representation of the ranges is unchanged. However, it improves readability of tests.
1 parent 557bf38 commit 4636b66

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ func.func private @callee(%arg0: memref<?xindex, 4>) {
758758
}
759759

760760
// CHECK-LABEL: func @test_i8_bounds
761-
// CHECK: test.reflect_bounds {smax = 127 : i8, smin = -128 : i8, umax = -1 : i8, umin = 0 : i8}
761+
// CHECK: test.reflect_bounds {smax = 127 : si8, smin = -128 : si8, umax = 255 : ui8, umin = 0 : ui8}
762762
func.func @test_i8_bounds() -> i8 {
763763
%cst1 = arith.constant 1 : i8
764764
%0 = test.with_bounds { umin = 0 : i8, umax = 255 : i8, smin = -128 : i8, smax = 127 : i8 } : i8

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func.func @test() -> i1 {
7575
// -----
7676

7777
// CHECK-LABEL: func @test
78-
// CHECK: test.reflect_bounds {smax = 24 : i8, smin = 0 : i8, umax = 24 : i8, umin = 0 : i8}
78+
// CHECK: test.reflect_bounds {smax = 24 : si8, smin = 0 : si8, umax = 24 : ui8, umin = 0 : ui8}
7979
func.func @test() -> i8 {
8080
%cst1 = arith.constant 1 : i8
8181
%i8val = test.with_bounds { umin = 0 : i8, umax = 12 : i8, smin = 0 : i8, smax = 12 : i8 } : i8
@@ -87,7 +87,7 @@ func.func @test() -> i8 {
8787
// -----
8888

8989
// CHECK-LABEL: func @test
90-
// CHECK: test.reflect_bounds {smax = 127 : i8, smin = -128 : i8, umax = -1 : i8, umin = 0 : i8}
90+
// CHECK: test.reflect_bounds {smax = 127 : si8, smin = -128 : si8, umax = 255 : ui8, umin = 0 : ui8}
9191
func.func @test() -> i8 {
9292
%cst1 = arith.constant 1 : i8
9393
%i8val = test.with_bounds { umin = 0 : i8, umax = 127 : i8, smin = 0 : i8, smax = 127 : i8 } : i8

mlir/test/lib/Dialect/Test/TestOpDefs.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,11 +706,20 @@ void TestReflectBoundsOp::inferResultRanges(
706706
const ConstantIntRanges &range = argRanges[0];
707707
MLIRContext *ctx = getContext();
708708
Builder b(ctx);
709-
auto intTy = getType();
710-
setUminAttr(b.getIntegerAttr(intTy, range.umin()));
711-
setUmaxAttr(b.getIntegerAttr(intTy, range.umax()));
712-
setSminAttr(b.getIntegerAttr(intTy, range.smin()));
713-
setSmaxAttr(b.getIntegerAttr(intTy, range.smax()));
709+
Type sIntTy, uIntTy;
710+
// For plain `IntegerType`s, we can derive the appropriate signed and unsigned
711+
// Types for the Attributes.
712+
if (auto intTy = llvm::dyn_cast<IntegerType>(getType())) {
713+
unsigned bitwidth = intTy.getWidth();
714+
sIntTy = b.getIntegerType(bitwidth, /*isSigned=*/true);
715+
uIntTy = b.getIntegerType(bitwidth, /*isSigned=*/false);
716+
} else
717+
sIntTy = uIntTy = getType();
718+
719+
setUminAttr(b.getIntegerAttr(uIntTy, range.umin()));
720+
setUmaxAttr(b.getIntegerAttr(uIntTy, range.umax()));
721+
setSminAttr(b.getIntegerAttr(sIntTy, range.smin()));
722+
setSmaxAttr(b.getIntegerAttr(sIntTy, range.smax()));
714723
setResultRanges(getResult(), range);
715724
}
716725

0 commit comments

Comments
 (0)