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

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jeff Law <[email protected]>:

https://gcc.gnu.org/g:7565093dd76ecbbb9b5e664db38f01680b72ac1a

commit r17-6555-g7565093dd76ecbbb9b5e664db38f01680b72ac1a
Author: Jeff Law <[email protected]>
Date:   Sat Nov 21 07:09:43 2026 -0700

    [PR rtl-optimization/128910] Fix incorrect equivalence between SUBREGS with
different promotion state

    Wow, this one was fun.  I fully expected this to be a RISC-V target
problem,
    but in the end it's generic and very old.  It's just been latent for
decades!

    The core problem is exp_equiv_p (used by CSE and GCSE) returns true for
SUBREG
    expressions with different promotion states.

    A RISC-V backend change in this cycle stopped pretending we always had zero
    extension insns during expansion.  Instead the port now emits the shift
pair
    when the appropriate extensions are not available.

    That caused the testcase from the PR to use expanded shift pairs for zero
    extension.  We had an underlying SUBREG object in those newly exposed
shifts.
    In one context that SUBREG object had promoted state and in another context
it
    did not.  GCSE (incorrectly) determined the SUBREGs were equivalent and
created
    the dominating definition allowing the two instances to be removed.  The
    representative instance GCSE inserted had the promotion state markers, but
was
    inserted into a point where the promoted state did not hold.  combine then
came
    along saw we had a shift pair implementing zero extension on a value that
was
    marked as already extended, so combine removed the zero extension.  Boom,
    incorrect code.

    Bootstrapped and regression tested on x86 and aarch64.  Also tested on
    riscv32-elf and riscv64-elf.  Pushing to the trunk.

    Assisted-By: Claude for dumpfile analysis

            PR rtl-optimization/128910
    gcc/
            * cse.cc (exp_equiv_p): Return false for SUBREGs that have
different
            promotion states.

    gcc/testsuite
            * gcc.dg/torture/pr128910.c: New test.

Reply via email to