* [PATCH] MATCH: Make zero_one_valued_p non-recusive fully
@ 2023-09-17 21:40 Andrew Pinski
2023-09-18 9:04 ` Richard Biener
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Pinski @ 2023-09-17 21:40 UTC (permalink / raw)
To: gcc-patches; +Cc: Andrew Pinski
So it turns out VN can't handle any kind of recusion for match. In this
case we have `b = a & -1` and we try to match a as being zero_one_valued_p
and VN returns b as being the value and we just go into an infinite loop at
this point.
OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
Note genmatch should warn (or error out) if this gets detected so I filed PR 111446
which I will be looking into next week or the week after so we don't run into
this issue again.
PR tree-optimization/111442
gcc/ChangeLog:
* match.pd (zero_one_valued_p): Have the bit_and match not be
recusive.
gcc/testsuite/ChangeLog:
* gcc.c-torture/compile/pr111442-1.c: New test.
---
gcc/match.pd | 5 ++++-
gcc/testsuite/gcc.c-torture/compile/pr111442-1.c | 13 +++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr111442-1.c
diff --git a/gcc/match.pd b/gcc/match.pd
index 887665633d4..773c3810f51 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2183,8 +2183,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* (a&1) is always [0,1] too. This is useful again when
the range is not known. */
+/* Note this can't be recusive due to VN handling of equivalents,
+ VN and would cause an infinite recusion. */
(match zero_one_valued_p
- (bit_and:c@0 @1 zero_one_valued_p))
+ (bit_and:c@0 @1 integer_onep)
+ (if (INTEGRAL_TYPE_P (type))))
/* A conversion from an zero_one_valued_p is still a [0,1].
This is useful when the range of a variable is not known */
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr111442-1.c b/gcc/testsuite/gcc.c-torture/compile/pr111442-1.c
new file mode 100644
index 00000000000..5814ee938de
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr111442-1.c
@@ -0,0 +1,13 @@
+
+int *a, b;
+int main() {
+ int d = 1, e;
+ if (d)
+ e = a ? 0 % 0 : 0;
+ if (d)
+ a = &d;
+ d = -1;
+ b = d & e;
+ b = 2 * e ^ 1;
+ return 0;
+}
--
2.31.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] MATCH: Make zero_one_valued_p non-recusive fully
2023-09-17 21:40 [PATCH] MATCH: Make zero_one_valued_p non-recusive fully Andrew Pinski
@ 2023-09-18 9:04 ` Richard Biener
2023-09-18 9:08 ` Jakub Jelinek
0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2023-09-18 9:04 UTC (permalink / raw)
To: Andrew Pinski; +Cc: gcc-patches
On Sun, Sep 17, 2023 at 11:41 PM Andrew Pinski via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> So it turns out VN can't handle any kind of recusion for match. In this
> case we have `b = a & -1` and we try to match a as being zero_one_valued_p
> and VN returns b as being the value and we just go into an infinite loop at
> this point.
Huh, interesting. Must be because we return an available expression for
the b, a & -1 equivalency class. Otherwise I'd have expected you get 'a'.
>
> OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
OK.
Richard.
> Note genmatch should warn (or error out) if this gets detected so I filed PR 111446
> which I will be looking into next week or the week after so we don't run into
> this issue again.
>
> PR tree-optimization/111442
>
> gcc/ChangeLog:
>
> * match.pd (zero_one_valued_p): Have the bit_and match not be
> recusive.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.c-torture/compile/pr111442-1.c: New test.
> ---
> gcc/match.pd | 5 ++++-
> gcc/testsuite/gcc.c-torture/compile/pr111442-1.c | 13 +++++++++++++
> 2 files changed, 17 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr111442-1.c
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 887665633d4..773c3810f51 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -2183,8 +2183,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>
> /* (a&1) is always [0,1] too. This is useful again when
> the range is not known. */
> +/* Note this can't be recusive due to VN handling of equivalents,
> + VN and would cause an infinite recusion. */
> (match zero_one_valued_p
> - (bit_and:c@0 @1 zero_one_valued_p))
> + (bit_and:c@0 @1 integer_onep)
> + (if (INTEGRAL_TYPE_P (type))))
>
> /* A conversion from an zero_one_valued_p is still a [0,1].
> This is useful when the range of a variable is not known */
> diff --git a/gcc/testsuite/gcc.c-torture/compile/pr111442-1.c b/gcc/testsuite/gcc.c-torture/compile/pr111442-1.c
> new file mode 100644
> index 00000000000..5814ee938de
> --- /dev/null
> +++ b/gcc/testsuite/gcc.c-torture/compile/pr111442-1.c
> @@ -0,0 +1,13 @@
> +
> +int *a, b;
> +int main() {
> + int d = 1, e;
> + if (d)
> + e = a ? 0 % 0 : 0;
> + if (d)
> + a = &d;
> + d = -1;
> + b = d & e;
> + b = 2 * e ^ 1;
> + return 0;
> +}
> --
> 2.31.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] MATCH: Make zero_one_valued_p non-recusive fully
2023-09-18 9:04 ` Richard Biener
@ 2023-09-18 9:08 ` Jakub Jelinek
0 siblings, 0 replies; 3+ messages in thread
From: Jakub Jelinek @ 2023-09-18 9:08 UTC (permalink / raw)
To: Richard Biener, Andrew Pinski; +Cc: gcc-patches
On Mon, Sep 18, 2023 at 11:04:16AM +0200, Richard Biener via Gcc-patches wrote:
> > Note genmatch should warn (or error out) if this gets detected so I filed PR 111446
> > which I will be looking into next week or the week after so we don't run into
> > this issue again.
> >
> > PR tree-optimization/111442
> >
> > gcc/ChangeLog:
> >
> > * match.pd (zero_one_valued_p): Have the bit_and match not be
> > recusive.
s/recusive/recursive/g
s/recusion/recursion/g
> > diff --git a/gcc/match.pd b/gcc/match.pd
> > index 887665633d4..773c3810f51 100644
> > --- a/gcc/match.pd
> > +++ b/gcc/match.pd
> > @@ -2183,8 +2183,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> >
> > /* (a&1) is always [0,1] too. This is useful again when
> > the range is not known. */
> > +/* Note this can't be recusive due to VN handling of equivalents,
> > + VN and would cause an infinite recusion. */
> > (match zero_one_valued_p
> > - (bit_and:c@0 @1 zero_one_valued_p))
> > + (bit_and:c@0 @1 integer_onep)
> > + (if (INTEGRAL_TYPE_P (type))))
> >
> > /* A conversion from an zero_one_valued_p is still a [0,1].
> > This is useful when the range of a variable is not known */
> > diff --git a/gcc/testsuite/gcc.c-torture/compile/pr111442-1.c b/gcc/testsuite/gcc.c-torture/compile/pr111442-1.c
> > new file mode 100644
> > index 00000000000..5814ee938de
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.c-torture/compile/pr111442-1.c
> > @@ -0,0 +1,13 @@
> > +
> > +int *a, b;
> > +int main() {
> > + int d = 1, e;
> > + if (d)
> > + e = a ? 0 % 0 : 0;
> > + if (d)
> > + a = &d;
> > + d = -1;
> > + b = d & e;
> > + b = 2 * e ^ 1;
> > + return 0;
> > +}
> > --
> > 2.31.1
> >
Jakub
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-09-18 9:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-17 21:40 [PATCH] MATCH: Make zero_one_valued_p non-recusive fully Andrew Pinski
2023-09-18 9:04 ` Richard Biener
2023-09-18 9:08 ` Jakub Jelinek
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).