[mlir][Index] Implement InferIntRangeInterface
authorKrzysztof Drewniak <Krzysztof.Drewniak@amd.com>
Mon, 9 Jan 2023 17:09:17 +0000 (17:09 +0000)
committerKrzysztof Drewniak <Krzysztof.Drewniak@amd.com>
Thu, 19 Jan 2023 17:48:24 +0000 (17:48 +0000)
commit455305624884cf9237143e2ba0635fcc5ba5206a
tree3fd0e13ba18ce62f17726ca6026f4ce78a7d01a3
parentb05fa4faf64d6c6811bbecead13dc7c23ac43aca
[mlir][Index] Implement InferIntRangeInterface

Implement InferIntRangeInterface for all operations in the Index dialect. The
inference implementation, unlike the one for Arith, accounts for the
fact that Index can be either 64 or 32 bits long by evaluating both
cases. Bounds are stored as if index were i64, but when inferring new
bounds, we compute both f(...) and f(trunc(...)). We then compare
trunc(f(...)) to f(trunc(...)). If they are equal in the relevant
range components, we use the 64-bit range computation, otherwise we
give the range ext(f(trunc(...))) union f(...).

Note that this can cause surprising behavior as seen in the tests,
where, for example, the order of min and max operations impacts the
behavior of the inference. The inference could perhaps be made more
precise in the future (ex. by tracking 32 and 64-bit results
separately and having them influence each other somehow) butt, since
my project targets an index=i32 platform and doesn't see index-valued
values > uint32_max, I'm not too concerned about it.

Depends on https://reviews.llvm.org/D141299

Depends on https://reviews.llvm.org/D141296

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D140899
mlir/include/mlir/Dialect/Index/IR/IndexOps.h
mlir/include/mlir/Dialect/Index/IR/IndexOps.td
mlir/include/mlir/Interfaces/Utils/InferIntRangeCommon.h [new file with mode: 0644]
mlir/lib/Dialect/Arith/IR/CMakeLists.txt
mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp
mlir/lib/Dialect/Index/IR/CMakeLists.txt
mlir/lib/Dialect/Index/IR/InferIntRangeInterfaceImpls.cpp [new file with mode: 0644]
mlir/lib/Interfaces/CMakeLists.txt
mlir/lib/Interfaces/Utils/CMakeLists.txt [new file with mode: 0644]
mlir/lib/Interfaces/Utils/InferIntRangeCommon.cpp [new file with mode: 0644]
mlir/test/Dialect/Index/int-range-inference.mlir [new file with mode: 0644]