Fold away empty loops that iterate at least once and only return
values defined outside of the loop.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
I'll let @bondhugula clarify but my impression about his comment in D120776 is that we should be able to have a single implementation that works for both ScfForOp and AffineForOp by using/extending interfaces like LoopLikeInterface? Maybe I got it wrong. In any case, adding a scf specific implementation is also great. Thanks!
mlir/test/Dialect/SCF/canonicalize.mlir | ||
---|---|---|
363 | Please, add // ----- before the new test. |
mlir/lib/Dialect/SCF/SCF.cpp | ||
---|---|---|
763 | If the loop is known to have 0 iteration, we would have removed the loop and returned success: line 711-714. | |
mlir/test/Dialect/SCF/canonicalize.mlir | ||
363 | for_yields_2, for_yields_3, and for_yields_4 all use make_i32() declared before for_yields_2, thus no // ----- between them. |
mlir/lib/Dialect/SCF/SCF.cpp | ||
---|---|---|
761 | This check isn't tight enough: |
mlir/lib/Dialect/SCF/SCF.cpp | ||
---|---|---|
761 | When lbValue >= ubValue, the loop does not iterate, so we do not fold. When lbValue + step - 1 <= ubValue, the loop can still iterate. For example, if lbValue = 0, step = 1, and ubValue = 1, we have 0 + 1 - 1 <= 1, but the loop iterates once. |
This check isn't tight enough:
lbValue + step - 1 <= ubValue?