public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Pinski <pinskia@gmail.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: Andrew Pinski <apinski@marvell.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Fix PR 110874: infinite loop in gimple_bitwise_inverted_equal_p with fre
Date: Thu, 3 Aug 2023 02:23:13 -0700	[thread overview]
Message-ID: <CA+=Sn1n=75=WxeVYH838LPFj_iQ=O9LvfX5D2OczL0afkxJPYg@mail.gmail.com> (raw)
In-Reply-To: <CAFiYyc3Mo_m6s4ksO=kv8nsLJBa8wU6842vj2BKo2uBfSwsxzw@mail.gmail.com>

On Thu, Aug 3, 2023 at 12:23 AM Richard Biener via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> On Thu, Aug 3, 2023 at 4:34 AM Andrew Pinski via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> >
> > So I didn't expect valueization to cause calling gimple_nop_convert
> > to iterate between 2 different SSA names causing an infinite loop
> > in gimple_bitwise_inverted_equal_p.
> > So we should cause a bound on gimple_bitwise_inverted_equal_p calling
> > gimple_nop_convert and only look through one rather than always.
> >
> > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
> >
> > gcc/ChangeLog:
> >
> >         PR tree-optimization/110874
> >         * gimple-match-head.cc (gimple_bitwise_inverted_equal_p):
> >         Add new argument, again with default value of true.
> >         Don't try gimple_nop_convert if again is false.
> >         Update call to gimple_bitwise_inverted_equal_p for
> >         new argument.
> >
> > gcc/testsuite/ChangeLog:
> >
> >         PR tree-optimization/110874
> >         * gcc.c-torture/compile/pr110874-a.c: New test.
> > ---
> >  gcc/gimple-match-head.cc                        | 14 +++++++++-----
> >  .../gcc.c-torture/compile/pr110874-a.c          | 17 +++++++++++++++++
> >  2 files changed, 26 insertions(+), 5 deletions(-)
> >  create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr110874-a.c
> >
> > diff --git a/gcc/gimple-match-head.cc b/gcc/gimple-match-head.cc
> > index b1e96304d7c..e91aaab86dd 100644
> > --- a/gcc/gimple-match-head.cc
> > +++ b/gcc/gimple-match-head.cc
> > @@ -273,7 +273,7 @@ gimple_bitwise_equal_p (tree expr1, tree expr2, tree (*valueize) (tree))
> >  /* Helper function for bitwise_equal_p macro.  */
> >
> >  static inline bool
> > -gimple_bitwise_inverted_equal_p (tree expr1, tree expr2, tree (*valueize) (tree))
> > +gimple_bitwise_inverted_equal_p (tree expr1, tree expr2, tree (*valueize) (tree), bool again = true)
> >  {
> >    if (expr1 == expr2)
> >      return false;
> > @@ -285,12 +285,16 @@ gimple_bitwise_inverted_equal_p (tree expr1, tree expr2, tree (*valueize) (tree)
> >      return false;
> >
> >    tree other;
> > -  if (gimple_nop_convert (expr1, &other, valueize)
> > -      && gimple_bitwise_inverted_equal_p (other, expr2, valueize))
> > +  if (again
> > +      && gimple_nop_convert (expr1, &other, valueize)
> > +      && other != expr1
> > +      && gimple_bitwise_inverted_equal_p (other, expr2, valueize, false))
> >      return true;
> >
> > -  if (gimple_nop_convert (expr2, &other, valueize)
> > -      && gimple_bitwise_inverted_equal_p (expr1, other, valueize))
> > +  if (again
> > +      && gimple_nop_convert (expr2, &other, valueize)
> > +      && other != expr2
> > +      && gimple_bitwise_inverted_equal_p (expr1, other, valueize, false))
> >      return true;
>
> Hmm, I don't think this tests all three relevant combinations?  I think the way
> gimple_bitwise_equal_p handles this is better (not recursing).  I'd split out
> the "tail" matching the BIT_NOT to another helper, I suppose that could
> even be a (match ...) pattern here.

That sounds like a better idea. I am testing the patch right now that
uses a (match ) pattern for
the BIT_NOT and CMP cases. That will remove the recursiveness too.

Thanks,
Andrew

>
> >    if (TREE_CODE (expr1) != SSA_NAME
> > diff --git a/gcc/testsuite/gcc.c-torture/compile/pr110874-a.c b/gcc/testsuite/gcc.c-torture/compile/pr110874-a.c
> > new file mode 100644
> > index 00000000000..b314410a892
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.c-torture/compile/pr110874-a.c
> > @@ -0,0 +1,17 @@
> > +struct S1 {
> > +  unsigned f0;
> > +};
> > +static int g_161;
> > +void func_109(unsigned g_227, unsigned t) {
> > +  struct S1 l_178;
> > +  int l_160 = 0x1FAE99D5L;
> > +  int *l_230[] = {&l_160};
> > +  if (l_160) {
> > +    for (l_178.f0 = -7; l_178.f0;) {
> > +      ++g_227;
> > +      break;
> > +    }
> > +    (g_161) = g_227;
> > +  }
> > +  (g_161) &= t;
> > +}
> > --
> > 2.31.1
> >

      reply	other threads:[~2023-08-03  9:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-03  2:34 Andrew Pinski
2023-08-03  7:21 ` Richard Biener
2023-08-03  9:23   ` Andrew Pinski [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+=Sn1n=75=WxeVYH838LPFj_iQ=O9LvfX5D2OczL0afkxJPYg@mail.gmail.com' \
    --to=pinskia@gmail.com \
    --cc=apinski@marvell.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).