From patchwork Mon Apr 24 09:54:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 754182 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wBMBp4pb1z9sDC for ; Mon, 24 Apr 2017 19:54:35 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="oFutJj56"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=oVkNmWJ2bgge+Dotyngk4BW5d3bNwMF3qN/bka6SK5/+OiSFO6QSX Y4amXe3dRTEKVH2j1IKVHVVHNmwxmgUvhV4i1TvFmcUyRgIUOgplgytiEb1FTucX g4GZ7Ql/pY6POW2xXdRg26Js5et3LAhceJrPk8yDa5uObRtmwcZjGo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=LL1GUr2PZOkS34xWqDb5qMrwOyY=; b=oFutJj56VR+XbDQvtyrf qaQ6EQDTT364HdYggqKJxCM4Rvc9Ndr7XCVYZxfIKzjTqt8YD0VOk2zK32FqyD5R YHSZa/yT9v1fR7IfJRpIY55DHQyV3iupskvPNSrhdcpwLklTyDewSM4t72Gc5Hwp DqqaNCtzPX801A1aIM7HTQw= Received: (qmail 67836 invoked by alias); 24 Apr 2017 09:54:21 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 67823 invoked by uid 89); 24 Apr 2017 09:54:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=exceeding, walker X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Apr 2017 09:54:18 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9C26AAC65 for ; Mon, 24 Apr 2017 09:54:18 +0000 (UTC) Date: Mon, 24 Apr 2017 11:54:18 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Cleanup SCCVN Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 This does a cleanup I postponed for GCC 8, namely not fail value-numbering completely if we end up with a large SCC but instead just drop that SCC to varying. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2017-04-24 Richard Biener * tree-ssa-sccvn.h (run_scc_vn): Adjust prototype. * tree-ssa-sccvn.c (print_scc): Print SCC size. (extract_and_process_scc_for_name): Never fail but drop SCC to varying. (DFS): Adjust and never fail. (sccvn_dom_walker::fail): Remove. (sccvn_dom_walker::before_dom_children): Adjust. (run_scc_vn): Likewise and never fail. * tree-ssa-pre.c (pass_pre::execute): Adjust. (pass_fre::execute): Likewise. Index: gcc/tree-ssa-pre.c =================================================================== --- gcc/tree-ssa-pre.c (revision 247091) +++ gcc/tree-ssa-pre.c (working copy) @@ -5086,11 +5086,7 @@ pass_pre::execute (function *fun) loop_optimizer_init may create new phis, etc. */ loop_optimizer_init (LOOPS_NORMAL); - if (!run_scc_vn (VN_WALK)) - { - loop_optimizer_finalize (); - return 0; - } + run_scc_vn (VN_WALK); init_pre (); scev_initialize (); @@ -5202,8 +5198,7 @@ pass_fre::execute (function *fun) { unsigned int todo = 0; - if (!run_scc_vn (VN_WALKREWRITE)) - return 0; + run_scc_vn (VN_WALKREWRITE); memset (&pre_stats, 0, sizeof (pre_stats)); Index: gcc/tree-ssa-sccvn.c =================================================================== --- gcc/tree-ssa-sccvn.c (revision 247091) +++ gcc/tree-ssa-sccvn.c (working copy) @@ -3153,7 +3153,7 @@ print_scc (FILE *out, vec scc) tree var; unsigned int i; - fprintf (out, "SCC consists of:"); + fprintf (out, "SCC consists of %u:", scc.length ()); FOR_EACH_VEC_ELT (scc, i, var) { fprintf (out, " "); @@ -4316,7 +4316,7 @@ process_scc (vec scc) and process them. Returns true if all went well, false if we run into resource limits. */ -static bool +static void extract_and_process_scc_for_name (tree name) { auto_vec scc; @@ -4332,24 +4332,37 @@ extract_and_process_scc_for_name (tree n scc.safe_push (x); } while (x != name); - /* Bail out of SCCVN in case a SCC turns out to be incredibly large. */ - if (scc.length () - > (unsigned)PARAM_VALUE (PARAM_SCCVN_MAX_SCC_SIZE)) + /* Drop all defs in the SCC to varying in case a SCC turns out to be + incredibly large. + ??? Just switch to a non-optimistic mode that avoids any iteration. */ + if (scc.length () > (unsigned)PARAM_VALUE (PARAM_SCCVN_MAX_SCC_SIZE)) { if (dump_file) - fprintf (dump_file, "WARNING: Giving up with SCCVN due to " - "SCC size %u exceeding %u\n", scc.length (), - (unsigned)PARAM_VALUE (PARAM_SCCVN_MAX_SCC_SIZE)); - - return false; + { + print_scc (dump_file, scc); + fprintf (dump_file, "WARNING: Giving up value-numbering SCC due to " + "size %u exceeding %u\n", scc.length (), + (unsigned)PARAM_VALUE (PARAM_SCCVN_MAX_SCC_SIZE)); + } + tree var; + unsigned i; + FOR_EACH_VEC_ELT (scc, i, var) + { + gimple *def = SSA_NAME_DEF_STMT (var); + mark_use_processed (var); + if (SSA_NAME_IS_DEFAULT_DEF (var) + || gimple_code (def) == GIMPLE_PHI) + set_ssa_val_to (var, var); + else + defs_to_varying (def); + } + return; } if (scc.length () > 1) sort_scc (scc); process_scc (scc); - - return true; } /* Depth first search on NAME to discover and process SCC's in the SSA @@ -4359,7 +4372,7 @@ extract_and_process_scc_for_name (tree n Returns true if successful, false if we stopped processing SCC's due to resource constraints. */ -static bool +static void DFS (tree name) { auto_vec itervec; @@ -4399,12 +4412,11 @@ start_over: { /* See if we found an SCC. */ if (VN_INFO (name)->low == VN_INFO (name)->dfsnum) - if (!extract_and_process_scc_for_name (name)) - return false; + extract_and_process_scc_for_name (name); /* Check if we are done. */ if (namevec.is_empty ()) - return true; + return; /* Restore the last use walker and continue walking there. */ use = name; @@ -4687,7 +4699,7 @@ class sccvn_dom_walker : public dom_walk { public: sccvn_dom_walker () - : dom_walker (CDI_DOMINATORS, true), fail (false), cond_stack (0) {} + : dom_walker (CDI_DOMINATORS, true), cond_stack (0) {} virtual edge before_dom_children (basic_block); virtual void after_dom_children (basic_block); @@ -4697,7 +4709,6 @@ public: void record_conds (basic_block, enum tree_code code, tree lhs, tree rhs, bool value); - bool fail; auto_vec > > cond_stack; }; @@ -4793,9 +4804,6 @@ sccvn_dom_walker::before_dom_children (b edge e; edge_iterator ei; - if (fail) - return NULL; - if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, "Visiting BB %d\n", bb->index); @@ -4851,12 +4859,8 @@ sccvn_dom_walker::before_dom_children (b { gphi *phi = gsi.phi (); tree res = PHI_RESULT (phi); - if (!VN_INFO (res)->visited - && !DFS (res)) - { - fail = true; - return NULL; - } + if (!VN_INFO (res)->visited) + DFS (res); } for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) @@ -4864,12 +4868,8 @@ sccvn_dom_walker::before_dom_children (b ssa_op_iter i; tree op; FOR_EACH_SSA_TREE_OPERAND (op, gsi_stmt (gsi), i, SSA_OP_ALL_DEFS) - if (!VN_INFO (op)->visited - && !DFS (op)) - { - fail = true; - return NULL; - } + if (!VN_INFO (op)->visited) + DFS (op); } /* Finally look at the last stmt. */ @@ -4941,7 +4941,7 @@ sccvn_dom_walker::before_dom_children (b due to resource constraints. DEFAULT_VN_WALK_KIND_ specifies how we use the alias oracle walking during the VN process. */ -bool +void run_scc_vn (vn_lookup_kind default_vn_walk_kind_) { size_t i; @@ -4977,12 +4977,6 @@ run_scc_vn (vn_lookup_kind default_vn_wa SSA defs and decide whether outgoing edges are not executable. */ sccvn_dom_walker walker; walker.walk (ENTRY_BLOCK_PTR_FOR_FN (cfun)); - if (walker.fail) - { - scc_vn_restore_ssa_info (); - free_scc_vn (); - return false; - } /* Initialize the value ids and prune out remaining VN_TOPs from dead code. */ @@ -5027,8 +5021,6 @@ run_scc_vn (vn_lookup_kind default_vn_wa } } } - - return true; } /* Return the maximum value id we have ever seen. */ Index: gcc/tree-ssa-sccvn.h =================================================================== --- gcc/tree-ssa-sccvn.h (revision 247091) +++ gcc/tree-ssa-sccvn.h (working copy) @@ -212,7 +212,7 @@ enum vn_lookup_kind { VN_NOWALK, VN_WALK extern vn_ssa_aux_t VN_INFO (tree); extern vn_ssa_aux_t VN_INFO_GET (tree); tree vn_get_expr_for (tree); -bool run_scc_vn (vn_lookup_kind); +void run_scc_vn (vn_lookup_kind); void free_scc_vn (void); void scc_vn_restore_ssa_info (void); tree vn_nary_op_lookup (tree, vn_nary_op_t *);