https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128542
Bug ID: 128542
Summary: Do array slice copies with __builtin_memcpy if they
are contiguous
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: tkoenig at gcc dot gnu.org
Target Milestone: ---
Test case from PR128431:
subroutine foo (from_small, to_small, from_buf, to_buf)
implicit none
unsigned(8), value :: from_small, to_small
unsigned(1), dimension(41), intent(out) :: from_buf, to_buf
integer, parameter :: grpsz = 6, tabsz=729
integer :: i, k
unsigned(16), parameter :: base = 3u_16
integer, parameter :: n_grp = int(64 * log(2.0)/log(real(base)) / grpsz) !
rounding down
integer, parameter :: halfsize = n_grp * grpsz
unsigned(kind=1), dimension(0:grpsz-1,0:tabsz-1), parameter :: tab = reshape
([ &
((mod(uint(k)/base**uint(i), base), i=0, grpsz-1), k=0, tabsz-1) &
], shape = [grpsz,tabsz])
unsigned, parameter :: tabszu = uint(tabsz)
unsigned(8) :: from_rem, to_rem
do i=0, halfsize-1, grpsz
to_rem = mod(to_small, tabszu)
to_small = to_small / tabszu
from_rem = mod(from_small, tabszu)
from_small = mod(from_small, tabszu)
to_buf (i:i+grpsz-1) = tab(:,int(to_rem))
from_buf (i:i+grpsz-1) = tab(:,int(from_rem))
end do
end subroutine foo
The two array slice copies could be done with memcpy to give the middle
end better inforrmation. (PR 128431 also shows that the middle end
translates this suboptimally, but the Fortran front end can also makes things
easier here).
In this particular case, tab is a parameter, but an array gives the same
effect.