GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
x86

x86: Check reaching definitions for stack access [PR128527]

Improves x86 stack access analysis to prevent incorrect stack realignment triggers.

This commit refines how the x86 backend determines if a register is being used as a stack address, specifically addressing issues with stack realignment in leaf functions. Previously, the analysis could be misled by register redefinitions between a stack definition and its use. The update enhances the analysis to correctly check reaching definitions using UD (use-definition) chains. This ensures that stack realignment is only triggered by genuine stack accesses, not by registers that happen to be redefined or loaded from memory, thus fixing assertion failures and incorrect prologue code.

In Details

The ix86_access_stack_p function incorrectly identified registers as stack addresses if a stack definition dominated their use, even with intervening redefinitions. This was exacerbated by requires_stack_frame_p returning true for callee-saved registers. The fix involves a more precise UD chain analysis to examine reaching definitions. It now checks non-jump instructions that use the stack or frame pointer outside of memory and recursively analyzes definitions of registers used in those reaching definitions. This prevents spurious stack address identification, particularly in leaf functio…

For Context
reaching definitions
In compiler analysis, a reaching definition of a variable at a particular point in the code is a definition of that variable that might be active (i.e., could reach that point without being redefined).
UD chains
Use-Definition chains. These trace the path from a variable's use back to its definition, essential for dataflow analysis.
stack realignment
A feature that adjusts the stack pointer alignment to match the requirements of specific data types or instructions, typically for performance or correctness.
leaf function
A function that does not call any other functions.
dominance
In control flow graphs, a node A dominates node B if every path from the entry node to B must go through A.
callee-saved register
Registers that a function must preserve across its execution, meaning if the function uses them, it must save their original values and restore them before returning.
Filed Under: x86stackreaching definitionscompiler analysisoptimization