GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
tree-optimization Performance Win

Tree-optimization Lowers mempcpy to memcpy When Result is Unused.

The compiler now optimizes `mempcpy` calls to `memcpy` when the return value is ignored, potentially improving performance.

The GIMPLE folding pass now transforms __builtin_mempcpy into __builtin_memcpy when the return value of mempcpy is unused. Since many targets have highly optimized memcpy implementations, this transformation can improve code generation. New tests were added to ensure both the unfolded and folded mempcpy are properly handled.

In Details

This change adds a case to gimple_fold_builtin in gimple-fold.cc to handle BUILT_IN_MEMPCPY. When the result of __builtin_mempcpy is unused, it's replaced with __builtin_memcpy. gimple-fold.cc is part of the tree-ssa optimisations. The optimisation relies on the target providing an efficient implementation of memcpy.

For Context

mempcpy and memcpy are standard C library functions that copy memory. mempcpy returns a pointer to the end of the copied memory block, while memcpy returns a pointer to the beginning. If the return value is not needed, using memcpy can be more efficient because it avoids the overhead of calculating and returning the end pointer. This commit optimizes code by replacing mempcpy with memcpy when the return value is ignored, which can lead to better performance, as modern architectures often have optimized memcpy implementations.

Filed Under: tree-optimizationmemcpymempcpygimpleperformance