This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add folding for shape.any
ClosedPublic

Authored by tpopp on May 20 2020, 9:09 AM.

Details

Summary

If any input to shape.any is a const_shape, shape.any can be replaced
with that input.

Diff Detail

Event Timeline

tpopp created this revision.May 20 2020, 9:09 AM
Herald added a reviewer: silvas. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
silvas accepted this revision.May 20 2020, 11:49 AM
silvas added inline comments.
mlir/test/Dialect/Shape/canonicalize.mlir
262

Can you expand a bit on this "yet"? Is that a direction we want to go? It seems like it would be a very small change to this patch to support that, suggesting there is a deeper reason why we want to avoid that, which would be good to document here or in AnyOp::fold

jpienaar accepted this revision.May 20 2020, 4:50 PM
jpienaar marked an inline comment as done.
jpienaar added inline comments.
mlir/lib/Dialect/Shape/IR/Shape.cpp
106

So the folder only focuses on case where the output can be fully statically computed? [this overlaps with Sean's question below]

108

Nit: Perhaps expand the comment slightly: it is commutative and so constants have been moved to the trailing operands.

This would be known to someone who read the canonicalization doc or looked at FoldUtils.cpp , but I think it is useful to avoid needing that context especially as short.

This revision is now accepted and ready to land.May 20 2020, 4:50 PM
herhut accepted this revision.May 25 2020, 4:43 AM
herhut added inline comments.
mlir/test/Dialect/Shape/canonicalize.mlir
262

We would need to inspect operands and their types for this to work, which is more complex than just looking at constant operands. So it makes sense to land this first, if only to support static shape workloads, and expand later. A comment like Folding of any with partially constant operands is not yet implemented should convey this.

tpopp updated this revision to Diff 268477.Jun 4 2020, 8:09 AM
tpopp marked 5 inline comments as done.

Explain commutativity of any.

Herald added a project: Restricted Project. · View Herald TranscriptJun 4 2020, 8:09 AM
tpopp added inline comments.Jun 4 2020, 8:12 AM
mlir/lib/Dialect/Shape/IR/Shape.cpp
106

Yes, I started to add that as a comment, but then realized that's essentially the definition of folding, so I think it would be redundant to state.

mlir/test/Dialect/Shape/canonicalize.mlir
262

There's a not a specific reason to not support it. I would rather wait until there's a clear use case though to implement more of this as it's more risky given the inherent lack of safety in the operation.

This revision was automatically updated to reflect the committed changes.