This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][Tosa] Turn reshape(const()) from canonicalization into fold; fix dynamic shape case
ClosedPublic

Authored by mgehre-amd on Jul 6 2023, 8:15 AM.

Details

Summary
  1. Turns the canonicalization into a fold, so it can cleanup IR within other passes.
  1. When the output of the reshape is a dynamic shaped tensor,

we cannot apply the fold to the constant, because constants are required to have
static shape.

Diff Detail

Event Timeline

mgehre-amd created this revision.Jul 6 2023, 8:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 6 2023, 8:15 AM
mgehre-amd requested review of this revision.Jul 6 2023, 8:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 6 2023, 8:15 AM
mgehre-amd added inline comments.Jul 6 2023, 8:23 AM
mlir/test/Dialect/Tosa/canonicalize.mlir
378–379

Note that I modified this test to be non-splat because a test for a splat constant already exists below (see reshape_canonicalize_const_spat)

jpienaar accepted this revision.Jul 6 2023, 8:29 AM
jpienaar added a subscriber: jpienaar.
jpienaar added inline comments.
mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
836–841

Unless it has single use ?

This revision is now accepted and ready to land.Jul 6 2023, 8:29 AM
eric-k256 accepted this revision.Jul 6 2023, 8:32 AM

Looks good to me.

mlir/test/Dialect/Tosa/canonicalize.mlir
378–379

I hadn't noticed the typo in _spat before. I'll try to remember to do a typo fix later.

mgehre-amd added inline comments.Jul 6 2023, 11:05 AM
mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
836–841

If it has a single use, then adding the reshaped variant will not duplicate it because the non-reshaped one will be removed.

mgehre-amd added inline comments.Jul 6 2023, 11:10 AM
mlir/test/Dialect/Tosa/canonicalize.mlir
378–379

I also didn't notice the typo when copying the function name :-D. I have added a typo fix in my commit.