From patchwork Mon Oct 29 13:46:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 990231 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-488514-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="YwlmCssU"; 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 42kGB54Lrkz9s7W for ; Tue, 30 Oct 2018 00:47:25 +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=Gm1J2rEMKFZ6dyw95b36Zn+r7DPgc5ZZkut1xxs+zd6qjaUduhCyS pwXu0X8jEaMOxiw5mtg01WaPxriTokxc+5ZlXkRYMA/vMiXrvhnKT7J4E0KGI9wI 7WEWLGK3JvJSg0jlJ2rrPIKw+lfeZ6VcU7DYl0ZfeOB29NOTFFW+uo= 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=/HXNrtspMG8QpPIQRK8ZkD9/CpQ=; b=YwlmCssUVWytyBTO4+rN IOASlBppsOYDtiNpYgBa5YvOzcxU2h1boVPLt6dnXceIGOBroCdSTjaD0E/7yteY fdJIUuQktYgLcrYmQ1UTmAAbSiXBFKhcIwYvChsd5AF3QUjdsAJKZXcL2e3M0BHg 3rScRLWGT42e5ztRsu7XElY= Received: (qmail 114242 invoked by alias); 29 Oct 2018 13:46:39 -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 108415 invoked by uid 89); 29 Oct 2018 13:46:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:vect_pr, refcnt, rooted, edges 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, 29 Oct 2018 13:46:30 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 20AF8AD4A for ; Mon, 29 Oct 2018 13:46:28 +0000 (UTC) Date: Mon, 29 Oct 2018 14:46:28 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR87790 Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 When fixing compile-time issues with the SLP graph processing I failed to recognize that vect_detect_hybrid_slp_stmts needs to union info over graph edges and thus a simple visited flag doesn't do the trick. The following instead makes sure we propagate to children only after we have visited all incoming edges. Bootstrap & regtest running on x86_64-unknown-linux-gnu. Richard. 2018-10-29 Richard Biener PR tree-optimization/87790 * tree-vect-slp.c (vect_mark_slp_stmts): Simplify. (vect_make_slp_decision): Adjust. (vect_slp_analyze_bb_1): Likewise. (vect_detect_hybrid_slp_stmts): Properly union SLP type over edges. diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c index 5b925be80f4..a1db0dfde86 100644 --- a/gcc/tree-vect-slp.c +++ b/gcc/tree-vect-slp.c @@ -1477,14 +1469,10 @@ vect_print_slp_tree (dump_flags_t dump_kind, dump_location_t loc, vect_print_slp_tree (dump_kind, loc, node, visited); } -/* Mark the tree rooted at NODE with MARK (PURE_SLP or HYBRID). - If MARK is HYBRID, it refers to a specific stmt in NODE (the stmt at index - J). Otherwise, MARK is PURE_SLP and J is -1, which indicates that all the - stmts in NODE are to be marked. */ +/* Mark the tree rooted at NODE with PURE_SLP. */ static void -vect_mark_slp_stmts (slp_tree node, enum slp_vect_type mark, int j, - hash_set &visited) +vect_mark_slp_stmts (slp_tree node, hash_set &visited) { int i; stmt_vec_info stmt_info; @@ -1497,18 +1485,17 @@ vect_mark_slp_stmts (slp_tree node, enum slp_vect_type mark, int j, return; FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) - if (j < 0 || i == j) - STMT_SLP_TYPE (stmt_info) = mark; + STMT_SLP_TYPE (stmt_info) = pure_slp; FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child) - vect_mark_slp_stmts (child, mark, j, visited); + vect_mark_slp_stmts (child, visited); } static void -vect_mark_slp_stmts (slp_tree node, enum slp_vect_type mark, int j) +vect_mark_slp_stmts (slp_tree node) { hash_set visited; - vect_mark_slp_stmts (node, mark, j, visited); + vect_mark_slp_stmts (node, visited); } /* Mark the statements of the tree rooted at NODE as relevant (vect_used). */ @@ -2197,7 +2211,7 @@ vect_make_slp_decision (loop_vec_info loop_vinfo) /* Mark all the stmts that belong to INSTANCE as PURE_SLP stmts. Later we call vect_detect_hybrid_slp () to find stmts that need hybrid SLP and loop-based vectorization. Such stmts will be marked as HYBRID. */ - vect_mark_slp_stmts (SLP_INSTANCE_TREE (instance), pure_slp, -1); + vect_mark_slp_stmts (SLP_INSTANCE_TREE (instance)); decided_to_slp++; } @@ -2221,7 +2235,7 @@ vect_make_slp_decision (loop_vec_info loop_vinfo) static void vect_detect_hybrid_slp_stmts (slp_tree node, unsigned i, slp_vect_type stype, - hash_set &visited) + hash_map &visited) { stmt_vec_info stmt_vinfo = SLP_TREE_SCALAR_STMTS (node)[i]; imm_use_iterator imm_iter; @@ -2231,15 +2245,16 @@ 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; + /* We need to union stype over the incoming graph edges but we still + want to limit recursion to stay O(N+E). */ + bool only_edge = (++visited.get_or_insert (node) < node->refcnt); /* Propagate hybrid down the SLP tree. */ if (stype == hybrid) ; else if (HYBRID_SLP_STMT (stmt_vinfo)) stype = hybrid; - else + else if (!only_edge) { /* Check if a pure SLP stmt has uses in non-SLP stmts. */ gcc_checking_assert (PURE_SLP_STMT (stmt_vinfo)); @@ -2281,15 +2296,16 @@ vect_detect_hybrid_slp_stmts (slp_tree node, unsigned i, slp_vect_type stype, STMT_SLP_TYPE (stmt_vinfo) = hybrid; } - 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, visited); + if (!only_edge) + 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, visited); } static void vect_detect_hybrid_slp_stmts (slp_tree node, unsigned i, slp_vect_type stype) { - hash_set visited; + hash_map visited; vect_detect_hybrid_slp_stmts (node, i, stype, visited); } @@ -2875,7 +2891,7 @@ vect_slp_analyze_bb_1 (gimple_stmt_iterator region_begin, /* Mark all the statements that we want to vectorize as pure SLP and relevant. */ - vect_mark_slp_stmts (SLP_INSTANCE_TREE (instance), pure_slp, -1); + vect_mark_slp_stmts (SLP_INSTANCE_TREE (instance)); vect_mark_slp_stmts_relevant (SLP_INSTANCE_TREE (instance)); i++; Index: gcc/testsuite/gcc.dg/pr87790.c =================================================================== --- gcc/testsuite/gcc.dg/pr87790.c (nonexistent) +++ gcc/testsuite/gcc.dg/pr87790.c (working copy) @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-require-profiling "-fprofile-generate" } */ +/* { dg-options "-Ofast -fprofile-generate" } */ +/* { dg-additional-options "-march=znver1" { target { x86_64-*-* i?86-*-* } } } */ + +int a, b; +void c(int d[][8]) +{ + int e, f; + for (; b; b++) { + e = d[b][0] % 4 * 21; + if (e >= 21) + e--; + a = d[b][0] - e; + f = 1; + for (; f != 8; f++) + d[b][f] = a; + } +}