https://gcc.gnu.org/g:3a86d687cdf7b2f1b74cf17128f00931a5aa0c59
commit 3a86d687cdf7b2f1b74cf17128f00931a5aa0c59 Author: Alexandre Oliva <[email protected]> Date: Thu Nov 27 22:28:53 2025 -0300 cselib: lookup mem addr during invalidation Diff: --- gcc/cselib.cc | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/gcc/cselib.cc b/gcc/cselib.cc index 7f1991b09c3c..eb63aa9439df 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))); + /* Attempt to 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; @@ -3459,12 +3467,11 @@ cselib_finish (void) next_uid = 0; } -/* Dump the cselib_val *X to FILE *OUT. */ +/* Dump the cselib_val V to FILE *OUT. */ int -dump_cselib_val (cselib_val **x, FILE *out) +dump_cselib_val (cselib_val *v, FILE *out) { - cselib_val *v = *x; bool need_lf = true; print_inline_rtx (out, v->val_rtx, 0); @@ -3533,15 +3540,27 @@ dump_cselib_val (cselib_val **x, FILE *out) return 1; } +/* Dump the cselib_val *X to FILE *OUT. */ + +static int +dump_cselib_val_ptr (cselib_val **x, FILE *out) +{ + cselib_val *v = *x; + return dump_cselib_val (v, out); +} + /* Dump to OUT everything in the CSELIB table. */ void dump_cselib_table (FILE *out) { fprintf (out, "cselib hash table:\n"); - cselib_hash_table->traverse <FILE *, dump_cselib_val> (out); - fprintf (out, "cselib preserved hash table:\n"); - cselib_preserved_hash_table->traverse <FILE *, dump_cselib_val> (out); + cselib_hash_table->traverse <FILE *, dump_cselib_val_ptr> (out); + if (cselib_preserved_hash_table) + { + fprintf (out, "cselib preserved hash table:\n"); + cselib_preserved_hash_table->traverse <FILE *, dump_cselib_val_ptr> (out); + } if (first_containing_mem != &dummy_val) { fputs ("first mem ", out);
