https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128542
--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Thomas Koenig <[email protected]>: https://gcc.gnu.org/g:c548a927b535fd8cb003e4b51aa4225613669905 commit r17-6285-gc548a927b535fd8cb003e4b51aa4225613669905 Author: Thomas Koenig <[email protected]> Date: Sat Nov 14 10:47:45 2026 +0100 Use memcpy/memmove for contiguous array slice copies. This patch was motivated by the observation that the middle and back ends currently generate inefficient code for what our scalarizers generate for copies of contiguous array slices. It modifies the contitions for issuing __builtin_memcpy so that variable-sized arrays and array slices are handled. While I looked at the code, I found that generating temporaries could be avoided in some cases by using memmove, so I added that as well. gcc/fortran/ChangeLog: PR fortran/128542 PR fortran/40598 * trans-expr.cc (gfc_build_compare_string): Correct comment. (gfc_build_memcpy_call): If use_memmove is true, call __builtin_memmove. (gfc_trans_array_copy): Also handle array slices and arrays whose extents are not known at compile-time, including bounds checking. (copyable_slice_p): New function. (gfc_trans_assignment): Use copyable_slice_p and do not check dependency before calling gfc_trans_array_copy. * trans.h (gfc_build_memcpy_call): Add optional argument use_memmove. gcc/testsuite/ChangeLog: PR fortran/128542 PR fortran/40598 * gfortran.dg/array_temporaries_1.f90: One less temporary created. Add check for memmove. * gfortran.dg/dependency_28.f90: Likewise. * gfortran.dg/elemental_dependency_1.f90: Remove variable names from original dump scan. Add memcpy calls. * gfortran.dg/array_memcpy_6.f90: New test.
