<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/65038>65038</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] [hlfir] execution time comparison between with/without -flang-experimental-hlfir
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
k-arrows
</td>
</tr>
</table>
<pre>
Consider the following code:
(only "explicit DO loops" part from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52473#c10)
```console
$ cat testme.f90
module kinds
integer, parameter :: sp = selected_real_kind(6) ! Single precision
integer, parameter :: dp = selected_real_kind(15) ! Double precision
end module kinds
module replacements
use kinds
contains
subroutine cshift_sp_3_v1 (array, shift, dim, res)
integer, parameter :: wp = sp
real(kind=wp), dimension(:,:,:), intent(in), contiguous :: array
integer, intent(in) :: shift, dim
real(kind=wp), dimension(:,:,:), intent(out), contiguous :: res
integer :: i,j,k
integer :: sh, rsh
integer :: n
res = 0
if (dim == 1) then
n = size(array,1)
sh = modulo(shift, n)
rsh = n - sh
do k=1, size(array,3)
do j=1, size(array,2)
do i=1, rsh
res(i,j,k) = array(i+sh,j,k)
end do
do i=rsh+1,n
res(i,j,k) = array(i-rsh,j,k)
end do
end do
end do
else if (dim == 2) then
n = size(array,2)
sh = modulo(shift,n)
rsh = n - sh
do k=1, size(array,3)
do j=1, rsh
do i=1, size(array,1)
res(i,j,k) = array(i,j+sh, k)
end do
end do
do j=rsh+1, n
do i=1, size(array,1)
res(i,j,k) = array(i,j-rsh, k)
end do
end do
end do
else if (dim == 3) then
n = size(array,3)
sh = modulo(shift, n)
rsh = n - sh
do k=1, rsh
do j=1, size(array,2)
do i=1, size(array,1)
res(i,j,k) = array(i, j, k+sh)
end do
end do
end do
do k=rsh+1, n
do j=1, size(array,2)
do i=1, size(array,1)
res(i,j, k) = array(i, j, k-rsh)
end do
end do
end do
else
stop "Wrong argument to dim"
end if
end subroutine cshift_sp_3_v1
end module replacements
program testme
use kinds
use replacements
implicit none
integer, parameter :: wp = sp ! Working precision
INTEGER, PARAMETER :: n = 200
real(kind=wp) :: a(n,n,n), b(n,n,n)
integer i, j, k
real t1, t2
print *,"Testing explicit DO loops"
call random_number(a)
do k = 1,3
call cpu_time ( t1 )
do j = 1, 100
call cshift_sp_3_v1 (a, 1, k, b)
end do
call cpu_time ( t2 )
write ( *, * ) 'Dim = ', k, ' Elapsed CPU time = ', t2-t1
end do
end program testme
```
Result (on my WSL2, with flang-new which I recently built)
```console
$ flang-new -Ofast testme.f90
$ ./a.out
Testing explicit DO loops
Dim = 1 Elapsed CPU time = .5384389
Dim = 2 Elapsed CPU time = .5455937
Dim = 3 Elapsed CPU time = .51351356
$ flang-new -Ofast -flang-experimental-hlfir testme.f90
$ ./a.out
Testing explicit DO loops
Dim = 1 Elapsed CPU time = 7.887358
Dim = 2 Elapsed CPU time = 7.938386
Dim = 3 Elapsed CPU time = 7.9478416
```
I would like to know what methods can be taken to understand the reasons for these kinds of performance differences.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8WFuP4joS_jXmpQRKHALhgYduaFYj7e456jOreUROUkncOHZkO4fp-fUrOwHCrYe57CJEwHWv-my-hBnDS4m4JPEzidcj1tpK6eVuzLRWezNKVf6-XClpeI4abIVQKCHUnssSMpUjiZ5IsCbBE6GJkuIdCKX4tRE84xbWf4BQqjGEUmiYtlBoVUNlbWOcHd0QuimzbFLKdqJ0SegmbctvXAhG6MZUar9N23KSlZxEG56TaB3T6TwiNMrCgNBFH3gWdO9MSaMEHtKZQsYsWDS2xkmxCLr1WuWtQNhxmZtuBYBLiyVqQlcuS1ajRQ0uwegJTAMkWoNBgZnFfKuRia2zJjSZEboAQkP4i8tSIDQaM264ko84zj9wHMYHz2vVpteeUeZwXchZgRobwTKsUdpjna0508-UtIzLo9i0qVat5RIhMxUv7NY022j7dwiEJkxr9u4K8RL3Jee1u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