]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
VN: Don't recurse on for the same value of `a | b` [PR117496]
authorAndrew Pinski <quic_apinski@quicinc.com>
Fri, 8 Nov 2024 21:39:05 +0000 (13:39 -0800)
committerAndrew Pinski <quic_apinski@quicinc.com>
Sat, 9 Nov 2024 16:20:33 +0000 (08:20 -0800)
After adding vn_valueize to the handle the `a | b ==/!= 0` case
of insert_predicates_for_cond, it would go into an infinite loop
as the Value number for either a or b could be the same as what it
is for the whole expression. This avoids that recursion so there is
no infinite loop here.

Bootstrapped and tested on x86_64-linux.

PR tree-optimization/117496

gcc/ChangeLog:

* tree-ssa-sccvn.cc (insert_predicates_for_cond): If the
valueization for the new lhs is the same as the old one,
don't recurse.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr117496-1.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/testsuite/gcc.dg/torture/pr117496-1.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr117496-1.c b/gcc/testsuite/gcc.dg/torture/pr117496-1.c
new file mode 100644 (file)
index 0000000..f35d13d
--- /dev/null
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+
+
+/* PR tree-optimization/117496 */
+/* This would go into an infinite loop into VN while recording
+   the predicates for the `tracks == 0 && wm == 0` GIMPLE_COND.
+   As wm_N and tracks_N would valueize back to `tracks | wm`.  */
+
+int main_argc, gargs_preemp, gargs_nopreemp;
+static void gargs();
+void main_argv() {
+  int tracks = 0;
+  gargs(main_argc, main_argv, &tracks);
+}
+void gargs(int, char *, int *tracksp) {
+  int tracks = *tracksp, wm;
+  for (;;) {
+    if (tracks == 0)
+      wm |= 4;
+    if (gargs_nopreemp)
+      gargs_preemp = 0;
+    if (tracks == 0 && wm == 0)
+      tracks++;
+  }
+}
index 16299662b957d6cfc7c5a38565947c6f470b6c9d..e93acb44200e8a171f9b0f02907d21b48fa511b4 100644 (file)
@@ -7900,6 +7900,7 @@ insert_related_predicates_on_edge (enum tree_code code, tree *ops, edge pred_e)
 
 /* Insert on the TRUE_E true and FALSE_E false predicates
    derived from LHS CODE RHS.  */
+
 static void
 insert_predicates_for_cond (tree_code code, tree lhs, tree rhs,
                            edge true_e, edge false_e)
@@ -7977,10 +7978,16 @@ insert_predicates_for_cond (tree_code code, tree lhs, tree rhs,
          tree nlhs;
 
          nlhs = vn_valueize (gimple_assign_rhs1 (def_stmt));
-         insert_predicates_for_cond (EQ_EXPR, nlhs, rhs, e, nullptr);
+         /* A valueization of the `a` might return the old lhs
+            which is already handled above. */
+         if (nlhs != lhs)
+           insert_predicates_for_cond (EQ_EXPR, nlhs, rhs, e, nullptr);
 
+         /* A valueization of the `b` might return the old lhs
+            which is already handled above. */
          nlhs = vn_valueize (gimple_assign_rhs2 (def_stmt));
-         insert_predicates_for_cond (EQ_EXPR, nlhs, rhs, e, nullptr);
+         if (nlhs != lhs)
+           insert_predicates_for_cond (EQ_EXPR, nlhs, rhs, e, nullptr);
        }
     }
 }