From 39bd65faee3bafe2dc067e5fedb5079896551a8a Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 4 Jan 2021 13:02:24 +0100 Subject: tree-optimization/98464 - replace loop info with avail at uses This does VN replacement in loop nb_iterations consistent with the rest of the IL by using availability at the definition site of uses. 2021-01-04 Richard Biener PR tree-optimization/98464 * tree-ssa-sccvn.c (vn_valueize_for_srt): Rename from ... (vn_valueize_wrapper): ... this. Temporarily adjust vn_context_bb. (process_bb): Adjust. * g++.dg/opt/pr98464.C: New testcase. --- gcc/tree-ssa-sccvn.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'gcc/tree-ssa-sccvn.c') diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 19defc0..1701685 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -304,12 +304,23 @@ static vn_nary_op_t last_inserted_nary; static vn_tables_t valid_info; -/* Valueization hook. Valueize NAME if it is an SSA name, otherwise - just return it. */ +/* Valueization hook for simplify_replace_tree. Valueize NAME if it is + an SSA name, otherwise just return it. */ tree (*vn_valueize) (tree); -tree vn_valueize_wrapper (tree t, void* context ATTRIBUTE_UNUSED) -{ - return vn_valueize (t); +static tree +vn_valueize_for_srt (tree t, void* context ATTRIBUTE_UNUSED) +{ + basic_block saved_vn_context_bb = vn_context_bb; + /* Look for sth available at the definition block of the argument. + This avoids inconsistencies between availability there which + decides if the stmt can be removed and availability at the + use site. The SSA property ensures that things available + at the definition are also available at uses. */ + if (!SSA_NAME_IS_DEFAULT_DEF (t)) + vn_context_bb = gimple_bb (SSA_NAME_DEF_STMT (t)); + tree res = vn_valueize (t); + vn_context_bb = saved_vn_context_bb; + return res; } @@ -6995,7 +7006,7 @@ process_bb (rpo_elim &avail, basic_block bb, if (bb->loop_father->nb_iterations) bb->loop_father->nb_iterations = simplify_replace_tree (bb->loop_father->nb_iterations, - NULL_TREE, NULL_TREE, &vn_valueize_wrapper); + NULL_TREE, NULL_TREE, &vn_valueize_for_srt); } /* Value-number all defs in the basic-block. */ -- cgit v1.1