From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7879) id C593E3858D32; Sun, 4 Sep 2022 12:23:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C593E3858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662294232; bh=leXdbaIzzhEGYahM3lcZYRjr57E2MODQROfsEEgH7ZY=; h=From:To:Subject:Date:From; b=Pe2DzhAqK8GfEpFPLh/cbNXjTAKqpviyQPO/a2rSJiPZv6lKlCd1PWURow7lHrJlB DUe6a6mbrfZ0QtBwIy/kpoaGWp3vnQFcrZ/eUHUH9WD8/u3uGsgUziEp5n2zyxodB5 TGZTVjS4VwOdeps6LTmU5j/DF2RbLrnO9G9zDb+U= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Filip Kastl To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/pheeck/heads/sccp)] fixed error where algorithm would ignore non-ssa names X-Act-Checkin: gcc X-Git-Author: Filip Kastl X-Git-Refname: refs/users/pheeck/heads/sccp X-Git-Oldrev: c798727d40ceb10337f785c448d07e62c184513c X-Git-Newrev: fe245814b018faba7e5095e9eeb081fd25ca23fc Message-Id: <20220904122352.C593E3858D32@sourceware.org> Date: Sun, 4 Sep 2022 12:23:52 +0000 (GMT) List-Id: https://gcc.gnu.org/g:fe245814b018faba7e5095e9eeb081fd25ca23fc commit fe245814b018faba7e5095e9eeb081fd25ca23fc Author: Filip Kastl Date: Sun Sep 4 14:23:45 2022 +0200 fixed error where algorithm would ignore non-ssa names Diff: --- gcc/sccp.cc | 69 +++++++++++++++++++------------------------------------------ 1 file changed, 21 insertions(+), 48 deletions(-) diff --git a/gcc/sccp.cc b/gcc/sccp.cc index a4b332e0c29..4dcedc293fd 100644 --- a/gcc/sccp.cc +++ b/gcc/sccp.cc @@ -219,7 +219,7 @@ tarjan_compute_sccs (vec phis) { tree op_var = gimple_phi_arg_def (phi, j); if (TREE_CODE (op_var) != SSA_NAME) - continue; /* Skip arguments that aren't SSA names. */ + continue; /* Skip any operand that isn't an SSA name. */ gimple *op_stmt = SSA_NAME_DEF_STMT (op_var); @@ -260,7 +260,7 @@ tarjan_compute_sccs (vec phis) tree op_var = gimple_phi_arg_def (phi, j); // TODO Same code // twice (iterator?) if (TREE_CODE (op_var) != SSA_NAME) - continue; /* Skip arguments that aren't SSA names. */ + continue; /* Skip any operand that isn't an SSA name. */ gimple *op_stmt = SSA_NAME_DEF_STMT (op_var); @@ -352,8 +352,14 @@ remove_zero_uses_phis () gphi *phi = pi.phi (); tree ssa_name = gimple_phi_result (phi); if (has_zero_uses (ssa_name)) - /* Note that remove_phi_node() also frees SSA name. */ - remove_phi_node (&pi, true); + { + /* Note that remove_phi_node() also frees SSA name. */ + remove_phi_node (&pi, true); + + // DEBUG + unsigned version = SSA_NAME_VERSION (ssa_name); + std::cerr << "Removed " << version << std::endl; + } else gsi_next (&pi); } @@ -376,18 +382,20 @@ process_scc (vec scc) unsigned i; for (i = 0; i < gimple_phi_num_args (phi); i++) { + // Check if operand is a phi from scc + bool op_in_scc = false; tree op = gimple_phi_arg_def (phi, i); - if (TREE_CODE (op) != SSA_NAME) - continue; /* Skip arguments that aren't SSA names. */ - gimple *op_stmt = SSA_NAME_DEF_STMT (op); - - // Check if operand is a phi from scc (TODO Efficiency) - bool op_in_scc = false; - for (gphi *foo : scc) + if (TREE_CODE (op) == SSA_NAME) { - if (op_stmt == foo) - op_in_scc = true; + gimple *op_stmt = SSA_NAME_DEF_STMT (op); + + // TODO Efficiency + for (gphi *foo : scc) + { + if (op_stmt == foo) + op_in_scc = true; + } } if (!op_in_scc) @@ -408,7 +416,6 @@ process_scc (vec scc) replace_scc_by_value (scc, outer_ops.pop()); else if (outer_ops.length () > 1) { - std::cerr << inner.length () << std::endl; remove_redundant_phis (inner); } } @@ -459,40 +466,6 @@ pass_sccp::execute (function *) { init_sccp (); remove_redundant_phis (get_all_normal_phis ()); - - /* - // DEBUG - basic_block bb; - FOR_EACH_BB_FN (bb, cfun) - { - debug_bb (bb); - gphi_iterator pi; - std::cerr << "PHI LIST" << std::endl; - for (pi = gsi_start_phis (bb); !gsi_end_p (pi); gsi_next (&pi)) - { - gphi *phi = pi.phi (); - debug_gimple_stmt (phi); - } - std::cerr << std::endl << std::endl; - } - */ - - /* - std::cerr << "function:" << std::endl; - for (vec scc : sccs) - { - std::cerr << "scc:" << std::endl; - for (gphi *phi : scc) - { - tree ssa_name = gimple_phi_result (phi); - unsigned vnum = SSA_NAME_VERSION (ssa_name); - std::cerr << vnum << std::endl; - } - std::cerr << std::endl; - } - std::cerr << std::endl; - */ - finalize_sccp (); return 0;