From patchwork Fri Oct 26 10:58:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 989536 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-488389-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="voH6ezfp"; dkim-atps=neutral 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 42hLZN485rz9sDX for ; Fri, 26 Oct 2018 21:58:19 +1100 (AEDT) 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=iDWvjIfd70/dSW0XAh/7XGq2Rz4mrS/2Z/SpQ5H35GrR4vpHu1I+G vd6Vs7scfidgBipMdE82YTpeHChXovG/bj9d9tEOrNVH9PtHu9ImdoQfuD0BzEHN sm8hfzl8pTK16QMdY8JQY/cf9Ek9fo1JQe6HsWI1uNOZkFRZJ2qh48= 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=cIkO+jTMKbqao/Qi06u5TLsi8AE=; b=voH6ezfpmTZdY3pZ8FuK u70Ehqi+ZOV0ep9aPuwiddGgF7olW4f7BZDg7Mny8BqCA06N0+GzQL33edNINEXz USuJMA0hbw4SziY1naFm62AHTPiC56MA82cxjqoLD80DQywLDSgA5SyZYwkNwX++ fTyi2jWRMDiH8+ptPNqWOvE= Received: (qmail 101622 invoked by alias); 26 Oct 2018 10:58:10 -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 101575 invoked by uid 89); 26 Oct 2018 10:58:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=Ideas, walking, life 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; Fri, 26 Oct 2018 10:58:06 +0000 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2FFDDAD5D for ; Fri, 26 Oct 2018 10:58:04 +0000 (UTC) Date: Fri, 26 Oct 2018 12:58:03 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix compile-time issue with last SLP vectorizer patch Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 While I fixed up all correctness places I totally forgot about compile-time when not adding visited hash_set<>s to all SLP tree walks. This rectifies things and fixes 538.imagick_r build time (currently reducing a testcase which I will add once finished). Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. I wish there were a nicer C++ way of allocating the visited set than adding wrapping overloads. I played with void foo (hash_set &visited = hash_set ()) but that doesn't work because visited isn't const. Making it const also doesn't work of course (unless casting the const away in the function). Ideas? Thanks, Richard. 2018-10-26 Richard Biener * tree-vect-slp.c (vect_mark_slp_stmts): Add visited hash_set and wrapper. (vect_mark_slp_stmts_relevant): Likewise. (vect_detect_hybrid_slp_stmts): Likewise. (vect_bb_slp_scalar_cost): Likewise. (vect_remove_slp_scalar_calls): Likewise. diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c index ab8504a10bd..5b925be80f4 100644 --- a/gcc/tree-vect-slp.c +++ b/gcc/tree-vect-slp.c @@ -1483,7 +1483,8 @@ vect_print_slp_tree (dump_flags_t dump_kind, dump_location_t loc, stmts in NODE are to be marked. */ static void -vect_mark_slp_stmts (slp_tree node, enum slp_vect_type mark, int j) +vect_mark_slp_stmts (slp_tree node, enum slp_vect_type mark, int j, + hash_set &visited) { int i; stmt_vec_info stmt_info; @@ -1492,19 +1493,28 @@ vect_mark_slp_stmts (slp_tree node, enum slp_vect_type mark, int j) if (SLP_TREE_DEF_TYPE (node) != vect_internal_def) return; + if (visited.add (node)) + return; + FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) if (j < 0 || i == j) STMT_SLP_TYPE (stmt_info) = mark; FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child) - vect_mark_slp_stmts (child, mark, j); + vect_mark_slp_stmts (child, mark, j, visited); } +static void +vect_mark_slp_stmts (slp_tree node, enum slp_vect_type mark, int j) +{ + hash_set visited; + vect_mark_slp_stmts (node, mark, j, visited); +} /* Mark the statements of the tree rooted at NODE as relevant (vect_used). */ static void -vect_mark_slp_stmts_relevant (slp_tree node) +vect_mark_slp_stmts_relevant (slp_tree node, hash_set &visited) { int i; stmt_vec_info stmt_info; @@ -1513,6 +1523,9 @@ vect_mark_slp_stmts_relevant (slp_tree node) if (SLP_TREE_DEF_TYPE (node) != vect_internal_def) return; + if (visited.add (node)) + return; + FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) { gcc_assert (!STMT_VINFO_RELEVANT (stmt_info) @@ -1521,7 +1534,14 @@ vect_mark_slp_stmts_relevant (slp_tree node) } FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child) - vect_mark_slp_stmts_relevant (child); + vect_mark_slp_stmts_relevant (child, visited); +} + +static void +vect_mark_slp_stmts_relevant (slp_tree node) +{ + hash_set visited; + vect_mark_slp_stmts_relevant (node, visited); } @@ -2200,7 +2220,8 @@ vect_make_slp_decision (loop_vec_info loop_vinfo) can't be SLPed) in the tree rooted at NODE. Mark such stmts as HYBRID. */ static void -vect_detect_hybrid_slp_stmts (slp_tree node, unsigned i, slp_vect_type stype) +vect_detect_hybrid_slp_stmts (slp_tree node, unsigned i, slp_vect_type stype, + hash_set &visited) { stmt_vec_info stmt_vinfo = SLP_TREE_SCALAR_STMTS (node)[i]; imm_use_iterator imm_iter; @@ -2210,6 +2231,9 @@ vect_detect_hybrid_slp_stmts (slp_tree node, unsigned i, slp_vect_type stype) loop_vec_info loop_vinfo = STMT_VINFO_LOOP_VINFO (stmt_vinfo); int j; + if (visited.add (node)) + return; + /* Propagate hybrid down the SLP tree. */ if (stype == hybrid) ; @@ -2259,7 +2283,14 @@ vect_detect_hybrid_slp_stmts (slp_tree node, unsigned i, slp_vect_type stype) FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), j, child) if (SLP_TREE_DEF_TYPE (child) != vect_external_def) - vect_detect_hybrid_slp_stmts (child, i, stype); + vect_detect_hybrid_slp_stmts (child, i, stype, visited); +} + +static void +vect_detect_hybrid_slp_stmts (slp_tree node, unsigned i, slp_vect_type stype) +{ + hash_set visited; + vect_detect_hybrid_slp_stmts (node, i, stype, visited); } /* Helpers for vect_detect_hybrid_slp walking pattern stmt uses. */ @@ -2571,12 +2602,16 @@ vect_slp_analyze_operations (vec_info *vinfo) static void vect_bb_slp_scalar_cost (basic_block bb, slp_tree node, vec *life, - stmt_vector_for_cost *cost_vec) + stmt_vector_for_cost *cost_vec, + hash_set &visited) { unsigned i; stmt_vec_info stmt_info; slp_tree child; + if (visited.add (node)) + return; + FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) { gimple *stmt = stmt_info->stmt; @@ -2636,12 +2671,22 @@ vect_bb_slp_scalar_cost (basic_block bb, /* Do not directly pass LIFE to the recursive call, copy it to confine changes in the callee to the current child/subtree. */ subtree_life.safe_splice (*life); - vect_bb_slp_scalar_cost (bb, child, &subtree_life, cost_vec); + vect_bb_slp_scalar_cost (bb, child, &subtree_life, cost_vec, + visited); subtree_life.truncate (0); } } } +static void +vect_bb_slp_scalar_cost (basic_block bb, + slp_tree node, vec *life, + stmt_vector_for_cost *cost_vec) +{ + hash_set visited; + vect_bb_slp_scalar_cost (bb, node, life, cost_vec, visited); +} + /* Check if vectorization of the basic block is profitable. */ static bool @@ -3930,7 +3975,7 @@ vect_schedule_slp_instance (slp_tree node, slp_instance instance, SLP instances may refer to the same scalar stmt. */ static void -vect_remove_slp_scalar_calls (slp_tree node) +vect_remove_slp_scalar_calls (slp_tree node, hash_set &visited) { gimple *new_stmt; gimple_stmt_iterator gsi; @@ -3942,8 +3987,11 @@ vect_remove_slp_scalar_calls (slp_tree node) if (SLP_TREE_DEF_TYPE (node) != vect_internal_def) return; + if (visited.add (node)) + return; + FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child) - vect_remove_slp_scalar_calls (child); + vect_remove_slp_scalar_calls (child, visited); FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) { @@ -3961,6 +4009,13 @@ vect_remove_slp_scalar_calls (slp_tree node) } } +static void +vect_remove_slp_scalar_calls (slp_tree node) +{ + hash_set visited; + vect_remove_slp_scalar_calls (node, visited); +} + /* Generate vector code for all SLP instances in the loop/basic block. */ void