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

--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <[email protected]>:

https://gcc.gnu.org/g:4933ad22c7293472c0bd283dce5680e6415b3819

commit r16-8087-g4933ad22c7293472c0bd283dce5680e6415b3819
Author: Andrew Pinski <[email protected]>
Date:   Thu Mar 12 15:35:30 2026 -0700

    cprop_hardreg: purge dead edges and cleanupcfg if something changes
[PR124454]

    cprop_hardreg changes:
    ```
    (insn 69 62 183 6 (set (reg:SI 1 x1 [orig:107 _12 ] [107])
            (zero_extend:SI (mem:QI (reg/f:DI 1 x1 [150]) [0 MEM[(char *)_4]+0
S1 A64]))) "/app/example.cpp":8:7 discrim 1 149 {*zero_extendqisi2_aarch64}
         (expr_list:REG_EH_REGION (const_int 2 [0x2])
            (nil)))
    ```

    into:
    ```
    (insn 69 62 183 6 (set (reg:SI 1 x1 [orig:107 _12 ] [107])
            (zero_extend:SI (mem:QI (plus:DI (reg/f:DI 31 sp)
                        (const_int 56 [0x38])) [0 MEM[(char *)_4]+0 S1 A64])))
"/app/example.cpp":8:7 discrim 1 149 {*zero_extendqisi2_aarch64}
         (expr_list:REG_EH_REGION (const_int 2 [0x2])
            (nil)))
    ```

    But that new instruction no longer traps as it is load from the stack. So
later on
    purge_dead_edges removes the REG_EH_REGION note and the edge to the eh
landing pad
    but this is during find_many_sub_basic_blocks in split3 and nothing then
removes the
    unreachable basic blocks.

    To fix this, instead of depending on a later pass to clean this up,
cprop_hardreg
    should call purge_all_dead_edges if non-call exceptions were enabled and
then
    also call cleanup_cfg (to remove the unreachable blocks).

    Bootstrapped and tested on x86_64-linux-gnu and lightly tested for
aarch64-linux-gnu.

            PR rtl-optimization/124454

    gcc/ChangeLog:

            * regcprop.cc (pass_cprop_hardreg::execute): If something
            changed and non-call exceptions is on, call purge_all_dead_edges
            and cleanup_cfg.

    gcc/testsuite/ChangeLog:

            * gcc.dg/pr124454-1.c: New test.

    Signed-off-by: Andrew Pinski <[email protected]>

Reply via email to