]> git.ipfire.org Git - people/ms/gcc.git/commitdiff
reassoc: Fold some statements [PR108819]
authorJakub Jelinek <jakub@redhat.com>
Sat, 18 Feb 2023 11:40:49 +0000 (12:40 +0100)
committerJakub Jelinek <jakub@redhat.com>
Sun, 19 Mar 2023 05:28:51 +0000 (06:28 +0100)
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.

(cherry picked from commit 32b5875c911f80d551d006d7473e6f1f8705857a)

gcc/testsuite/gcc.dg/pr108819.c [new file with mode: 0644]
gcc/tree-ssa-reassoc.cc

diff --git a/gcc/testsuite/gcc.dg/pr108819.c b/gcc/testsuite/gcc.dg/pr108819.c
new file mode 100644 (file)
index 0000000..28fa558
--- /dev/null
@@ -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;
+}
index 43b25371d4b02c6e3410783f856db394f8a9738b..016efced1c686d44b835fd8a0afb77f005b11961 100644 (file)
@@ -4650,6 +4650,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;
 }