| Issue |
233562
|
| Summary |
[flang][OpenMP] METADIRECTIVE drops a runtime-condition variant on a different dummy argument
|
| Labels |
flang:openmp
|
| Assignees |
chichunchen
|
| Reporter |
chichunchen
|
When a METADIRECTIVE condition is false at runtime, Flang removes the later candidates that test the same condition. It decides whether two conditions are the same with `evaluate::Expr` equality, which treats dummy arguments of different procedures at the same position as equal. A condition on a host-associated dummy argument and one on a local dummy argument are therefore treated as the same, and the second variant is never tried.
https://godbolt.org/z/9bfv4s9Td:
```fortran
subroutine host_dummy(a, n)
logical, intent(in) :: a
integer, intent(in) :: n
call inner(a, n)
contains
subroutine inner(b, m)
logical, intent(in) :: b
integer, intent(in) :: m
integer :: i
!$omp metadirective &
!$omp& when(user={condition(a)}: simd) &
!$omp& when(user={condition(b)}: do) &
!$omp& otherwise(nothing)
do i = 1, m
end do
end subroutine
end subroutine
```
```
flang -fc1 -fopenmp -fopenmp-version=52 -emit-hlfir repro.f90 -o -
```
Expected:
```fortran
if (a) then
! SIMD
else if (b) then
! DO
else
! plain loop
end if
```
Actual: the DO variant is dropped, so the loop isn't workshared when `a` is false and `b` is true:
```fortran
if (a) then
! SIMD
else
! plain loop
end if
```
`when(user={condition(a .and. b)}: simd) when(user={condition(a)}: do)` fails the same way. The check rewrites `x .and. x` as `x`, and with `a` and `b` treated as equal, `a .and. b` becomes `a`. When `a .and. b` is false, the `condition(a)` candidate is dropped even though `a` may still be true.
The comparison is `AreSameRepeatableMetadirectiveCondition` in `flang/lib/Semantics/openmp-utils.cpp`. The positional equality comes from `AreSameSymbol` in `flang/lib/Evaluate/variable.cpp`, which is meant for comparing procedure characteristics.
Assisted with Github Copilot and Claude Opus 5.5.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs