ipa-icf: Compare fields, not just offsets, for ADDR_EXPR under OEP_ADDRESS_OF
Fixes interprocedural constant propagation to correctly identify identical fields in structs, preventing incorrect code unification.
The interprocedural constant propagation (IPA-ICF) pass incorrectly unified structs with different field declarations but identical offsets. This occurred when comparing ADDR_EXPRs under OEP_ADDRESS_OF, where it accepted different FIELD_DECLs with the same offset. A new flag, OEP_ADDRESS_OF_SAME_FIELD, is introduced to ensure that only identical fields are considered equivalent, thus preventing errors like the one in PR119006 where a strlen calculation failed after struct unification.
In Details
ipa-icf-gimple.cc's func_checker::compare_operand previously used operand_equal_p with OEP_ADDRESS_OF, which allowed different FIELD_DECLs with the same DECL_FIELD_OFFSET and DECL_FIELD_BIT_OFFSET to be considered equal. This caused issues when subsequent passes, like get_range_strlen_tree, relied on TYPE_DOMAIN and TYPE_MAX_VALUE from the FIELD_DECL. The fix introduces OEP_ADDRESS_OF_SAME_FIELD, which fold-const.cc honors to restrict equality to identical fields, addressing PR119006.
- ipa-icf
- Interprocedural constant propagation via idempotent code folding. It identifies identical code sections across a program and unifies them to reduce code size and potentially improve optimization. Operates on GIMPLE intermediate representation.
- OEP_ADDRESS_OF
- Operand Evaluation Predicate flag used in GCC's tree matching. When set, it indicates that an expression should be evaluated as an address, affecting how operands are compared.
- FIELD_DECL
- A declaration of a member within a C/C++ struct or class. It holds information about the member's type, name, offset, and bit offset within the structure.
- GIMPLE
- GCC's three-address intermediate representation. It simplifies control flow and data flow analysis, serving as a common ground for various optimization passes.