https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116627

--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:73726725ae03995ef8b61622c954f7ca70416f79

commit r15-3950-g73726725ae03995ef8b61622c954f7ca70416f79
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Sun Sep 29 21:52:32 2024 +0200

    cselib: Discard useless locs of preserved VALUEs [PR116627]

    remove_useless_values iteratively discards useless locs (locs of
    cselib_val which refer to non-preserved VALUEs with no locations),
    which in turn can make further values useless until no further VALUEs
    are made useless and then discards the useless VALUEs.

    Preserved VALUEs (something done during var-tracking only I think)
    live in a different hash table, cselib_preserved_hash_table rather
    than cselib_hash_table.  cselib_find_slot first looks up slot in
    cselib_preserved_hash_table and only if not found looks it up in
    cselib_hash_table (and INSERTs only into the latter), whereas preservation
    of a VALUE results in move of a cselib_val from the latter to the former
    hash table.

    The testcase in the PR (apparently too fragile, it only reproduces on 14
    branch with various flags on a single arch, not on trunk) ICEs, because
    we have a preserved VALUE (QImode with (const_int 0) as one of the locs).
    In a different BB SImode r2 is looked up, a non-preserved VALUE is created
    for it, and the r13-2916 added code attempts to lookup also SUBREGs of that
    in narrower modes, among those QImode, so adds to that SImode r2
    non-preserve VALUE a new loc of (subreg:QI (value:SI) 0).  That SImode
    value is considered useless, so remove_useless_value discards it, but
    nothing discarded it from the preserved VALUE's loc_list, so when looking
    something up in the hash table we ICE trying to derevence CSELIB_VAL
    of the discarded VALUE.

    I think we need to discuard useless locs even from the preserved VALUEs.
    That IMHO shouldn't create any further useless VALUEs, the preserved
    VALUEs are never useless, so we don't need to iterate with it, can do it
    just once, but IMHO it needs to be done because actually
    discard_useless_values.

    The following patch does that.

    2024-09-29  Jakub Jelinek  <ja...@redhat.com>

            PR target/116627
            * cselib.cc (remove_useless_values): Discard useless locs
            even from preserved cselib_vals in cselib_preserved_hash_table
            hash table.

Reply via email to