PR target/48609: Improve RTL expansion of complex value return.
Optimizes returning complex values by directly composing parts in registers, avoiding memory spills.
This patch optimizes the return of complex values, specifically for architectures like x86 that use integer registers for this purpose according to their ABI. Previously, GCC would inefficiently spill the complex value to memory and then reload it. The change improves RTL expansion to directly compose the real and imaginary parts using shifts and additions, generating more efficient code.
In Details
In gcc/expr.cc, the emit_group_load_1 function has been modified to improve the return of complex values that fit within an integer register's size, conforming to certain ABIs (e.g., x86). Previously, this scenario led to unnecessary memory spills and reloads during RTL expansion. The updated logic now directly constructs the complex value by combining the low and high parts (real and imaginary components, respecting endianness) using shifts and additions, thereby eliminating the intermediate memory operations and generating more compact and performant code.
- RTL expansion
- The process in GCC where intermediate representations (like GENERIC or GIMPLE) are converted into Register Transfer Language (RTL), a lower-level representation closer to machine code. This is where many target-independent optimizations occur.
- complex value
- A data type representing a number with a real and an imaginary part, often denoted as
a + bi. - x86 ABI
- The Application Binary Interface for the x86 architecture, which defines conventions for function calls, parameter passing, register usage, and data layout.
- memory spill
- An operation during code generation where a value held in a CPU register must be temporarily stored in main memory because all available registers are in use.
- PR48609
- A Problem Report (PR) identifier in the GCC bug tracking system, indicating a specific issue that has been reported and is being addressed.