[all-commits] [llvm/llvm-project] 046448: [flang] Lower loops with unstructured internals as...
Kareem Ergawy via All-commits
all-commits at lists.llvm.org
Tue Sep 22 00:38:35 PDT 2026
Branch: refs/heads/users/ergawy/unstructured-lower-category-c
Home: https://github.com/llvm/llvm-project
Commit: 046448a9c0b2b081231ffa9e401f51dbd204d7af
https://github.com/llvm/llvm-project/commit/046448a9c0b2b081231ffa9e401f51dbd204d7af
Author: ergawy <kareem.ergawy at gmail.com>
Date: 2026-09-21 (Mon, 21 Sep 2026)
Changed paths:
M flang/include/flang/Lower/AbstractConverter.h
M flang/include/flang/Lower/PFTBuilder.h
M flang/lib/Lower/Bridge.cpp
M flang/lib/Lower/OpenMP/OpenMP.cpp
M flang/lib/Lower/PFTBuilder.cpp
M flang/test/Lower/OpenACC/acc-cache.f90
A flang/test/Lower/OpenACC/acc-unstructured-internals.f90
M flang/test/Lower/OpenACC/acc-unstructured.f90
R flang/test/Lower/OpenMP/Todo/metadirective-loop-unstructured.f90
A flang/test/Lower/OpenMP/metadirective-loop-unstructured.f90
M flang/test/Lower/OpenMP/wsloop-unstructured-cycle.f90
A flang/test/Lower/OpenMP/wsloop-unstructured-internals.f90
M flang/test/Lower/always-execute-loop-body.f90
M flang/test/Lower/do_loop_unstructured.f90
M flang/test/Lower/select-case-statement.f90
Log Message:
-----------
[flang] Lower loops with unstructured internals as structured ops
A loop whose control flow is structured but whose branching is confined
to its body was detected in a previous change and classified separately
from a fully unstructured loop, but it still lowered the same way: the
loop dissolved into a raw CFG and its structured form was lost.
Lower it structurally instead. The body -- everything but the loop
control -- is folded into an scf.execute_region, which may hold as many
blocks as the branching needs while the loop op's own region stays a
single well formed block. The loop keeps its bounds on the op, so it is
still available to whatever wants to transform or parallelize it.
A CYCLE targets the EndDoStmt, which is the boundary between the loop
body and the loop control. Inside the wrap that boundary is the region's
yield block, so the EndDoStmt's block is remapped to the yield for the
extent of the wrap and restored afterwards. This mirrors what the
whole-construct wrap already does with constructExit.
Directive lowering consumes the DO itself and never reaches
genFIR(DoConstruct), where a plain loop's body is wrapped, so the wrap is
driven through a new AbstractConverter::withWrappedLoopBody hook and
applied at each site that lowers a loop body on its own: the OpenMP body
lowering, the collapsed-DO early return, and the acc.loop early return.
Sharing one hook keeps the EndDoStmt remapping from drifting between
them.
Also exclude a REAL control variable from the classification. Bounds
loop control says nothing about the type of its bounds, and a REAL DO
cannot form a fir.do_loop, whose induction variable must be a signless
integer or index.
Tests that pinned the previous lowering are updated. The metadirective
case is no longer rejected as not yet implemented, so its test moves out
of Todo/ and asserts the lowering it now gets. always-execute-loop-body
keeps an unstructured loop, since the trip count it checks only exists on
that path. New tests cover the classification under both OpenACC and
OpenMP, including a loop whose GOTO jumps over an inner loop.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list