https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121355
--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrew Pinski <[email protected]>: https://gcc.gnu.org/g:9f94029829daf3b83bb95226dcfe003c5ddcade2 commit r16-3534-g9f94029829daf3b83bb95226dcfe003c5ddcade2 Author: Andrew Pinski <[email protected]> Date: Sat Aug 30 15:16:20 2025 -0700 fold: Unwrap MEM_REF after get_inner_reference in split_address_to_core_and_offset [PR121355] Inside split_address_to_core_and_offset, this calls get_inner_reference. Take: ``` _6 = t_3(D) + 12; _8 = &MEM[(struct s1 *)t_3(D) + 4B].t; _1 = _6 - _8; ``` On the assignement of _8, get_inner_reference will return `MEM[(struct s1 *)t_3(D) + 4B]` and an offset but that does not match up with `t_3(D)` which is how split_address_to_core_and_offset handles pointer plus. So this patch adds the unwrapping of the MEM_REF after the call to get_inner_reference and have it act like a pointer plus. Changes since v1: * v2: Remove check on operand 1 for poly_int_tree_p, it is always. Add before the check to see if it fits in shwi instead of after. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/121355 gcc/ChangeLog: * fold-const.cc (split_address_to_core_and_offset): Handle an MEM_REF after the call to get_inner_reference. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/ptrdiff-1.c: New test. Signed-off-by: Andrew Pinski <[email protected]>
