[flang-commits] [flang] [llvm] [mlir] [flang][OpenMP] Support the FULL clause on the UNROLL construct (PR #214115)

Spencer Bryngelson via flang-commits flang-commits at lists.llvm.org
Wed Aug 5 07:25:03 PDT 2026


sbryngelson wrote:

Thanks. All three addressed, though two of them turned up something.

**`GetNestedLoop`** — done, much neater.

**Verifier** — added, but not the constant-bounds part, and I would like your read. flang emits the
trip count as a computed value even for a literal loop:

```mlir
%14 = arith.select %13, %c0_i32, %12 : i32
omp.canonical_loop(%canonloop) %iv : i32 in range(%14) { ... }
omp.unroll_full(%canonloop)
```

so `matchPattern(tripCount, m_Constant())` rejects flang's own output for `do i = 1, 100` — it
failed my two new tests. Verifiers run before folding, and `getConstantIntValue` only matches
literal constants too, so I could not find a way to express "constant after folding" at that
boundary. The verifier currently checks only that the applyee has a generator.

Options I can see: leave it to semantics; have flang fold the trip count before emitting; or add a
fold-aware check. Happy to do whichever you prefer.

**Test with `tile`** — I cannot write a lowering test for it, because the composition is broken
today, and not by this patch:

| outer | ops emitted |
|---|---|
| `unroll full` + `tile` | `omp.unroll_full` only, tile dropped |
| `unroll` + `tile` | `omp.unroll_heuristic` only, tile dropped |
| `unroll partial(2)` + `tile` | `omp.unroll_partial` only, tile dropped |
| `tile` alone | `omp.tile (%grid1, %intratile1) <- (%canonloop) sizes(...)` |

`getNestedDoConstruct` descends through an intervening OpenMP construct to reach the DO
(`Utils.cpp`, "Loop transformations can introduce nested OpenMP constructs between the directive
and the actual do-loop nest"), so the nested construct is never lowered. Chaining properly needs
the unrolled loop as a generatee, which `omp.unroll_*` does not provide.

Since it affects the two unroll forms that predate this PR, I have not tried to implement chaining
here. What I did add is a `TODO` so the nested construct is diagnosed instead of silently dropped,
plus `flang/test/Lower/OpenMP/Todo/unroll-nested-transform.f90`. Say the word if you would rather
that be a separate patch and I will split it out.

Every other composition I tried is already rejected with "This construct requires a canonical loop
nest": `parallel do` + `unroll full`, `do` + `unroll full`, and `tile` + `unroll full`.


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


More information about the flang-commits mailing list