Preserve alignment of access during address forwarding.
GCC now preserves the alignment of memory accesses when forwarding addresses during tree optimization.
GCC’s tree-ssa-forwprop pass now preserves the alignment of memory accesses when forwarding addresses. This prevents the optimizer from picking up the alignment of parts of the forwarded address instead of the original access. A new test case, gcc.dg/pr125206.c, validates this fix.
In Details
The tree-ssa-forwprop pass in GCC optimizes expressions by propagating address expressions. This commit fixes an issue where the alignment of the original memory access was not preserved during address forwarding. The fix ensures that the correct alignment is maintained, preventing potential misalignments. The relevant code changes are in tree-ssa-forwprop.cc within the forward_propagate_addr_expr_1 function.
For Context
GCC's tree optimization phase aims to improve the efficiency of generated code by transforming the program's abstract syntax tree (AST). Address forwarding is a technique where the compiler replaces a memory access with a direct pointer to the data. Memory alignment is crucial for performance; misaligned accesses can lead to significant slowdowns, especially on architectures that penalize them. This change ensures that the compiler maintains correct memory alignment during address forwarding, leading to more efficient code execution.