Code generation for C compound literals: why so odd?
GCC generates unusual x86 code for C compound literals, possibly due to an optimization quirk.
The author questions GCC’s -O3 code generation for C compound literals, specifically noting an inefficient sequence involving stack-based initialization and register manipulation. Alternative function implementations produce more straightforward assembly. The issue appears to be specific to compound literals, suggesting a potential optimization or codegen bug.
In Details
This discussion concerns GCC's x86-64 code generation for C compound literals, specifically when returning struct P. The generated assembly exhibits unusual patterns for initializing the r and e members, involving stack preparation and bitwise operations that seem inefficient compared to direct struct initialization or member assignment. The author suspects an optimization pass or instruction selection issue.
- compound literal
- A C language construct that creates an unnamed object with automatic storage duration, initialized with a specified value. It's often used for initializing structs or arrays without declaring a named variable.
- x86-64
- A 64-bit common instruction set architecture, widely used in desktop and server processors. GCC generates machine code for this architecture.
- -O3
- A GCC compiler optimization flag that enables a high level of aggressive optimizations, aiming for maximum performance at the potential cost of increased compile time and code size.
- ABI
- Application Binary Interface. Defines how low-level binary code is structured, including function calling conventions, data type sizes, and register usage, ensuring interoperability between compiled code.