It is preferred to merge tosa.transpose operations together rather than convert
one to a tosa.reshape. This is to leverage the tosa.transpose -> tosa.transpose
merging canonicalization.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
This is good idea!
I am wondering if we can use the "benefit" (https://mlir.llvm.org/docs/PatternRewriter/#benefit) mechnism here of Pattern Rewriting, something like:
enum TransposeRewriteBenefit : uint8_t { None = 0, ReshapeTranspose, ConsolidateTransposes, } TransposeBenefit;
And then use is in c'tors:
TransposeIsReshape(MLIRContext *context) : OpRewritePattern(context, ReshapeTranspose) {} ConsolidateTransposeOptimization(MLIRContext *context) : OpRewritePattern(context, ConsolidateTransposes) {}
More at: https://mlir.llvm.org/docs/DeclarativeRewrites/#adjusting-benefits
Unfortunately benefit cannot be used to target the beneficial pattern as the transpose-transpose case depends on the interaction of two operations. Depending on the processing order it is possible for the top-most case to canonicalize to a reshape and be unable to merge with the consuming transpose. It may be possible to rearrange whether a consumer/producer is checked for being a transpose allowing the benefit pattern to be used however if a pattern used the canonicalization patterns but processed it in the opposite ordering it would then fail.