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.
While at that, rework dump_cselib_table to not crash when
cselib_preserved_hash_table is not allocated, and to remove the
extraneous indirection from dump_cselib_val that made it inconvenient
to call from a debugger.
Regstrapped on x86_64-linux-gnu. Ok to install?
for gcc/ChangeLog
* cselib.cc (cselib_invalidate_mem): Lookup the address as
part of canonicalizing it.
(dump_cselib_val): Split out of and rename to...
(dump_cselib_val_ptr): ... this.
(dump_cselib_table): Adjust.
---
gcc/cselib.cc | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/gcc/cselib.cc b/gcc/cselib.cc
index 7f1991b09c3c8..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;
@@ -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);
--
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!