From patchwork Tue Aug 23 13:20:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 678 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp949122wro; Tue, 23 Aug 2022 06:21:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR61gGCPaX3mvtAp0q/apMUuvwH8rE7rU5vy/vQK4xInXCXA8kN0DMdq6m5rT3O26mFZMXoI X-Received: by 2002:a17:907:2d23:b0:730:acf0:4907 with SMTP id gs35-20020a1709072d2300b00730acf04907mr16942809ejc.700.1661260863737; Tue, 23 Aug 2022 06:21:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661260863; cv=none; d=google.com; s=arc-20160816; b=jBITq+xQzjP2ow35/hN2omkAZNZv6sSOYuH7lE9QBvvUt345XlOQalPP3KWFXViZNq ExQDH2zHniyibfb4JoaDWODkfwwKqxUTyOXphpiY+gZsu4CNC0xY+zucxzh40hBKg//N RloCDwGKgXJS7BkVsBnx2NNpQEhlzYJK5VVW2dcCflkzoUV3UopDRWf/dzHcGH+6QT6y ZJeImTPW1KGwihMxGl7MAbDmxg/XE49n0bho1T4/jxLlaKHj93dew1F5s2KiusfcEvRA TNQrCaine2LbxGBezKgl/bi6bKcYzQroTJ0rxeVTYpfZimUU4f9fVAulAkJHhVwtxX0T AD6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=FIzWR6MPZ9dzEjSlmxBa+gjx6BzPOZJBTtkPr7nYekQ=; b=zAY/q8kzscV1sZ24OCpPo5OTcB7ES21svZ9eI6tnmMhKFW/lsi1A5Y1cSjEanDxfm8 8Vg4tbxfXotEEYyOL5QBBogSq+QkTBCJcIHapSV2DQbB9VWlb41HBoBWBXDJab95YfhI q31XuI+UHV6wxP9x8o2QRJM+5ZGGIiTryA4MnEKnGVYXO0JUWe+IbAu6OE0pxi40DQgo 2j87AujVIsAJcv32uqOwgzKoliA8NNRtT2pHOBIFz2+BJpYiCOorR1K28YRZ0uEWP/JQ 6u+CijrvU26xZNZ08EPS6sLRgeNbirHnFlHc6uKaatj/rmUO2SjIKdce27U/9v0klt+R Id+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rGlLfF2b; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id t4-20020a508d44000000b00446ce49ddf6si2137298edt.96.2022.08.23.06.21.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 06:21:03 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rGlLfF2b; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 51B3E3853551 for ; Tue, 23 Aug 2022 13:21:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 51B3E3853551 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661260861; bh=FIzWR6MPZ9dzEjSlmxBa+gjx6BzPOZJBTtkPr7nYekQ=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=rGlLfF2bhN/LrezHkGM3hfeYzZTCqfPgiNloS5cWFy0qcF4D5+nrkOneSOqE+VoAk CsVK1d3w+f18gopUTaETIlIZFCQEbgggipkEBC3KCQN+eoTQosVBgyGChevNmARVH4 7D3hCTCwZnXTwxYU/TAhDbOGa1WYqFS/ZjKobCYg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id F41493858022 for ; Tue, 23 Aug 2022 13:20:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F41493858022 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id A0AEF337C7 for ; Tue, 23 Aug 2022 13:20:15 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 8F47E2C141 for ; Tue, 23 Aug 2022 13:20:15 +0000 (UTC) Date: Tue, 23 Aug 2022 13:20:15 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/106722 - uninit analysis with long def -> use path User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20220823132101.51B3E3853551@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1741958271251113545?= X-GMAIL-MSGID: =?utf-8?q?1741958271251113545?= The following applies similar measures as r13-2133-ge66cf626c72d58 to the computation of the use predicate when the path from PHI def to use is too long and we run into compute_control_dep_chain limits. It also moves the preprocessor define limits internal. This resolves the reduced testcase but not the original one. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/106722 * gimple-predicate-analysis.h (MAX_NUM_CHAINS, MAX_CHAIN_LEN, MAX_POSTDOM_CHECK, MAX_SWITCH_CASES): Move ... * gimple-predicate-analysis.cc: ... here and document. (simple_control_dep_chain): New function, factored from predicate::use_cannot_happen. (predicate::use_cannot_happen): Adjust. (predicate::predicate): Use simple_control_dep_chain as fallback. * g++.dg/uninit-pr106722-1.C: New testcase. --- gcc/gimple-predicate-analysis.cc | 68 ++++++++++++++++++------ gcc/gimple-predicate-analysis.h | 4 -- gcc/testsuite/g++.dg/uninit-pr106722-1.C | 65 ++++++++++++++++++++++ 3 files changed, 117 insertions(+), 20 deletions(-) create mode 100644 gcc/testsuite/g++.dg/uninit-pr106722-1.C diff --git a/gcc/gimple-predicate-analysis.cc b/gcc/gimple-predicate-analysis.cc index e8e2dbf7034..a4291657d0b 100644 --- a/gcc/gimple-predicate-analysis.cc +++ b/gcc/gimple-predicate-analysis.cc @@ -46,6 +46,19 @@ #define DEBUG_PREDICATE_ANALYZER 1 +/* In our predicate normal form we have MAX_NUM_CHAINS or predicates + and in those MAX_CHAIN_LEN (inverted) and predicates. */ +#define MAX_NUM_CHAINS 8 +#define MAX_CHAIN_LEN 5 + +/* When enumerating paths between two blocks this limits the number of + post-dominator skips between two edges possibly defining a predicate. */ +#define MAX_POSTDOM_CHECK 8 + +/* The limit for the number of switch cases when we do the linear search + for the case corresponding to an edge. */ +#define MAX_SWITCH_CASES 40 + /* Return true if, when BB1 is postdominating BB2, BB1 is a loop exit. */ static bool @@ -1034,6 +1047,36 @@ is_degenerate_phi (gimple *phi, pred_info *pred) return true; } +/* If compute_control_dep_chain bailed out due to limits this routine + tries to build a partial sparse path using dominators. Returns + path edges whose predicates are always true when reaching E. */ + +static void +simple_control_dep_chain (vec& chain, basic_block from, basic_block to) +{ + if (!dominated_by_p (CDI_DOMINATORS, to, from)) + return; + + basic_block src = to; + while (src != from + && chain.length () <= MAX_CHAIN_LEN) + { + basic_block dest = src; + src = get_immediate_dominator (CDI_DOMINATORS, src); + edge pred_e; + if (single_pred_p (dest) + && (pred_e = find_edge (src, dest))) + chain.safe_push (pred_e); + } +} + +static void +simple_control_dep_chain (vec& chain, basic_block from, edge to) +{ + chain.safe_push (to); + simple_control_dep_chain (chain, from, to->src); +} + /* Recursively compute the control dependence chains (paths of edges) from the dependent basic block, DEP_BB, up to the dominating basic block, DOM_BB (the head node of a chain should be dominated by it), @@ -1273,20 +1316,8 @@ predicate::use_cannot_happen (gphi *phi, unsigned opnds) /* If compute_control_dep_chain bailed out due to limits build a partial sparse path using dominators. Collect only edges whose predicates are always true when reaching E. */ - cur_chain.truncate (0); - cur_chain.quick_push (e); - basic_block src = e->src; - while (src->index != ENTRY_BLOCK - && cur_chain.length () <= MAX_CHAIN_LEN) - { - basic_block dest = src; - src = get_immediate_dominator (CDI_DOMINATORS, src); - edge pred_e; - if (single_pred_p (dest) - && (pred_e = find_edge (src, dest))) - cur_chain.quick_push (pred_e); - } - dep_chains[0] = cur_chain.copy (); + simple_control_dep_chain (dep_chains[0], + ENTRY_BLOCK_PTR_FOR_FN (cfun), e); num_chains++; } @@ -1737,8 +1768,13 @@ predicate::predicate (basic_block def_bb, basic_block use_bb, func_t &eval) auto_vec dep_chains[MAX_NUM_CHAINS]; auto_vec cur_chain; - compute_control_dep_chain (cd_root, use_bb, dep_chains, &num_chains, - cur_chain, &num_calls); + if (!compute_control_dep_chain (cd_root, use_bb, dep_chains, &num_chains, + cur_chain, &num_calls)) + { + gcc_assert (num_chains == 0); + simple_control_dep_chain (dep_chains[0], cd_root, use_bb); + num_chains++; + } if (DEBUG_PREDICATE_ANALYZER && dump_file) { diff --git a/gcc/gimple-predicate-analysis.h b/gcc/gimple-predicate-analysis.h index 204cdbccfc7..77672291c36 100644 --- a/gcc/gimple-predicate-analysis.h +++ b/gcc/gimple-predicate-analysis.h @@ -22,10 +22,6 @@ #ifndef GIMPLE_PREDICATE_ANALYSIS_H_INCLUDED #define GIMPLE_PREDICATE_ANALYSIS_H_INCLUDED -#define MAX_NUM_CHAINS 8 -#define MAX_CHAIN_LEN 5 -#define MAX_POSTDOM_CHECK 8 -#define MAX_SWITCH_CASES 40 /* Represents a simple Boolean predicate. */ struct pred_info diff --git a/gcc/testsuite/g++.dg/uninit-pr106722-1.C b/gcc/testsuite/g++.dg/uninit-pr106722-1.C new file mode 100644 index 00000000000..a10f8dd88c7 --- /dev/null +++ b/gcc/testsuite/g++.dg/uninit-pr106722-1.C @@ -0,0 +1,65 @@ +// { dg-do compile } +// { dg-require-effective-target c++11 } +// { dg-options "-O2 -Wmaybe-uninitialized --param logical-op-non-short-circuit=0" } +long pow2p_hwi_x; +bool exact_log2___trans_tmp_5, exact_log2___trans_tmp_4; +int exact_log2(long x) { + exact_log2___trans_tmp_5 = pow2p_hwi_x && exact_log2___trans_tmp_4; + return exact_log2___trans_tmp_5 ? x : 1; +} +enum signop {}; +template void rshift(T1, T2, signop); +struct generic_wide_int { + template generic_wide_int(T); +}; +template struct poly_int_pod { + bool is_constant() const; + template bool is_constant(T *) const; + int coeffs[N]; +}; +template +template +bool poly_int_pod::is_constant(T *const_value) const { + if (is_constant()) { + *const_value = coeffs[0]; + return true; + } + return false; +} +struct poly_int : poly_int_pod<1, int> { + template poly_int(C0); +}; +enum tree_code_class {} tree_code_type; +void tree_class_check_failed(int *, tree_code_class, char *, int, char *) + __attribute__((__noreturn__)); +int tree_class_check___t, tree_class_check___l, + vect_gen_vector_loop_niters_loop_vinfo; +char tree_class_check___f, tree_class_check___g; +tree_code_class tree_class_check___class; +int *tree_class_check() { + if (tree_code_type) + tree_class_check_failed(&tree_class_check___t, tree_class_check___class, + &tree_class_check___f, tree_class_check___l, + &tree_class_check___g); + return &tree_class_check___t; +} +int *build_int_cst(int, long); +bool is_gimple_val(int); +void force_gimple_operand(int, int *, bool, int); +void vect_gen_vector_loop_niters(bool niters_no_overflow) { + poly_int vf(vect_gen_vector_loop_niters_loop_vinfo); + int *log_vf = nullptr; + long const_vf; + if (vf.is_constant(&const_vf)) + log_vf = build_int_cst(0, 0); + if (is_gimple_val(0)) { + int stmts; + force_gimple_operand(0, &stmts, true, 0); + if (stmts && log_vf) + if (niters_no_overflow) { + generic_wide_int __trans_tmp_1(tree_class_check()); + int __trans_tmp_2 = exact_log2(const_vf); // { dg-bogus "uninitialized" } + rshift(__trans_tmp_1, __trans_tmp_2, (signop)0); + } + } +}