Extend IPA load analysis to walk PHIs for unknown offsets
GCC's IPA can now trace values through PHI nodes when analyzing loads with unknown offsets.
This commit enhances GCC’s interprocedural analysis by enabling the ipa_load_from_parm_agg_unknown_offset function to traverse chained PHI nodes. This allows for correct analysis of loops that modify strings or other data structures through pointers where the exact offset is not known at compile time. New test cases are included to verify this functionality.
In Details
Commit 173072492587491dea9e2b0a9d02da9e4dff2c65 adds PHI node walking to ipa_load_from_parm_agg_unknown_offset in gcc/ipa-prop.cc. This is crucial for correctly analyzing aggregate loads where the offset is unknown and the load operates on values produced by a sequence of PHI nodes, common in loops and within inlined functions that manipulate data passed by reference. This complements 7ce404d9c953b0a1b51e1501ca7332b037170481 and 9961d5f117c4afe323dc1be8b0df9031b28265e4 by providing a more robust analysis of unknown-offset accesses, particularly relevant for PR ipa/127171.
- PHI node
- A special node in Static Single Assignment (SSA) form, used to represent the assignment of a value when control flow paths merge. A PHI node selects one of several input values based on which predecessor block was executed.
- unknown_offset
- A state in GCC's analysis indicating that the precise memory offset being accessed within an aggregate data structure cannot be determined at compile time. This often occurs with pointer arithmetic or indirect accesses.
- Interprocedural Analysis (IPA)
- A compile-time analysis that examines relationships and dependencies between different functions within a program, rather than just a single function in isolation. It's used to enable optimizations that require knowledge beyond a single function's scope.
- aggregate
- A data structure that groups together multiple values, such as a struct or an array.