public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-5651] middle-end/108625 - wrong folding due to misinterpreted !
Date: Thu,  2 Feb 2023 12:13:42 +0000 (GMT)	[thread overview]
Message-ID: <20230202121342.1F6133858C60@sourceware.org> (raw)

https://gcc.gnu.org/g:605d1297b91c2c7c23ccfe669e66dda5791d1f55

commit r13-5651-g605d1297b91c2c7c23ccfe669e66dda5791d1f55
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Feb 2 11:09:26 2023 +0100

    middle-end/108625 - wrong folding due to misinterpreted !
    
    The following fixes a problem with ! handling in genmatch which isn't
    conservative enough when intermediate simplifications push to the
    sequence but the final operation appears to just pick an existing
    (but in this case newly defined in the sequence) operand.  The easiest
    fix is to disallow adding to the sequence when processing !.
    
            PR middle-end/108625
            * genmatch.cc (expr::gen_transform): Also disallow resimplification
            from pushing to lseq with force_leaf.
            (dt_simplify::gen_1): Likewise.
    
            * gcc.dg/pr108625.c: New testcase.

Diff:
---
 gcc/genmatch.cc                 |  6 ++++--
 gcc/testsuite/gcc.dg/pr108625.c | 14 ++++++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc
index e147ab9db7a..43bd0212d0e 100644
--- a/gcc/genmatch.cc
+++ b/gcc/genmatch.cc
@@ -2541,7 +2541,8 @@ expr::gen_transform (FILE *f, int indent, const char *dest, bool gimple,
       for (unsigned i = 0; i < ops.length (); ++i)
 	fprintf (f, ", _o%d[%u]", depth, i);
       fprintf (f, ");\n");
-      fprintf_indent (f, indent, "tem_op.resimplify (lseq, valueize);\n");
+      fprintf_indent (f, indent, "tem_op.resimplify (%s, valueize);\n",
+		      !force_leaf ? "lseq" : "NULL");
       fprintf_indent (f, indent,
 		      "_r%d = maybe_push_res_to_seq (&tem_op, %s);\n", depth,
 		      !force_leaf ? "lseq" : "NULL");
@@ -3451,7 +3452,8 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
 	  if (!is_predicate)
 	    {
 	      fprintf_indent (f, indent,
-			      "res_op->resimplify (lseq, valueize);\n");
+			      "res_op->resimplify (%s, valueize);\n",
+			      !e->force_leaf ? "lseq" : "NULL");
 	      if (e->force_leaf)
 		fprintf_indent (f, indent,
 				"if (!maybe_push_res_to_seq (res_op, NULL)) "
diff --git a/gcc/testsuite/gcc.dg/pr108625.c b/gcc/testsuite/gcc.dg/pr108625.c
new file mode 100644
index 00000000000..03fc2889c4f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr108625.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-forwprop1 -fdump-tree-optimized" } */
+
+unsigned char foo(int x)
+{
+  int t = -x;
+  unsigned char t1 = t;
+  unsigned char t2 = t;
+  /* We may not rewrite this as (unsigned char)(t - x).  */
+  return t1 + t2;
+}
+
+/* { dg-final { scan-tree-dump-times "x_" 1 "forwprop1" } } */
+/* { dg-final { scan-tree-dump-times "x_" 1 "optimized" } } */

                 reply	other threads:[~2023-02-02 12:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230202121342.1F6133858C60@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).