tree-optimization: Fold length-one memset through arbitrary pointers.
Optimizes length-one memset calls through arbitrary pointers into scalar stores.
The compiler can now optimize calls to memset with a length of one, even when the destination is an arbitrary pointer (e.g., a function parameter). Previously, such calls were not optimized into scalar stores unless the destination was a known ADDR_EXPR. This change allows folding these into a single byte store, preserving volatile qualification and supporting both constant and non-constant fill values, thereby improving performance and code generation efficiency.
In Details
The gimple_fold_builtin_memset function now includes a dedicated folding path for length-one memset calls through arbitrary pointer destinations. It constructs a MEM_REF at offset zero, preserving the volatile qualifier and the call's result if used. This fold is deferred until after object-size analysis to keep the original memset available for diagnostics. This complements the existing folding for ADDR_EXPR destinations.
- tree-optimization
- A phase in the GCC compilation pipeline where the code is represented in an intermediate form called 'tree' and optimized for efficiency.
- memset
- A standard C library function used to fill a block of memory with a specified byte value.
- ADDR_EXPR
- An expression in GCC's intermediate representation that represents the address of an object.
- Scalar store
- An operation that writes a single value (like a byte, word, or dword) to a memory location.
- GIMPLE
- GCC's low-level Intermediate Representation (IR) used for performing optimizations. It's a three-address-like code format.