This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Add `index_to_size` and `size_to_index` to the shape dialect
ClosedPublic

Authored by frgossen on May 20 2020, 1:39 AM.

Details

Summary

Add the two conversion operations index_to_size and size_to_index to the
shape dialect.
This facilitates the conversion of index types between the shape and the
standard dialect.

Depends On D80278

Diff Detail

Event Timeline

frgossen created this revision.May 20 2020, 1:39 AM
Herald added a reviewer: silvas. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
frgossen updated this revision to Diff 265167.May 20 2020, 1:57 AM

Simplify folding

pifon2a accepted this revision.May 20 2020, 2:42 AM
herhut accepted this revision.May 20 2020, 3:03 AM

Thanks!

silvas accepted this revision.May 20 2020, 12:00 PM

Awesome, thanks :)

jpienaar accepted this revision.May 20 2020, 4:25 PM

Looks good modulo small changes.

mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
199

This is already captured in the arguments and results below (and in generated doc for the ops).

341

size represents a non-negative integer with support for being unknown and invalid, what is the conversion/behavior when the operand is invalid?

This revision is now accepted and ready to land.May 20 2020, 4:25 PM
herhut added inline comments.May 26 2020, 12:05 AM
mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
341

If the size is invalid, then I'd assume that all code that depends on it has undefined behavior. In particular, size_to_index should have an undefined result. For the inverse, we could consider checking that the index argument is indeed positive or clamp it at [0,inf). That has the drawback that we cannot compile the conversion from index to size into a no-op.

I would prefer not to expose the internal representation of invalid (-1 I believe) at runtime. However, if we go for undefined behavior, returning -1 would be valid.

frgossen marked 2 inline comments as done.May 26 2020, 1:59 AM
frgossen added inline comments.
mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
341

As there exists no lowering at the moment, it seems that all of these operations' semantics are embedded in the constant folding mechanism.
Would it be okay to say the behaviour is undefined in this case?

frgossen updated this revision to Diff 266126.May 26 2020, 2:08 AM
frgossen marked an inline comment as done.

Remove redundant documentation

frgossen added inline comments.May 26 2020, 2:26 AM
mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
341

We could also say that the conversion from index_to_size is undefined if the argument is negative.

rriddle added inline comments.May 27 2020, 2:11 PM
mlir/lib/Dialect/Shape/IR/Shape.cpp
274

nit: Remove newline here and below.

frgossen marked 3 inline comments as done.May 28 2020, 6:53 AM
frgossen updated this revision to Diff 266859.May 28 2020, 6:55 AM

Document undefined behavior

This revision was automatically updated to reflect the committed changes.