From: Richard Biener <rguenther@suse.de>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] tree-ssa-math-opts: Fix up uaddc/usubc pattern matching [PR110271]
Date: Fri, 16 Jun 2023 19:04:03 +0200 [thread overview]
Message-ID: <92697657-9F94-4239-B039-F8A54C8A5963@suse.de> (raw)
In-Reply-To: <ZIxwDtDoomPI9d5n@tucnak>
> Am 16.06.2023 um 16:23 schrieb Jakub Jelinek <jakub@redhat.com>:
>
> Hi!
>
> The following testcase ICEs, because I misremembered what the return value
> from match_arith_overflow is. It isn't true if __builtin_*_overflow was
> matched, but it is true only in the BIT_NOT_EXPR case if stmt was removed.
>
> So, if match_arith_overflow matches something, gsi_stmt (gsi) will not
> be stmt and match_uaddc_usubc will be confused and can ICE.
>
> The following patch fixes it by checking if gsi_stmt (gsi) == stmt,
> in that case we know it is still a PLUS_EXPR/MINUS_EXPR and we can try to
> pattern match it further as UADDC/USUBC.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
Ok
Richard
> 2023-06-16 Jakub Jelinek <jakub@redhat.com>
>
> PR tree-optimization/110271
> * tree-ssa-math-opts.cc (math_opts_dom_walker::after_dom_children)
> <case PLUS_EXPR>: Ignore return value from match_arith_overflow,
> instead call match_uaddc_usubc only if gsi_stmt (gsi) is still stmt.
>
> * gcc.c-torture/compile/pr110271.c: New test.
>
> --- gcc/tree-ssa-math-opts.cc.jj 2023-06-15 09:12:28.777829348 +0200
> +++ gcc/tree-ssa-math-opts.cc 2023-06-16 10:44:31.231798664 +0200
> @@ -5558,9 +5558,12 @@ math_opts_dom_walker::after_dom_children
>
> case PLUS_EXPR:
> case MINUS_EXPR:
> - if (!convert_plusminus_to_widen (&gsi, stmt, code)
> - && !match_arith_overflow (&gsi, stmt, code, m_cfg_changed_p))
> - match_uaddc_usubc (&gsi, stmt, code);
> + if (!convert_plusminus_to_widen (&gsi, stmt, code))
> + {
> + match_arith_overflow (&gsi, stmt, code, m_cfg_changed_p);
> + if (gsi_stmt (gsi) == stmt)
> + match_uaddc_usubc (&gsi, stmt, code);
> + }
> break;
>
> case BIT_NOT_EXPR:
> --- gcc/testsuite/gcc.c-torture/compile/pr110271.c.jj 2023-06-16 10:57:32.757621687 +0200
> +++ gcc/testsuite/gcc.c-torture/compile/pr110271.c 2023-06-16 10:57:15.298871335 +0200
> @@ -0,0 +1,24 @@
> +/* PR tree-optimization/110271 */
> +
> +unsigned a, b, c, d, e;
> +
> +void
> +foo (unsigned *x, int y, unsigned int *z)
> +{
> + for (int i = 0; i < y; i++)
> + {
> + b += d;
> + a += b < d;
> + a += c = (__PTRDIFF_TYPE__) x > 3;
> + d = z[1] + (a < c);
> + a += e;
> + d += a < e;
> + }
> +}
> +
> +void
> +bar (unsigned int *z)
> +{
> + unsigned *x = x;
> + foo (x, 9, z);
> +}
>
> Jakub
>
prev parent reply other threads:[~2023-06-16 17:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-16 14:22 Jakub Jelinek
2023-06-16 17:04 ` Richard Biener [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=92697657-9F94-4239-B039-F8A54C8A5963@suse.de \
--to=rguenther@suse.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.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).