[flang-commits] [flang] [llvm] [flang][OpenMP] Track reachable metadirective replacements (PR #219014)
via flang-commits
flang-commits at lists.llvm.org
Wed Sep 9 19:47:40 PDT 2026
================
@@ -2448,6 +2448,20 @@ static void AppendConstructTraitsForDirective(
add(llvm::omp::TraitProperty::construct_dispatch_dispatch);
}
+void AppendConstructTraitsForSelector(const parser::OmpTraitSelectorName &name,
+ llvm::omp::VariantMatchInfo &vmi) {
+ if (const auto *dir{std::get_if<llvm::omp::Directive>(&name.u)}) {
+ AppendConstructTraitsForDirective(*dir, vmi);
+ } else if (const auto *value{
+ std::get_if<parser::OmpTraitSelectorName::Value>(&name.u)}) {
+ // SIMD is parsed as a predefined selector name because it can also take
+ // clause properties, unlike the other construct selectors.
+ if (*value == parser::OmpTraitSelectorName::Value::Simd) {
+ AppendConstructTraitsForDirective(llvm::omp::Directive::OMPD_simd, vmi);
----------------
MattPD wrote:
Could `collectEnclosingConstructTraits` also supply the SIMD trait? `DECLARE VARIANT` uses `AppendConstructTraitsForSelector`, but the lowering collector never records `omp.simd`.
Save this as `repro.f90` and run `flang -fc1 -fopenmp -fopenmp-version=52 -emit-hlfir -o - repro.f90`. Revision `7f525837ea63` emits `fir.call @_QMmPbase` inside `omp.simd`, whereas [the base revision](https://github.com/llvm/llvm-project/commit/89082772bed1ed16c0311b12147a96c35bb063d8) emits `fir.call @_QMmPsimd_var`. The call should select the SIMD variant. Please cover this inside-SIMD case alongside the correctly fixed outside-SIMD case.
```fortran
module m
contains
subroutine base(x)
!$omp declare variant(simd_var) match(construct={simd})
real :: x
x = x + 1.0
end subroutine
subroutine simd_var(x)
real :: x
x = x + 2.0
end subroutine
end module
subroutine test(a, n)
use m
integer :: n, i
real :: a(n)
!$omp simd
do i = 1, n
call base(a(i))
end do
end subroutine
```
https://github.com/llvm/llvm-project/pull/219014
More information about the flang-commits
mailing list