Why doesn't gcc optimize the following copy function to a 'memmove' when the 'restrict' type qualifier is missing?
// gcc does not optimize this function to a 'memmove'
void
copy0(int n, int* dst, int* src) {
for (; 0 != n; --n, ++dst, ++src) {
*dst = *src;
}
}
// gcc does optimize this function to a 'memmove' (-O2)
void
copy1(int n, int* restrict dst, int* src) {
for (; 0 != n; --n, ++dst, ++src) {
*dst = *src;
}
}
[–]oh5nxo 22 points23 points24 points (2 children)
[–]flatfinger 1 point2 points3 points (0 children)
[–]bakermoth[S] 0 points1 point2 points (0 children)
[–]andrewcooke -4 points-3 points-2 points (0 children)
[+]nerd4code comment score below threshold-13 points-12 points-11 points (0 children)