I’m a newbie for MLIR and curious about scf.for / while loop transform pass.
When I tried to understood the scf.for / while transform pass, I saw the some facts.
Most of the transform passes are for loops, and there is no transform for while loops. (only have a oneToNTypeConversion). Just, there was a pass to convert scf for loop into while loop. Here, my question is as follows.
- Why do most of the transformations for loops exist?
- Is for loop better than while loop? Other compilers have a while loop related canonization pass, but it does not seem to be in the scf of mlir.
- Is there any clear distinction between optimization (Transform, analysis) that can only be applied to While and optimization that can only be applied to For?
- If anyone knows about other compilers, I would appreciate it if you could answer me. Mainly, what kind of case is the dominant use of optimization pass for one type of loop (for or while)?
Just speculating, but the reason why you are seeing more
scf.for op related transforms than
scf.while op related transforms may be:
- In many cases,
scf.for loops are sufficient (e.g., tiling). I did not run into a situation where I really needed an
scf.while loop so far.
scf.while loops are more complex than
scf.for loops: they have two regions. It is easier to make mistakes. When I write
scf.for transforms (e.g., the bufferization implementation), I often get it right the first time. When I write
scf.while transforms, I rarely get it right the first time. So users may be reluctant to use the op.
Thanks for your comment! I have a more question about scf-for-to-while.
- Is there any problem to apply scf-for-to-while pass after all applicable for loop optmization? In other words, can scf-for-to-while cover any form of for loop?
- Current “scf.for” loop canonicalization and specialization, When I ran the example of these passes, It seemed to be executed by including “affine.ops”. (ex. affine.min / max). for loop that do not include affine, it seems that they cannot be converted to a Canonical form, but in this case, should I implement it myself?