Pass access direction to get_memory_rtx
Improves memory operand handling in built-ins by specifying load/store direction, preserving non-trapping info.
The get_memory_rtx function in builtins.cc previously created memory operands without distinguishing between loads and stores. This led to the loss of MEM_NOTRAP information for loads, as the default assumed store semantics. This commit adds a STORE_P argument to get_memory_rtx, allowing callers to explicitly mark destinations as stores and sources as loads. This preserves precise non-trapping information for loads used in string operations and comparisons.
In Details
The get_memory_rtx function in builtins.cc is used to create memory RTX objects for string operations. It previously lacked a way to differentiate between load and store accesses. This commit adds a STORE_P argument, which is then passed to set_mem_attributes. Callers like expand_builtin_memory_copy_args and expand_builtin_memcmp now explicitly mark memory operands as loads or stores, ensuring MEM_NOTRAP is correctly preserved for loads.
- MEM_NOTRAP
- A flag indicating that a memory access is guaranteed not to trap (e.g., cause a segmentation fault or other exception). This allows the compiler to perform more aggressive optimizations, such as reordering or eliminating the access.
- RTX
- Register Transfer Language. An intermediate representation used internally by GCC to represent operations on registers and memory before final machine code generation.
- Built-in Functions
- Functions provided by the compiler that often map directly to specific machine instructions or provide optimized implementations of standard library functions (e.g.,
memcpy,memset).