GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
tree-optimization

Preserve Scalar Replacement of Aggregates (SROA) during loop store motion

Ensures Scalar Replacement of Aggregates is maintained when moving stores within loops.

This commit enhances the loop store motion optimization in GCC by preserving Scalar Replacement of Aggregates (SROA). Previously, when performing loop store motion, the optimization could inadvertently break the SROA transformation. This patch modifies the gather_mem_refs_stmt function to correctly handle SROA when building canonicalized references, ensuring that scalar replacements are not lost during loop optimizations and potentially improving the effectiveness of SROA.

In Details

This patch fixes PR tree-optimization/128461 by ensuring that the Scalar Replacement of Aggregates (SROA) invariant is maintained during loop store motion. Specifically, the gather_mem_refs_stmt function in tree-ssa-loop-im.cc is modified to preserve SROA when building a canonicalized reference. This prevents the loop store motion pass from invalidating scalar replacements that were previously applied, ensuring that SSA-based optimizations continue to function correctly across loop transformations.

For Context
Scalar Replacement of Aggregates (SROA)
An optimization pass in GCC that replaces accesses to fields of aggregate types (like structs) with accesses to scalar variables. This can enable further scalar optimizations.
loop store motion
An optimization technique that moves store operations (writes to memory) within a loop to an earlier, invariant location, potentially reducing redundant stores.
tree-ssa-loop-im.cc
A GCC source file that implements loop invariant code motion and other loop optimizations within the SSA (Static Single Assignment) representation.
canonicalized reference
A standardized or normalized representation of a memory access, used within the compiler to simplify alias analysis and other memory-related optimizations.
SSA (Static Single Assignment)
A property of intermediate representations where each variable is assigned a value exactly once. This simplifies many compiler analyses and optimizations.
Filed Under: gccoptimizationloop optimizationSROA