Skip to content

Commit

Permalink
tree-optimization/112939 - VN PHI visiting and -ftrivial-auto-var-init
Browse files Browse the repository at this point in the history
The following builds upon the last fix, making sure we only value-number
to visited (un-)defs, otherwise prefer .VN_TOP.

	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.
  • Loading branch information
rguenth committed Dec 12, 2023
1 parent fc62716 commit f5f33b4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 23 additions & 0 deletions gcc/testsuite/gcc.dg/pr112939.c
Original file line number Diff line number Diff line change
@@ -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;
}
}
4 changes: 3 additions & 1 deletion gcc/tree-ssa-sccvn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)))
Expand Down

0 comments on commit f5f33b4

Please sign in to comment.