| Issue |
203228
|
| Summary |
[flang] Poor performance in flang for array section assignment due to excessive _FortranAAssign runtime calls.
|
| Labels |
flang,
flang-rt
|
| Assignees |
kaviya2510
|
| Reporter |
kaviya2510
|
Flang generates inefficient code for a simple array section resulting in poor performance compared to gfortran and ifx. The root cause appears to be excessive `_FortranAAssign` runtime call leading to millions of memmove calls (4 bytes each) instead of generating efficient bulk memory copies or vectorized loops.
Testcase:
```fortran
subroutine self_copy_ew(field, xm, ym, levs, xh, yh)
integer, intent(in) :: xm, ym, levs, xh, yh
real, intent(inout) :: field(xm + 2 * xh, ym + 2 * yh, levs)
integer :: x1, x2, x5, x6
x1 = 1
x2 = xh
x5 = xh + xm - xh + 1
x6 = xh + xm
field(x1:x2, :, :) = field(x5:x6, :, :)
end subroutine self_copy_ew
program test
implicit none
integer, parameter :: XM = 20, YM = 11, LEVS = 70, XH = 2
integer, parameter :: NCALLS = 50000
real, allocatable :: field(:,:,:)
integer :: i
real :: t0, t1
allocate(field(XM + 2 * XH, YM + 2 * XH, LEVS))
call random_number(field)
call cpu_time(t0)
do i = 1, NCALLS
call self_copy_ew(field, XM, YM, LEVS, XH, XH)
end do
call cpu_time(t1)
write(*,'(A,F8.4,A)') 'Time: ', t1-t0, ' s'
deallocate(field)
end program test
```
| Compiler | Time (s) |
|-------------|---------:|
| gfortran | 0.0759 |
| ifx | 0.1444 |
| flang | 1.9304 |
flang is:
- ~25× slower than gfortran
- ~13× slower than ifx
Godbolt link: https://godbolt.org/z/ehE4fG4Er
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs