* [PATCH] tree-optimization/112939 - VN PHI visiting and -ftrivial-auto-var-init
@ 2023-12-12 7:14 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-12-12 7:14 UTC (permalink / raw)
To: gcc-patches
The following builds upon the last fix, making sure we only value-number
to visited (un-)defs, otherwise prefer .VN_TOP.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
PR tree-optimization/112939
* tree-ssa-sccvn.cc (visit_phi): When all args are undefined
make sure we end up with a value that was visited, otherwise
fall back to .VN_TOP.
* gcc.dg/pr112939.c: New testcase.
---
gcc/testsuite/gcc.dg/pr112939.c | 23 +++++++++++++++++++++++
gcc/tree-ssa-sccvn.cc | 4 +++-
2 files changed, 26 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/pr112939.c
diff --git a/gcc/testsuite/gcc.dg/pr112939.c b/gcc/testsuite/gcc.dg/pr112939.c
new file mode 100644
index 00000000000..7017beff30a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr112939.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O -ftrivial-auto-var-init=zero" } */
+
+int i;
+
+void f (void)
+{
+ for (;;)
+ {
+ if (0)
+ for (;;)
+ {
+ int *a;
+ int *b = a;
+
+ l1:
+ *b = (*b != 0) ? 0 : 2;
+ }
+
+ if (i != 0)
+ goto l1;
+ }
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 11537fa3e0b..a178b768459 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -5946,6 +5946,8 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
if (TREE_CODE (def) == SSA_NAME)
{
tree val = SSA_VAL (def, &visited);
+ if (SSA_NAME_IS_DEFAULT_DEF (def))
+ visited = true;
if (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK))
def = val;
if (e->flags & EDGE_DFS_BACK)
@@ -6091,7 +6093,7 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
/* If we saw only undefined values and VN_TOP use one of the
undefined values. */
else if (sameval == VN_TOP)
- result = seen_undef ? seen_undef : sameval;
+ result = (seen_undef && seen_undef_visited) ? seen_undef : sameval;
/* First see if it is equivalent to a phi node in this block. We prefer
this as it allows IV elimination - see PRs 66502 and 67167. */
else if ((result = vn_phi_lookup (phi, backedges_varying_p)))
--
2.35.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-12-12 7:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-12 7:14 [PATCH] tree-optimization/112939 - VN PHI visiting and -ftrivial-auto-var-init Richard Biener
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).