[flang-commits] [flang] [flang][OpenMP] Lower DO and SIMD variants in metadirectives (PR #210810)
via flang-commits
flang-commits at lists.llvm.org
Tue Jul 28 02:08:05 PDT 2026
================
@@ -30,6 +29,52 @@ subroutine test_vendor_no_match()
#endif
end subroutine
+! An inapplicable variant must not have its clauses lowered.
+! CHECK-LABEL: func.func @_QPtest_inapplicable_assume()
+! CHECK: fir.call @_FortranAioOutputInteger32
+! CHECK-NOT: fir.call @_FortranAioOutputInteger32
----------------
MattPD wrote:
I said the excluded `assume` variant lowers to `llvm.intr.assume`, but it doesn't.
I locally flipped the vendor in `test_inapplicable_assume` to `llvm`, so `assume` wins selection. Lowering aborts:
```
Unimplemented: holds
UNREACHABLE executed at flang/lib/Lower/OpenMP/Clauses.cpp:1033!
```
Variant lowering routes every clause through that `Clauses.cpp` path, where `Holds` is an `llvm_unreachable`. Only the direct `!$omp assume` path calls `AssumeOp::create`. So no variant emits `llvm.intr.assume`, selected or not, and these `CHECK-NOT` lines cannot fail.
That leaves `test_unselected_fallback_clause` and `test_unselected_ranked_clause` testing nothing.
Can you anchor on a clause operand that variant lowering emits? This works on your branch at 5.1 and 5.2:
```fortran
! CHECK-LABEL: func.func @_QPtest_selected_num_threads(
! CHECK: fir.call @_QPf
! CHECK: omp.parallel num_threads(
subroutine test_selected_num_threads(x)
integer :: x
integer :: f
external :: f
!$omp begin metadirective &
!$omp & when(implementation={vendor(llvm)}: parallel num_threads(f())) &
!$omp & otherwise(nothing)
x = 1
!$omp end metadirective
end subroutine
! CHECK-LABEL: func.func @_QPtest_unselected_num_threads(
! CHECK-NOT: fir.call @_QPf
! CHECK-NOT: omp.parallel
! CHECK: return
subroutine test_unselected_num_threads(x)
integer :: x
integer :: f
external :: f
!$omp begin metadirective &
!$omp & when(implementation={vendor("unknown")}: parallel num_threads(f())) &
!$omp & otherwise(nothing)
x = 1
!$omp end metadirective
end subroutine
```
The first is the missing positive control. Both need the `#ifdef OMP_52` split.
The abort predates this PR. Filed as https://github.com/llvm/llvm-project/issues/212437.
https://github.com/llvm/llvm-project/pull/210810
More information about the flang-commits
mailing list