From 72a07d9b66fd77ddbd1cfc12501e0722d67d509a Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 10 Nov 2010 10:59:20 +0000 Subject: re PR tree-optimization/46398 (early FRE miscompiles simple testcase) 2010-11-10 Richard Guenther PR tree-optimization/46398 * tree-ssa-sccvn.c (process_scc): Iterate for all PHIs. * gcc.dg/torture/pr46398.c: New testcase. From-SVN: r166527 --- gcc/tree-ssa-sccvn.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'gcc/tree-ssa-sccvn.c') diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 02613aa..994e945 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -3108,9 +3108,20 @@ process_scc (VEC (tree, heap) *scc) if (VEC_length (tree, scc) == 1) { tree use = VEC_index (tree, scc, 0); - if (!VN_INFO (use)->use_processed) - visit_use (use); - return; + if (VN_INFO (use)->use_processed) + return; + /* We need to make sure it doesn't form a cycle itself, which can + happen for self-referential PHI nodes. In that case we would + end up inserting an expression with VN_TOP operands into the + valid table which makes us derive bogus equivalences later. + The cheapest way to check this is to assume it for all PHI nodes. */ + if (gimple_code (SSA_NAME_DEF_STMT (use)) == GIMPLE_PHI) + /* Fallthru to iteration. */ ; + else + { + visit_use (use); + return; + } } /* Iterate over the SCC with the optimistic table until it stops -- cgit v1.1