https://gcc.gnu.org/g:734daed657c4a193bc42b9ac62557e841c1d5f9a
commit 734daed657c4a193bc42b9ac62557e841c1d5f9a Author: Alexandre Oliva <[email protected]> Date: Sat Dec 13 04:12:28 2025 -0300 cselib: lookup mem addr during invalidation When processing stores for e.g. parameters passed on the stack, as in gcc.dg/pr117239.c, each store invalidates other stores pertaining to the same argument, because we can tell they refer to the same object, but not that the offsets don't overlap. The reason for that is that the mem_rtx being invalidated is canonicalized to an SP offset, while those in the cselib table have canonical values as addresses, and alias.cc can't resolve SP to values to compare the offsets. With this change, pr117239.c doesn't require -fschedule-insns to fail, with the PR117239 fixes reverted. for gcc/ChangeLog * cselib.cc (cselib_invalidate_mem): Lookup the address as part of canonicalizing it. Diff: --- gcc/cselib.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gcc/cselib.cc b/gcc/cselib.cc index 930357409bc5..c6628abf2a98 100644 --- a/gcc/cselib.cc +++ b/gcc/cselib.cc @@ -2623,6 +2623,14 @@ cselib_invalidate_mem (rtx mem_rtx) rtx mem_addr; mem_addr = canon_rtx (get_addr (XEXP (mem_rtx, 0))); + /* Resolve MEM_ADDR to a VALUE_RTX, so that canon_anti_dependence can compare + offsets from the same base, even for SP-based addresses. */ + if ((v = cselib_lookup (mem_addr, GET_MODE (mem_addr), + 0, GET_MODE (mem_rtx)))) + { + mem_addr = v->val_rtx; + mem_rtx = replace_equiv_address_nv (mem_rtx, mem_addr); + } mem_rtx = canon_rtx (mem_rtx); vp = &first_containing_mem;
