This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Index] Implement InferIntRangeInterface
ClosedPublic

Authored by krzysz00 on Jan 3 2023, 8:43 AM.

Details

Summary

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

Diff Detail

Event Timeline

krzysz00 created this revision.Jan 3 2023, 8:43 AM
Herald added a project: Restricted Project. · View Herald Transcript
krzysz00 requested review of this revision.Jan 3 2023, 8:43 AM

At a glance, this seems correct. Please split up the patch and I'll take a deeper look

mlir/include/mlir/Dialect/Index/IR/IndexOps.td
309

please split out the addition of these ops from this patch

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

can this be split out of the current patch too?

(Comment seen, I'll probably split the patch on Monday)

krzysz00 updated this revision to Diff 487472.Jan 9 2023, 9:22 AM
krzysz00 retitled this revision from [mlir][Index] Add min operations, int range inference support to [mlir][Index] Implement InferIntRangeInterface.
krzysz00 edited the summary of this revision. (Show Details)

Split patch

krzysz00 updated this revision to Diff 487473.Jan 9 2023, 9:23 AM

Add depends lines to commit message

Mogball added inline comments.Jan 9 2023, 4:40 PM
mlir/include/mlir/Interfaces/Utils/InferIntRangeCommon.h
29–30
32

I don't think it's important to explicitly specify the size here

34
106–115

can you drop the explicit values?

mlir/lib/Dialect/Index/IR/InferIntRangeInterfaceImpls.cpp
2

can you name this IndexOpsInferIntRange.cpp?

34

please drop const on these

165

can you move this comment down to the function?

185

please drop trivial braces

215
krzysz00 updated this revision to Diff 488373.Jan 11 2023, 1:45 PM
krzysz00 marked 5 inline comments as done.

Rebase, adress most review comments

mlir/include/mlir/Interfaces/Utils/InferIntRangeCommon.h
32

I'd say it's important so anyone needing to forward-declare this enum knows what to do.

mlir/lib/Dialect/Index/IR/InferIntRangeInterfaceImpls.cpp
2

I was trying to match the convention over in Arith and other dialects where you have BlahOpInterfaceImpls.cpp, but I'm not strongly attached to the name and can change it if you'd like

Mogball accepted this revision.Jan 15 2023, 10:33 AM

LGTM, thanks!

This revision is now accepted and ready to land.Jan 15 2023, 10:33 AM
krzysz00 updated this revision to Diff 489603.Jan 16 2023, 10:51 AM

Rebase for std::optional migration

krzysz00 updated this revision to Diff 490266.Jan 18 2023, 12:07 PM

Fix accidental build error

This revision was landed with ongoing or failed builds.Jan 19 2023, 9:48 AM
This revision was automatically updated to reflect the committed changes.