This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Canonicalization of shape.assuming_all
ClosedPublic

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

Details

Summary

This allows assuming_all to be replaced when all inputs are known to be
statically passing witnesses.

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, 12:01 PM

LGTM, but let's look into using a fold for this (the good thing is that all the test cases will carry over :) )

jpienaar accepted this revision.May 20 2020, 5:02 PM
jpienaar added inline comments.
mlir/lib/Dialect/Shape/IR/ShapeCanonicalization.td
1 ↗(On Diff #265270)

Missing file header?

4 ↗(On Diff #265270)

Could we indent by 2 instead?

def AllInputsTrueWitnesses : Constraint<CPred<[
  llvm::all_of($0.getOwner()->getOperands(), [](mlir::Value op) {
    return op.getDefiningOp<mlir::shape::TrueWitnessOp>();
  })}]>>;
12 ↗(On Diff #265270)

Could we just indent these by 2 instead? [yes we need a formatter ... and many other variants as below]

def ConstantAssumingAll : Pat<
  (Shape_AssumingAllOp:$op $input), (Shape_TrueWitnessOp),
  [(AllInputsTrueWitnesses $op)]>;
This revision is now accepted and ready to land.May 20 2020, 5:02 PM
herhut accepted this revision.May 25 2020, 4:27 AM

Feel free to land. Comments are just suggestions and can also be addressed in a follow up.

mlir/lib/Dialect/Shape/IR/ShapeCanonicalization.td
6 ↗(On Diff #265270)

This would be a great place to use the isTrueWitness helper.

11 ↗(On Diff #265270)

This could also be formulated as a pattern that drops constant true witnesses from the operands and a pattern that replaces an assuming_all with no operands by a constant true witness. That way we also get removal of constant operands (which is more a cosmetic cleanup and does not really propagate any knowledge).

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

Instead of canonicalization, use folding.

Herald added a project: Restricted Project. · View Herald TranscriptJun 4 2020, 8:08 AM
This revision was automatically updated to reflect the committed changes.