phiopt: Fix up factoring out loads for REF_REVERSE_STORAGE_ORDER [PR126729]
Fixes an oversight in conditional load factoring that caused storage order information to be lost or mismatched.
This commit addresses an issue in the phiopt optimization pass where the factor_out_conditional_load function did not correctly handle the REF_REVERSE_STORAGE_ORDER attribute. This oversight could lead to the loss of this attribute or incorrect handling when conditional loads were factored out. The fix ensures that this storage order information is preserved and correctly matched, preventing potential code generation errors.
In Details
Corrects factor_out_conditional_load in tree-ssa-phiopt.cc to properly account for REF_REVERSE_STORAGE_ORDER when factoring out conditional loads. The previous implementation overlooked this flag, leading to its loss or misinterpretation, which could affect the correctness of memory access patterns, particularly those involving endianness-sensitive operations. A new test case (gcc.dg/sso/factor_load-1.c) is added to verify the fix.
- phiopt
- A GCC optimization pass that operates on Static Single Assignment (SSA) form, likely involving the optimization of PHI nodes or related structures to improve code efficiency.
- factor_out_conditional_load
- An optimization technique where a conditional load operation is restructured to be performed outside the conditional branch, potentially improving performance by reducing control flow complexity or enabling further optimizations.
- REF_REVERSE_STORAGE_ORDER
- A flag or attribute associated with memory references indicating that the storage order of bytes within a multi-byte value is reversed. This is typically relevant for systems with different endianness.
- SSA
- Static Single Assignment form. An intermediate representation where each variable is assigned a value exactly once, simplifying many optimization analyses.