On Wed, Sep 25, 2024 at 1:38 AM Richard Biener
<richard.guent...@gmail.com> wrote:
>
> On Tue, Sep 24, 2024 at 6:14 PM Andrew Pinski <quic_apin...@quicinc.com> 
> wrote:
> >
> > Another small phiprop improvement, in some cases
> > we could have a vop defining statement be a phi which might
> > be the same bb as the load happens. This is ok since the phi
> > here is not a store so we can just accept it.
> >
> > Bootstrapped and tested on x86_64-linux-gnu.
>
> OK.

Just a quick note here, I have not applied this nor the other phiprop
patch because they can expose more wrong code due to a latent bug in
phiprop (see PR 116835). I am working on fixing that bug and after
that issue is resolved I will push both of these.

Thanks,
Andrew Pinski

>
> >         PR tree-optimization/116824
> >
> > gcc/ChangeLog:
> >
> >         * tree-ssa-phiprop.cc (propagate_with_phi): Don't
> >         reject if the bb of the def_stmt is the same as load
> >         and if the def_stmt was a phi.
> >
> > gcc/testsuite/ChangeLog:
> >
> >         * gcc.dg/tree-ssa/phiprop-3.c: New test.
> >
> > Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>
> > ---
> >  gcc/testsuite/gcc.dg/tree-ssa/phiprop-3.c | 30 +++++++++++++++++++++++
> >  gcc/tree-ssa-phiprop.cc                   |  3 ++-
> >  2 files changed, 32 insertions(+), 1 deletion(-)
> >  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phiprop-3.c
> >
> > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phiprop-3.c 
> > b/gcc/testsuite/gcc.dg/tree-ssa/phiprop-3.c
> > new file mode 100644
> > index 00000000000..a0d5891dc60
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.dg/tree-ssa/phiprop-3.c
> > @@ -0,0 +1,30 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-O1 -fdump-tree-phiprop1-details 
> > -fdump-tree-cselim-details -fdump-tree-phiopt2" } */
> > +
> > +/* PR tree-optimization/116824 */
> > +/* phiprop should be able to handle the case where the vops defining
> > +   statement was a phi in the same bb as the deference. */
> > +
> > +int g(int i, int *tt)
> > +{
> > +  const int t = 10;
> > +  const int *a;
> > +  {
> > +    if (t < i)
> > +    {
> > +      *tt = 1;
> > +      a = &t;
> > +    }
> > +    else
> > +    {
> > +      *tt = 1;
> > +      a = &i;
> > +    }
> > +  }
> > +  return *a;
> > +}
> > +
> > +/* { dg-final { scan-tree-dump-times "Inserting PHI for result of load" 1 
> > "phiprop1"} } */
> > +/* { dg-final { scan-tree-dump-times "factoring out stores" 1 "cselim"} } 
> > */
> > +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt2"} } */
> > +
> > diff --git a/gcc/tree-ssa-phiprop.cc b/gcc/tree-ssa-phiprop.cc
> > index f04990e8cb4..4d1df7d351e 100644
> > --- a/gcc/tree-ssa-phiprop.cc
> > +++ b/gcc/tree-ssa-phiprop.cc
> > @@ -401,7 +401,8 @@ propagate_with_phi (basic_block bb, gphi *phi, struct 
> > phiprop_d *phivn,
> >           def_stmt = SSA_NAME_DEF_STMT (vuse);
> >         }
> >        if (!SSA_NAME_IS_DEFAULT_DEF (vuse)
> > -         && (gimple_bb (def_stmt) == bb
> > +         && ((gimple_bb (def_stmt) == bb
> > +              && !is_a<gphi *>(def_stmt))
> >               || (gimple_bb (def_stmt)
> >                   && !dominated_by_p (CDI_DOMINATORS,
> >                                       bb, gimple_bb (def_stmt)))))
> > --
> > 2.43.0
> >

Reply via email to