i386: Improve vzeroupper placement with IPA-RA
Optimizes AVX/SSE transition penalties by improving vzeroupper placement when registers are not live across calls.
This change refines the placement of the vzeroupper instruction on the i386 architecture to reduce performance penalties when transitioning between AVX and SSE code. Previously, conservative restrictions unnecessarily inserted vzeroupper even when no SSE registers were live across a function call. The update uses inter-procedural register allocation (IPA-RA) information to determine if vzeroupper is truly needed, avoiding the penalty for integer-only callees and calls where no preserved SSE register remains live.
In Details
The ix86_avx_u128_mode_needed function in i386.cc is updated to pass LIVE register information. This allows the function to more accurately determine if AVX_U128_CLEAN is required by checking if any preserved SSE registers remain live across a call. This avoids unnecessary vzeroupper instructions, especially for calls to callees that do not clobber SSE registers, thus reducing AVX/SSE transition penalties. This impacts IPA-RA's ability to optimize code across function calls.
- vzeroupper
- An x86 instruction that zeros the upper 128 bits of an AVX register. It's used to ensure correct behavior when transitioning between SSE and AVX instruction sets, as AVX registers can hold 256-bit values whereas SSE registers hold 128-bit values.
- IPA-RA
- Inter-Procedural Analysis and Register Allocation. This phase of the compiler performs analysis and register allocation decisions considering the entire program, not just individual functions. It enables optimizations that span across function calls.
- SSE
- Streaming SIMD Extensions. A set of SIMD (Single Instruction, Multiple Data) instructions for the x86 architecture, primarily used for floating-point and integer multimedia processing.
- AVX
- Advanced Vector Extensions. An extension to x86 instruction set architecture for microprocessors that increases the processing widths beyond the original 128-bit SSE registers to 256-bit and later 512-bit.
- callee-preserved registers
- CPU registers that a called function (callee) must preserve its original value before returning to the caller. The caller can assume these registers will retain their values after a function call.