Predcom chains ensure TBAA-equivalence for type conversions
A fix ensures that predcom chains correctly handle type conversions, preventing incorrect alias analysis and data races in optimized code.
This commit addresses a bug in GCC’s predcom optimization pass where references with types that pass useless_type_conversion_p were incorrectly placed in the same alias analysis chain. This occurred even if the types had different alias sets (e.g., long and long long on LP64 systems). The fix enforces that references within a chain must also be equivalent according to TBAA (Tree Alias Analysis), preventing scenarios where loads of one type might alias with stores of another, leading to incorrect values being read before calls.
In Details
The pcom_worker::determine_offset function in tree-predcom.cc previously created alias chains based solely on a type conversion check (useless_type_conversion_p). This commit adds a check for refs_same_for_tbaa_p in both directions. This ensures that references within the same chain also exhibit equivalent TBAA behavior, preventing issues like those in PR128324 where a long store and a long long load formed a chain, causing a preheader load of the long long location to be incorrectly treated as a long access due to shared chain root alias information.
- TBAA
- Tree Alias Analysis. A technique used by GCC to determine memory aliasing, i.e., whether different memory accesses might refer to the same location. It's crucial for optimizing memory operations.
- predcom
- Abbreviation for 'pre-computation' or 'predicate-based commoning', a GCC optimization pass that identifies and factors out common computations, often involving loop-invariant code.
- alias sets
- In alias analysis, a classification of memory locations that distinguishes between accesses that are guaranteed not to alias and those that might alias. Different data types or memory regions can belong to different alias sets.
- LP64
- A data model where
longand pointers are 64 bits wide, whileintis 32 bits. Common on 64-bit Unix-like systems. - IPA
- Interprocedural Analysis. Analysis that considers information from multiple functions or the entire program, rather than just a single function.