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

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

https://gcc.gnu.org/g:cd65161b78ececc629183d210b56142c6653c092

commit r17-3003-gcd65161b78ececc629183d210b56142c6653c092
Author: Andrea Pinski <[email protected]>
Date:   Sun Aug 2 14:32:51 2026 -0700

    phiopt/cselim: Allow a load between the load and the store before the
condition [PR126580]

    In cond_store_replacement_limited, we currently reject any load after the
    store; this was done as a simple way out but we can do better and just not
    remove the store.

    That is we have:
    ```
    MEM0 = val;
    _1 = MEM1;
    if (_8)
      MEM0 = val2;
    ```
    cselim (non limited) and ifcvt would turn this info:
    ```
    MEM0 = val;
    _1 = MEM1;
    _2 = _8 ? val : val2;
    MEM0 = _2;
    ```
    So it would be a good idea to do it in limited too and not depend on the
    non-trapping part of cselim. So in the case of the testcases we can remove
    the conditional fully and just have 2 stores.  DSE will remove the
    first store if the load does not alias too.

    Bootstrapped and tested on x86_64-linux-gnu.

            PR tree-optimization/126580

    gcc/ChangeLog:

            * tree-ssa-phiopt.cc (cond_store_replacement_limited): Allow
            a load before the store; not removing the store.

    gcc/testsuite/ChangeLog:

            * gcc.dg/tree-ssa/pr126580-1.c: New test.
            * gcc.dg/tree-ssa/pr126580-2.c: New test.

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

Reply via email to