1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
From a49a60790ae2032dfeee617ba9488fc80e09b3a8 Mon Sep 17 00:00:00 2001
Message-ID: <a49a60790ae2032dfeee617ba9488fc80e09b3a8.1731138919.git.sam@gentoo.org>
From: Andrew Pinski <quic_apinski@quicinc.com>
Date: Fri, 8 Nov 2024 17:35:02 -0800
Subject: [PATCH] VN: Don't recurse on for the same value of `a | b` [PR117496]
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 | 25 +++++++++++++++++++++++
gcc/tree-ssa-sccvn.cc | 11 ++++++++--
2 files changed, 34 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/torture/pr117496-1.c
diff --git a/gcc/testsuite/gcc.dg/torture/pr117496-1.c b/gcc/testsuite/gcc.dg/torture/pr117496-1.c
new file mode 100644
index 000000000000..f35d13dfa85d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr117496-1.c
@@ -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++;
+ }
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 1967bbdca84d..9c460fc1bdb3 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -7897,6 +7897,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)
@@ -7973,10 +7974,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);
}
}
}
--
2.47.0
|