llvm-project
fcd548f9 - [flang][OpenACC] Skip non-loop evaluations when descending a collapsed/tiled DO nest (#223579)

Commit
18 days ago
[flang][OpenACC] Skip non-loop evaluations when descending a collapsed/tiled DO nest (#223579) ## Summary - The collapse/tile loop-nest descent in `Bridge.cpp` (used for OpenACC `collapse`/`tile` and CUDA Fortran `!$cuf kernel do`) assumed each loop level's nested evaluations have the fixed shape `{NonLabelDoStmt, DoConstruct, EndDoStmt}` and unconditionally advanced to the second nested evaluation to find the next inner `DO`. - A compiler directive (e.g. `!DIR$ IVDEP`) placed between loop levels inserts an extra sibling evaluation there, so the descent landed on the directive instead of the inner `DoConstruct` and lowered the directive's (empty) nested evaluations as the loop body — silently dropping the real body with no diagnostic. - Adds a helper that searches a level's nested evaluations for the actual `DoConstruct`, matching the approach already used by `visitLoopControl` in `OpenACC.cpp`, and uses it at all three affected descent sites (OpenACC collapse/tile, and the two CUDA Fortran kernel-do sites). ## Test plan - New lit test `flang/test/Lower/OpenACC/acc-loop-collapse-directive-between-loops.f90` covering `collapse(2)` with `!DIR$ IVDEP` and `collapse(3)` with `!DIR$ NOVECTOR` between loop levels. - Verified the new test fails without the fix (directive absorbed as loop body, no `hlfir.assign` for the real body) and passes with it. - Existing `acc-loop-collapse-force-lowering.f90`, `acc-loop-collapse-force-non-tightly-nested.f90`, `do-concurrent-collapse.f90`, `cuda-kernel-loop-directive.cuf`, `cuda-kernel-do-reduction.cuf` all still pass.
Author
Parents
Loading