From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2066) id C86783858C27; Mon, 31 May 2021 05:56:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C86783858C27 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jiu Fu Guo To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/guojiufu/heads/personal-branch)] using number_of_iterations_exit to check wrap/overflow X-Act-Checkin: gcc X-Git-Author: Jiufu Guo X-Git-Refname: refs/users/guojiufu/heads/personal-branch X-Git-Oldrev: d5538d2073f7b17289b3ac65dce122904b67b5d9 X-Git-Newrev: 0ed4c5d27ef0fb6e27046a749754752c9b27f2a4 Message-Id: <20210531055628.C86783858C27@sourceware.org> Date: Mon, 31 May 2021 05:56:28 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 May 2021 05:56:28 -0000 https://gcc.gnu.org/g:0ed4c5d27ef0fb6e27046a749754752c9b27f2a4 commit 0ed4c5d27ef0fb6e27046a749754752c9b27f2a4 Author: Jiufu Guo Date: Fri May 14 23:33:57 2021 +0800 using number_of_iterations_exit to check wrap/overflow Diff: --- gcc/tree-ssa-loop-split.c | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/gcc/tree-ssa-loop-split.c b/gcc/tree-ssa-loop-split.c index 425593ca70f..6ae36635d6b 100644 --- a/gcc/tree-ssa-loop-split.c +++ b/gcc/tree-ssa-loop-split.c @@ -1629,43 +1629,15 @@ get_ne_cond_branch (struct loop *loop) else if (!expr_invariant_in_loop_p (loop, bnd)) continue; - /* By default, unsigned type conversion could cause overflow. */ - tree type = TREE_TYPE (idx); - if (!INTEGRAL_TYPE_P (type) || TREE_CODE (idx) != SSA_NAME - || !TYPE_UNSIGNED (type) - || TYPE_PRECISION (type) == TYPE_PRECISION (sizetype)) + /* If no overflow/wrap happen, no need to split. */ + if (nowrap_type_p (TREE_TYPE (idx))) continue; - - /* Avoid to split if bound is MAX/MIN val. */ - tree bound_type = TREE_TYPE (bnd); - if (TREE_CODE (bnd) == INTEGER_CST && INTEGRAL_TYPE_P (bound_type) - && (bnd == TYPE_MAX_VALUE (bound_type) - || bnd == TYPE_MIN_VALUE (bound_type))) - continue; - - /* Extract conversion from idx. */ - if (TREE_CODE (idx) == SSA_NAME) - { - gimple *stmt = SSA_NAME_DEF_STMT (idx); - if (is_gimple_assign (stmt) - && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt)) - && flow_bb_inside_loop_p (loop, gimple_bb (stmt))) - idx = gimple_assign_rhs1 (stmt); - } - - /* Check if idx is simple iv with possible overflow/wrap. */ - class loop *useloop = loop_containing_stmt (cond); - affine_iv iv; - if (!simple_iv (loop, useloop, idx, &iv, false)) + class tree_niter_desc niter; + if (!number_of_iterations_exit (loop, e, &niter, false, false, NULL)) continue; - if (iv.no_overflow) + if (niter.control.no_overflow) return NULL; - /* If base is know value (esplically 0/1), other optimizations may be - able to analyze "idx != bnd" as "idx < bnd" or "idx > bnd". */ - if (TREE_CODE (iv.base) == INTEGER_CST) - continue; - /* Check loop is simple to split. */ gcc_assert (bb != loop->latch);