For the most common array assignments where the size is known at compile-time, we already use __buildin_memcpy; but the following cases were missed:
subroutine bar(a) implicit none real :: a(*),b(12) b = a(1:12) end subroutine subroutine bar(a,b) implicit none real :: a(*),b(*) a(1:12) = b(2:13) end subroutine And __buildin_memset can be used for: subroutine bar(a) implicit none real :: a(*),b(12) a(1:12) = 12 end subroutine For the following examples, the __buildin_* function can not be used as the size is not known at compile time, but the memory should be contiguous and thus __memcpy can be used: subroutine bar(a,n) implicit none integer :: n real :: a(n), b(n) a = b end subroutine For the following case, one could use memset, but I'm not sure whether it will be on average be faster than a normal do loop. (Overhead of function call versus the optimization of memset using e.g. copy-on-write.) subroutine bar(a,n) implicit none integer :: n real :: a(n) a = 5 end subroutine -- Summary: Use __buildin_memcpy and __memcpy for array assignment Product: gcc Version: 4.3.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: burnus at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31016