This revision folds transpose splat to a new splat with the transposed vector type. For a splat, there is no need to actually do transpose for it, it would be more effective to just build a new splat as the result, especially for a constant splat.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Please add longer descriptions to commits that explain _why_ the change is being made. I understand that canonicalization patterns are generally useful for code simplification, but something must have prompted you to add this specific pattern.
mlir/lib/Dialect/Vector/IR/VectorOps.cpp | ||
---|---|---|
4408 | The (result) type of the transpose op cannot be anything else than a vector, so just cast here. The code does not seem to handle the case where it is not a vector anyway... |
Thanks, I added the description to this revision.
mlir/lib/Dialect/Vector/IR/VectorOps.cpp | ||
---|---|---|
4408 | Done. |
mlir/lib/Dialect/Vector/IR/VectorOps.cpp | ||
---|---|---|
4408 | Use cast instead of dyn_cast, it asserts on mismatching types rather than returning null that may segfault. (https://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates) |
The following patch just landed and should handle the constant case of the folding, can you remove it from the canonicalization?
https://reviews.llvm.org/D123595
mlir/lib/Dialect/Vector/IR/VectorOps.cpp | ||
---|---|---|
4408 | Those code was removed cause of https://reviews.llvm.org/D123595 already implemented fold transpose constant splat. |
mlir/lib/Dialect/Vector/IR/VectorOps.cpp | ||
---|---|---|
4402–4407 | nit: prefer early exit (https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code) auto splatOp = transposeOp.getVector().getDefiningOp<vector::SplatOp>() if(!splatOp) return failure(); rewriter.replaceOpWithNewOp<vector::SplatOp>( transposeOp, transposeOp.getResultType(), splatOp.getInput()); return success(); |
nit: prefer early exit (https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code)
it could be: