[flang-commits] [flang] [flang] Lowering fortran structured do-while loops to `scf.while` (PR #177476)

via flang-commits flang-commits at lists.llvm.org
Mon Jan 26 06:53:43 PST 2026


================
@@ -2482,6 +2529,17 @@ class FirConverter : public Fortran::lower::AbstractConverter {
     } else if ((whileCondition =
                     std::get_if<Fortran::parser::ScalarLogicalExpr>(
                         &loopControl->u))) {
+      // Optionally lower a restricted subset of DO WHILE loops directly to
+      // scf.while. This subset excludes early-exit constructs (EXIT/CYCLE/GOTO,
+      // etc.) by requiring that the loop body is structured (as decided by the
+      // PFT branch analysis), allowing the loop to exit only when the condition
+      // becomes false.
+      if (Fortran::lower::lowerDoWhileToSCFWhile && !unstructuredContext) {
----------------
jeanPerier wrote:

No need to have the option twice, better removing it from Bridge.cpp I think.

It does not brings much and opens the door to thinking that it is possible to have `!unstructuredContext` and still have `Fortran::lower::lowerDoWhileToSCFWhile` which would lead to hit the assert below.

https://github.com/llvm/llvm-project/pull/177476


More information about the flang-commits mailing list