public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-6132] reassoc: Fold some statements [PR108819]
Date: Sat, 18 Feb 2023 11:41:23 +0000 (GMT)	[thread overview]
Message-ID: <20230218114123.1A2263858D32@sourceware.org> (raw)

https://gcc.gnu.org/g:32b5875c911f80d551d006d7473e6f1f8705857a

commit r13-6132-g32b5875c911f80d551d006d7473e6f1f8705857a
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Feb 18 12:40:49 2023 +0100

    reassoc: Fold some statements [PR108819]
    
    This spot in update_ops can replace one or both of the assign operands with
    constants, creating 1 & 1 and similar expressions which can confuse later
    passes until they are folded.  Rather than folding both constants by hand
    and also handling swapping of operands for commutative ops if the first one
    is constant and second one is not, the following patch just uses
    fold_stmt_inplace to do that.  I think we shouldn't fold more than the
    single statement because that could screw up the rest of the pass, we'd have
    to mark all those with uids, visited and the like.
    
    2023-02-18  Jakub Jelinek  <jakub@redhat.com>
    
            PR tree-optimization/108819
            * tree-ssa-reassoc.cc (update_ops): Fold new stmt in place.
    
            * gcc.dg/pr108819.c: New test.

Diff:
---
 gcc/testsuite/gcc.dg/pr108819.c | 19 +++++++++++++++++++
 gcc/tree-ssa-reassoc.cc         |  3 +++
 2 files changed, 22 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/pr108819.c b/gcc/testsuite/gcc.dg/pr108819.c
new file mode 100644
index 00000000000..28fa558b260
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr108819.c
@@ -0,0 +1,19 @@
+/* PR tree-optimization/108819 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fno-tree-ccp -fno-tree-forwprop" } */
+
+int a, b;
+
+int
+main ()
+{
+  int d = 1;
+  for (; b; b++)
+    if (a < 1)
+      while (d <= a && a <= 0UL)
+	{
+	  int *e = &d;
+	  *e = 0;
+	}
+  return 0;
+}
diff --git a/gcc/tree-ssa-reassoc.cc b/gcc/tree-ssa-reassoc.cc
index f163612f140..8fd22591f55 100644
--- a/gcc/tree-ssa-reassoc.cc
+++ b/gcc/tree-ssa-reassoc.cc
@@ -4687,6 +4687,9 @@ update_ops (tree var, enum tree_code code, const vec<operand_entry *> &ops,
       gimple_set_uid (g, gimple_uid (stmt));
       gimple_set_visited (g, true);
       gsi_insert_before (&gsi, g, GSI_SAME_STMT);
+      gimple_stmt_iterator gsi2 = gsi_for_stmt (g);
+      if (fold_stmt_inplace (&gsi2))
+	update_stmt (g);
     }
   return var;
 }

                 reply	other threads:[~2023-02-18 11:41 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=20230218114123.1A2263858D32@sourceware.org \
    --to=jakub@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).