This is an archive of the discontinued LLVM Phabricator instance.

[mlir][StandardDialect] Add some folding for operations in standard dialect.
ClosedPublic

Authored by mravishankar on Jun 9 2020, 11:55 PM.

Details

Diff Detail

Event Timeline

mravishankar created this revision.Jun 9 2020, 11:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2020, 11:55 PM
rriddle requested changes to this revision.Jun 10 2020, 11:07 AM
rriddle added inline comments.
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
430

This doesn't make sense to me, did you intend to check for all ones?

mlir/test/Transforms/constant-fold.mlir
98

Can you add a non i1 test case?

This revision now requires changes to proceed.Jun 10 2020, 11:07 AM
mravishankar marked an inline comment as done.

Fixing and folding bug

Minor fixes to comments

mravishankar marked 2 inline comments as done.Jun 11 2020, 2:08 PM
mravishankar added inline comments.
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
430

Yes indeed. Sorry about that, and thanks for catching this. Fixed it and generalized to test for splat tensor/vector constants as well.

rriddle added inline comments.Jun 11 2020, 2:22 PM
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
442

I don't think most of this is necessary, can you just use the existing m_ConstantInt and then check that result(if matched) isAllOnesValue?

mravishankar marked an inline comment as done.

Addressing comments.

mravishankar marked 2 inline comments as done.Jun 12 2020, 11:40 AM
mravishankar added inline comments.
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
442

Thanks for the suggestion. Done.

rriddle added inline comments.Jun 12 2020, 11:43 AM
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
442

Why do you need the check for IntegerType here? I wouldn't expect that to be necessary.

445

intValue.isAllOnesValue()

mravishankar marked 3 inline comments as done.

Address comments

mlir/lib/Dialect/StandardOps/IR/Ops.cpp
442

I think this wouldnt be valid to do for IndexTypes since there is no defined bitwidth for index types.

rriddle added inline comments.Jun 12 2020, 4:24 PM
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
442

I don't see the problem though, this seems conservative even in the case of IndexType. We have a maximum representation for an index constant, even if we don't know the exact bitwidth it will end up being. If all of the bits are one in the maximum representation, it is guaranteed that all bits will be one in any other representation. Also, given that we already fold index values in other operations we would have to create a new policy where we don't fold them(which seems a bit excessive IMO).

Address comments

mravishankar marked 3 inline comments as done.Jun 13 2020, 11:58 PM
mravishankar added inline comments.
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
442

Ah good point. With use of isAllOnesValue here I dont need the bitwidth explicitly. So I can remove the check for integer. Added test for index type as well to make sure it behaves as expected.

rriddle accepted this revision.Jun 15 2020, 1:35 PM
This revision is now accepted and ready to land.Jun 15 2020, 1:35 PM
This revision was automatically updated to reflect the committed changes.
mravishankar marked an inline comment as done.