IPA predicates avoid matching bit-field conditions against byte offsets.
Fixes IPA predicate matching to correctly handle bit-fields, preventing incorrect optimization and code generation issues.
This commit addresses an issue where IPA predicates incorrectly matched bit-field conditions against byte offsets. The predicate conditions were stored as bit offsets, while jump function values used byte offsets. The existing logic divided bit offsets by 8, losing sub-byte position information and leading to incorrect matching. This caused a test case to misinterpret a bit-field, resulting in unreachable code elimination and a fall-through into _start. The fix ensures that lookups are skipped for non-byte-aligned conditions, resolving PR 126153.
In Details
The ipa-fnsummary.cc function evaluate_conditions_for_known_args previously mishandled IPA predicates for bit-fields. It derived bit offsets from get_ref_base_and_extent_hwi but then used them with ipa_argagg_value::unit_offset (byte-aligned) by dividing by BITS_PER_UNIT. This silently dropped sub-byte precision. The fix modifies the function to skip aggregate value lookups when a condition's offset is not byte-aligned, preventing the incorrect reinterpretation of bit-fields and resolving PR 126153. A new test gcc.dg/torture/pr126153.c is added.
- IPA predicates
- In GCC's Interprocedural Analysis (IPA), these are conditions or properties that are evaluated across function calls to guide optimizations. They help the compiler understand program behavior beyond a single function.
- bit offset
- A position within a data structure measured in bits, often used when dealing with bit-fields or packed data.
- byte offset
- A position within a data structure measured in bytes. This is the standard way memory addresses are handled.
- jump functions
- A mechanism used in some optimization passes (like IPA) to represent conditions that determine control flow between different parts of the program.
- Interprocedural Analysis (IPA)
- An optimization phase in GCC that analyzes information across multiple functions in a program, rather than just within a single function, to enable more powerful optimizations.