Modern C/C compilers like clang, ICC, MSVC, and gcc avoid using push/pop instructions directly. Instead, they optimize code by using more efficient sub/mov or lea instructions. Push/pop is still utilized for specific scenarios like saving/restoring callee-saved registers and passing stack arguments.
Compilers do not typically support building stack frames gradually using push/pop instructions. This is because it conflicts with unwinding mechanisms for error handling and debugging, and may result in larger unwind info sections. Additionally, mixing push and [rsp] addressing modes can introduce inefficiencies on Intel CPUs due to stack-sync uops.
While push/pop instructions may seem beneficial for creating local variables, compilers currently prioritize more efficient and reliable techniques like sub/mov or lea. There are certain scenarios where push/pop is still used, but it is not typically employed for gradual stack frame building.
The above is the detailed content of Why Don't Modern Compilers Use Push/Pop for Gradual Stack Frame Building?. For more information, please follow other related articles on the PHP Chinese website!