diff options
author | Felix Schneider <fx.schn@gmail.com> | 2024-05-21 18:52:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-21 18:52:48 +0200 |
commit | 4636b66de513dfa15da1ba071f279b64ad68903f (patch) | |
tree | c366b2a7a766833ac7a980aac6f82ce26a859ec3 | |
parent | 557bf3835b96ef5839013b1e821a1cb869660aa3 (diff) |
[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.
-rw-r--r-- | mlir/test/Dialect/Arith/int-range-interface.mlir | 2 | ||||
-rw-r--r-- | mlir/test/Dialect/Arith/int-range-opts.mlir | 4 | ||||
-rw-r--r-- | mlir/test/lib/Dialect/Test/TestOpDefs.cpp | 19 |
3 files changed, 17 insertions, 8 deletions
diff --git a/mlir/test/Dialect/Arith/int-range-interface.mlir b/mlir/test/Dialect/Arith/int-range-interface.mlir index 16524b363472..17d3fcfc13ce 100644 --- a/mlir/test/Dialect/Arith/int-range-interface.mlir +++ b/mlir/test/Dialect/Arith/int-range-interface.mlir @@ -758,7 +758,7 @@ func.func private @callee(%arg0: memref<?xindex, 4>) { } // CHECK-LABEL: func @test_i8_bounds -// CHECK: test.reflect_bounds {smax = 127 : i8, smin = -128 : i8, umax = -1 : i8, umin = 0 : i8} +// CHECK: test.reflect_bounds {smax = 127 : si8, smin = -128 : si8, umax = 255 : ui8, umin = 0 : ui8} func.func @test_i8_bounds() -> i8 { %cst1 = arith.constant 1 : i8 %0 = test.with_bounds { umin = 0 : i8, umax = 255 : i8, smin = -128 : i8, smax = 127 : i8 } : i8 diff --git a/mlir/test/Dialect/Arith/int-range-opts.mlir b/mlir/test/Dialect/Arith/int-range-opts.mlir index 6179003ab4e7..71174f1c5ef0 100644 --- a/mlir/test/Dialect/Arith/int-range-opts.mlir +++ b/mlir/test/Dialect/Arith/int-range-opts.mlir @@ -75,7 +75,7 @@ func.func @test() -> i1 { // ----- // CHECK-LABEL: func @test -// CHECK: test.reflect_bounds {smax = 24 : i8, smin = 0 : i8, umax = 24 : i8, umin = 0 : i8} +// CHECK: test.reflect_bounds {smax = 24 : si8, smin = 0 : si8, umax = 24 : ui8, umin = 0 : ui8} func.func @test() -> i8 { %cst1 = arith.constant 1 : i8 %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 { // ----- // CHECK-LABEL: func @test -// CHECK: test.reflect_bounds {smax = 127 : i8, smin = -128 : i8, umax = -1 : i8, umin = 0 : i8} +// CHECK: test.reflect_bounds {smax = 127 : si8, smin = -128 : si8, umax = 255 : ui8, umin = 0 : ui8} func.func @test() -> i8 { %cst1 = arith.constant 1 : i8 %i8val = test.with_bounds { umin = 0 : i8, umax = 127 : i8, smin = 0 : i8, smax = 127 : i8 } : i8 diff --git a/mlir/test/lib/Dialect/Test/TestOpDefs.cpp b/mlir/test/lib/Dialect/Test/TestOpDefs.cpp index bfee0391f670..b058a8e1abbc 100644 --- a/mlir/test/lib/Dialect/Test/TestOpDefs.cpp +++ b/mlir/test/lib/Dialect/Test/TestOpDefs.cpp @@ -706,11 +706,20 @@ void TestReflectBoundsOp::inferResultRanges( const ConstantIntRanges &range = argRanges[0]; MLIRContext *ctx = getContext(); Builder b(ctx); - auto intTy = getType(); - setUminAttr(b.getIntegerAttr(intTy, range.umin())); - setUmaxAttr(b.getIntegerAttr(intTy, range.umax())); - setSminAttr(b.getIntegerAttr(intTy, range.smin())); - setSmaxAttr(b.getIntegerAttr(intTy, range.smax())); + Type sIntTy, uIntTy; + // For plain `IntegerType`s, we can derive the appropriate signed and unsigned + // Types for the Attributes. + if (auto intTy = llvm::dyn_cast<IntegerType>(getType())) { + unsigned bitwidth = intTy.getWidth(); + sIntTy = b.getIntegerType(bitwidth, /*isSigned=*/true); + uIntTy = b.getIntegerType(bitwidth, /*isSigned=*/false); + } else + sIntTy = uIntTy = getType(); + + setUminAttr(b.getIntegerAttr(uIntTy, range.umin())); + setUmaxAttr(b.getIntegerAttr(uIntTy, range.umax())); + setSminAttr(b.getIntegerAttr(sIntTy, range.smin())); + setSmaxAttr(b.getIntegerAttr(sIntTy, range.smax())); setResultRanges(getResult(), range); } |