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

Andrea Pinski <[email protected]> Wed, 5 Aug 2026 22:04:00 -0700
Newsgroups gmane.comp.gcc.patches
Message-ID <CALvbMcB9qb+TfCRsFKXAyAYPeTQrJnom1hTcA2k9Hg-+hHaYMQ@mail.gmail.com>
On Wed, Aug 5, 2026 at 7:20 PM Jeffrey Law <[email protected]> wrote:
>
>
>
> On 8/2/2026 7:25 PM, Andrea Pinski wrote:
> > 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.
> OK.


Thanks now pushed as r17-3003-gcd65161b78ececc629183d210b56142c6653c092.

> jeff
>