On Dec 5, 2025, Eric Botcazou <[email protected]> wrote:
>> * cselib.cc (cselib_invalidate_mem): Lookup the address as
>> part of canonicalizing it.
> The cselib_invalidate_mem change looks a bit risky at this stage
... and here's that part split out for the next stage1. Ok then?
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.
---
gcc/cselib.cc | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/gcc/cselib.cc b/gcc/cselib.cc
index 930357409bc54..c6628abf2a989 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;
--
Alexandre Oliva, happy hacker https://blog.lx.oliva.nom.br/
Free Software Activist FSFLA co-founder GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity.
Excluding neuro-others for not behaving ""normal"" is *not* inclusive!