out-of-SSA: Use all partition names to find decl
Fixes out-of-SSA to correctly identify the declaration for splitting partitions, preventing miscompilations.
This commit modifies the out-of-SSA pass to correctly identify the declaration associated with a partition, resolving a miscompilation issue. The split_overlapping_partition_decls function previously relied on a partition’s representative name to determine its associated variable. If this representative had no base variable (e.g., an anonymous temporary), the function might select the wrong variable, leading to incorrect partitioning and the fusion of memory accesses. The fix ensures that all names within a partition are considered to find the correct declaration, preventing situations where distinct stack slots share a MEM_EXPR and cause fused stores.
In Details
Refactors split_overlapping_partition_decls in cfgex by changing how the target declaration for partitioning is identified. Previously, it derived the VAR_DECL from the partition's representative, which could be null for temporaries. This commit modifies it to iterate over all names within a partition to find a valid VAR_DECL, PARM_DECL, or RESULT_DECL. This is crucial for correctly handling cases like loop-carried temporaries where distinct partitions might erroneously share a MEM_EXPR due to an incomplete view of the partition's variable associations, as seen in PR126405.
- out-of-SSA
- A GCC pass that converts SSA (Static Single Assignment) form back into a more traditional three-address representation, necessary for certain optimizations and code generation phases.
- partition
- In the context of out-of-SSA, a partition represents a set of memory locations that are treated as a single unit for analysis and transformation.
- MEM_EXPR
- A GCC internal representation for memory references, typically involving a base address and an offset.
- VAR_DECL
- A GCC internal representation node for a variable declaration.
- PARM_DECL
- A GCC internal representation node for a function parameter declaration.
- RESULT_DECL
- A GCC internal representation node for a function result (return value) declaration.
- SSA
- Static Single Assignment form, an intermediate representation where every variable is assigned a value exactly once.