Enhance 'ForOpIterArgsFolder' to remove unused iteration arguments in a
scf::ForOp. If the block argument corresponding to the given iterator has no
use and the yielded value equals the input, we fold it away.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Did you consider extending the existing ForOpIterArgsFolder to capture this case ?
The existing one will drop if you yield the bbarg directly (i.e. scf.yield %1, %arg3 : i32, i32 in your example).
It should be pretty straightforward to extend the condition here:
// Forwarded is `true` when the region `iter` argument is yielded. bool forwarded = (std::get<1>(it) == std::get<2>(it)); keepMask.push_back(!forwarded); canonicalize |= forwarded; if (forwarded) {
to capture the additional condition you want ?
mlir/include/mlir/IR/BlockAndValueMapping.h | ||
---|---|---|
80 | These methods should match the traditional datastructure methods, i.e. empty() |
Updating D98503: Canonicalization for scf::ForOp
- Use 'forOpIterArgsFolder' as suggested.
@rriddle and @nicolasvasilache thanks for the suggestions. @nicolasvasilache I updated the code as you suggested. Indeed it simplified a lot.
@nicolasvasilache I have just updated the comments. Could you please land this revision? (I don't have commit access) Thanks!
These methods should match the traditional datastructure methods, i.e. empty()