This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Canonicalize `shape.assuming` op to yield only inner values
ClosedPublic

Authored by frgossen on Mar 23 2021, 1:56 AM.

Diff Detail

Event Timeline

frgossen created this revision.Mar 23 2021, 1:56 AM
frgossen requested review of this revision.Mar 23 2021, 1:56 AM
bkramer added inline comments.Mar 23 2021, 2:19 AM
mlir/lib/Dialect/Shape/IR/Shape.cpp
273

Mind adding a comment on what this pattern does?

286

Won't this break if there are nested blocks within the assume?

frgossen updated this revision to Diff 332604.Mar 23 2021, 4:00 AM

Address comments

frgossen marked 2 inline comments as done.Mar 23 2021, 4:01 AM
frgossen added inline comments.
mlir/lib/Dialect/Shape/IR/Shape.cpp
286

Thanks!

mstorsjo removed a subscriber: mstorsjo.Mar 23 2021, 4:01 AM
frgossen marked an inline comment as done.Mar 23 2021, 4:02 AM
bkramer accepted this revision.Mar 23 2021, 4:09 AM

Looks good now. I can't comment on whether there should be a more general pass to do this kind of transform (IfOp has the same issue), though.

This revision is now accepted and ready to land.Mar 23 2021, 4:09 AM
This revision was landed with ongoing or failed builds.Mar 23 2021, 4:35 AM
This revision was automatically updated to reflect the committed changes.
herhut added a subscriber: herhut.Mar 23 2021, 6:05 AM
herhut added inline comments.
mlir/lib/Dialect/Shape/IR/Shape.cpp
273

Here is a counter example:

%w = cstr_eq(%shp0, %shp1)
%res = shape.assuming %w {
  %bcast = shape.broadcast(%shp0, %shp1)
  shape.yield %bcast
}

With the knowledge of %w being true, we can simplify the broadcast to %shp0 for example. Applying this canonicalization then would erase the fact that this is conditional on %w. As constraints are not side-effecting (on purpose), we would remove the constraint.