In some cases the casted buffer could be allocated in the destination's type.
By rebuilding the allocating op with the matching type, the memref.cast is not needed.
Details
- Reviewers
nicolasvasilache mehdi_amini
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp | ||
---|---|---|
374–377 | ||
382 | ||
383 | When does this happen? | |
397 | Avoid isa + cast : use dyn_cast instead. | |
405 | Can we do all of this in a single traversal of alloc->getUsers() instead of 3? | |
mlir/test/Dialect/MemRef/canonicalize.mlir | ||
957 | Is this useful to check? | |
959 | Same here, I'm not sure this is necessary to check here. Checking the alloc and the NOT: cast seems like capturing the intent of the test I think. | |
971 | Can you add negative tests? Basically we should have a case for each of the return failure() you have in the pattern I think. |
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp | ||
---|---|---|
383 | When castOp result is an UnrankedMemRefType, it cannot be casted to MemRefType. |
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp | ||
---|---|---|
365 | Is this valid for all operations in the memref dialect? Also what about something like: %alloc = memref.alloc(...) : memref<?x?xf32> %memref.copy %alloc, ... if (%cond) { %casted = memref.cast %alloc : memref<?x?xf32> to memref<4x4xf32> ... } The control flow should prevent the folding, because the cast may not be reachable I think? | |
383 | Ah! Forgot about unranked... It does not help that for Tensor the hierarchy is named with a different convention... | |
401 | This logic seems overly complex because the interaction between isValidUser and this (they both check for CastOp for example`, and getting the result MemrefType of the cast use. What does it look like if we inline isValidUser here instead? |
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp | ||
---|---|---|
365 | I think post-dominate is the condition strictly speaking, but "same block" is a good start for now. |
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp | ||
---|---|---|
365 | Added a test with scf.if and blocked it. |
Is this valid for all operations in the memref dialect?
Also what about something like:
The control flow should prevent the folding, because the cast may not be reachable I think?