This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add additional Canonicalization of shape.cstr_broadcastable.
ClosedPublic

Authored by tpopp on Jul 6 2020, 1:44 AM.

Details

Summary

Added canonicalization and folding was:

  • Folding when either input is an attribute indicating a scalar input

which can always be broadcasted.

  • Canonicalization where it can be determined that either input shape is

a scalar.

  • Canonicalization where the partially specified input shapes can be

proven to be broadcastable always.

Diff Detail

Event Timeline

tpopp created this revision.Jul 6 2020, 1:44 AM
Herald added a project: Restricted Project. · View Herald Transcript
herhut added inline comments.Jul 6 2020, 3:32 AM
mlir/include/mlir/Dialect/Traits.h
52

nit: they they. Also they may not ?

mlir/lib/Dialect/Shape/IR/Shape.cpp
335

Why is shape_of(%scalar) not folded to a constant?

frgossen accepted this revision.Jul 6 2020, 3:45 AM

Nice :)

mlir/lib/Dialect/Shape/IR/Shape.cpp
329

nit: I think, you can pass op directly.

333

Why is this static?
Not saying it is wrong, I just want to learn more about the C++ way of doing things.

337

nit: return type.hasRank() && type.getRank() == 0 may be easier to read

361

This is constant folding, is it? Should this case be moved to fold?

367

Maybe you can extract this as a method and reuse it for lhsShape and rhsShape like you did above.

mlir/lib/Dialect/Traits.cpp
21

Does llvm have some utility for a zip iteration like this one?
That would be really cool but I could not find.

28

The -1 is used for dynamic sizes, right?
You could use ShapedType::kDynamicSize

This revision is now accepted and ready to land.Jul 6 2020, 3:45 AM
rriddle added inline comments.Jul 6 2020, 6:59 PM
mlir/lib/Dialect/Shape/IR/Shape.cpp
333

nit: Value should be passed by value, i.e. non-const non-reference.

mlir/lib/Dialect/Traits.cpp
21

llvm::zip

tpopp updated this revision to Diff 275992.Jul 7 2020, 4:30 AM
tpopp marked 11 inline comments as done.

Refactor code. No new behavior was added.

tpopp added inline comments.Jul 7 2020, 4:57 AM
mlir/lib/Dialect/Shape/IR/Shape.cpp
333

I was just making it static because it didn't need any information specific to an instance of the object. I think more appropriate though is a function in an anonymous namespace outside of the class because this isn't really specific to that class' data.

335

I just wasn't able to test this properly. You're right in that it's folded.

tpopp marked an inline comment as done.Jul 7 2020, 4:58 AM
This revision was automatically updated to reflect the committed changes.