| Issue |
169649
|
| Summary |
LLVM doesn't make use of the return value of memcpy
|
| Labels |
missed-optimization
|
| Assignees |
|
| Reporter |
philnik777
|
`memcpy` always returns the destination pointer. This can be used to reduce the number of registers used if the destination pointer is used after a `memcpy`. However, Clang/LLVM currently doesn't make use of this AFAICT.
```c++
#include <cstddef>
auto test(int** dest, int* old_ptr, size_t old_cap, size_t size, size_t new_cap) {
auto new_ptr = ::operator new(new_cap * sizeof(int));
*dest = (int*)__builtin_memcpy(new_ptr, old_ptr, size * sizeof(int));
::operator delete(old_ptr, old_cap);
}
```
In the above example, there is an additional register used to save the `new_ptr` and store it after the call to `memcpy`. The return value of `memcpy` could be used instead though. GCC makes use of this and generates better code as a result: https://godbolt.org/z/jWvzWqnYo
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs