[Flang][OpenMP] - Excessive compile time when `_FortranAAssign` is called in OpenMP target regions
@bhandarkar-pranav is already working on this.
Since Jun 15, 2026.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Description
OpenMP target regions that generate calls to _FortranAAssign experience significantly longer compile times. This occurs when using the firstprivate clause, which requires copying array data to the device. The compile time overhead is approximately 30x compared to equivalent code using private (which does not generate _FortranAAssign calls).
Reproducer - Slow Case (with firstprivate)
! test_firstprivate.f90
! This version uses firstprivate, which generates _FortranAAssign calls
program test_firstprivate
implicit none
integer, allocatable :: arr(:)
integer :: source(8)
integer :: result
integer :: i
! Initialize source array
do i = 1, 8
source(i) = i * 10
end do
! Allocate array
allocate(arr(8))
arr(:) = 0
!$omp target firstprivate(source) map(tofrom: arr) map(from: result)
! firstprivate(source) causes _FortranAAssign to be called
arr(:) = source(:)
result = arr(1) + arr(8)
!$omp end target
end program test_firstprivate
Compile time: ~29 seconds
Comparison - Fast Case (with private)
! test_firstprivate.f90
! This version uses firstprivate, which generates _FortranAAssign calls
program test_private
implicit none
integer, allocatable :: arr(:)
integer :: source(8)
integer :: result
integer :: i
! Initialize source array
do i = 1, 8
source(i) = i * 10
end do
! Allocate array
allocate(arr(8))
arr(:) = 0
!$omp target private(source) map(tofrom: arr) map(from: result)
! firstprivate(source) causes _FortranAAssign to be called
arr(:) = source(:)
result = arr(1) + arr(8)
!$omp end target
deallocate(arr)
end program test_private
Compile time: ~0.9 seconds
Build Command
flang-new -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -O2 test_firstprivate.f90 -o test.out
Root Cause
The firstprivate clause requires the runtime to set up array data on the device side based on the array on the host. This generates calls to _FortranAAssign.
The private clause, by contrast, only allocates the array on the device without copying data, avoiding calls to _FortranAAssign entirely.
Impact
- 30x compile-time overhead when using
firstprivatecompared toprivate - This makes development iteration times impractical for codes using
firstprivatearrays with OpenMP GPU offloading - The overhead is present regardless of array size or complexity
Environment
- Compiler: flang-new (upstream LLVM/Flang main branch)
- Target:
amdgcn-amd-amdhsa(AMD GPU) - Optimization level:
-O2 - OpenMP flags:
-fopenmp -fopenmp-targets=amdgcn-amd-amdhsa
Also related to https://github.com/llvm/llvm-project/issues/200922
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.