On Wed, Aug 2, 2023 at 11:10 PM Jeff Law via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > > > On 8/2/23 17:52, Andrew Pinski via Gcc-patches wrote: > > This moves a few simple patterns that are done in value replacement > > in phiopt over to match.pd. Just the simple ones which might show up > > in other code. > > > > This allows some optimizations to happen even without depending > > on sinking from happening and in some cases where phiopt is not > > invoked (cond-1.c is an example there). > > > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. > > > > gcc/ChangeLog: > > > > * match.pd (`a == 0 ? b : b + a`, > > `a == 0 ? b : b - a`): New patterns. > > > > gcc/testsuite/ChangeLog: > > > > * gcc.dg/tree-ssa/cond-1.c: New test. > > * gcc.dg/tree-ssa/phi-opt-33.c: New test. > > * gcc.dg/tree-ssa/phi-opt-34.c: New test. > Are you going to remove the old implementation from phiopt?
That is the plan but I doubt it will be completed for GCC 14 because it will require a lot of changes to the match-and-simplify part of phi-opt to support all of what value replacement does and I have not thought through what is fully required to do that yet. I know having multiple things in the partial state is not a good idea but in this case other passes benefit from this change as shown by the cond-1.c testcase, loop if-conv also uses match-and-simplify when creating its conditional expressions (since r13-263-g9801ca737b1dcb; well it uses generic fold since r0-118636-gf35613b29cb159) so that pass will benefit in this case, removing the conditional even. I have a few other patches to remove many parts of minmax of phiopt that I will finish up for GCC 14 though so at least there will be more code removed from phi-opt for GCC 14. Thanks, Andrew PS here is a testcase where the vectorized code is improved due to this patch: ``` int f(unsigned *a, unsigned *b, unsigned *c, unsigned *d) { for(int i = 0;i < 128; i++) { unsigned aa = a[i]; unsigned bb = b[i]; unsigned cc = c[i]; unsigned r; unsigned r1; if (aa == 0) { r = bb; r1 = 1; } else { r = bb+aa; r1 = 0; } c[i] = r; d[i] = r1; } } ``` > > Jeff