From patchwork Thu May 11 05:12:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "juzhe.zhong@rivai.ai" X-Patchwork-Id: 92355 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4118453vqo; Wed, 10 May 2023 22:13:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5dnszC5s032bHcBSfu6S4wrn6nrhGztSgW+NEpjpAKk6xT6YxENJA766rWyHlA97R9ZuLk X-Received: by 2002:a05:6402:203:b0:50b:e015:71c3 with SMTP id t3-20020a056402020300b0050be01571c3mr16136666edv.25.1683782015164; Wed, 10 May 2023 22:13:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683782015; cv=none; d=google.com; s=arc-20160816; b=B3+yvOMVvSe6tgB6/Og6pTIqUJ2Fm5Q9iSXfYfrBmoougCTHFmRQJRYdvJpEgP40+I qhiQguU722b2L1r+7lSFQOmO5oej6EbR0NWTxNiDxo069V8vpnZWZWwn7RhybZ9CR1YQ dXOJK1FW1L81XM5s0HMU6/CzQjN5gTbS2zMoScpgorJCBnUqNHRNz3xXAc6N/YlMYQ0m suJgf1APXNXnM2p891os1Slj4zpOElsPcnsnqeNRcnnHKfWnVRo1KsGe07aDkLvCAFos AqXoDCpUjtEeRrdoHYebFMARdEDVOVH3HK1uqbLgHGdfpD6MWIa4D8XGONQRND8WJNb1 RQjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:feedback-id :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dmarc-filter:delivered-to; bh=NsRVPSeWwvMhAPX8uJKO4AN/owb9PAHM+sffuXe7XYc=; b=vGs38DrCZ/30jP2INqsodU5u6D48BOV6fX+HBqBJQcTBoTAyfSqrfug5nfc7K4Gqam bcAVGu/NpTatiw8nMKkGrY1OhZ+8o2zpZFLfBT8NUkWiXPktaLPDemVsAH2fI1Vl8GhL rN1BheF/JnM/vVZyp5b2u+pTSRO90EiFavWQFhYa0Ft2RMRf165Kr31TyV55ANX19Hiw D9yJFKjnUrjQrOSF2NKbYwnE9l0gj3meinJqODPB6fOrg3xUzR+57TDdLtS/wjoiET5R F5GGmQRbIbHSLWSwbHPVLvYOACF6hXrLjmCKxmRpoK1e1jhgxCVhU8QonmjeknmN9WDA kbEQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u18-20020aa7d0d2000000b0050bfbf2093bsi1548677edo.238.2023.05.10.22.13.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 22:13:35 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 113DC3856972 for ; Thu, 11 May 2023 05:13:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbg154.qq.com (smtpbg154.qq.com [15.184.224.54]) by sourceware.org (Postfix) with ESMTPS id 887953858D33 for ; Thu, 11 May 2023 05:12:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 887953858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai X-QQ-mid: bizesmtp77t1683781966txznxxy6 Received: from rios-cad5.localdomain ( [58.60.1.11]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 11 May 2023 13:12:45 +0800 (CST) X-QQ-SSF: 01400000000000F0Q000000A0000000 X-QQ-FEAT: k0mQ4ihyJQNoc0Krk5wyAfHzC4e4K3fz9xdG01LuLeBXlnf2tLc+iJhMDUMRx bkWCiy3QhUc7wuzrxEu65gVDADfa9YQXHAXd/Hmjycb6ntmjlKyAtXxHKQ4+lqjJaNwB5U0 TDddQQyJXoZFiyIiOmL6+a78w91wpvCxKv5TUumMcR1A0wa8WOYsXkkF2aJ+Zyo/h7AY3i2 z1fYHPzBQNxkKYJZQLlgQDPl3JI9AhJZPB5PSnGGuNs7GfVpwYI3S3LW/aCXNLVTDXSVjSz 5yPMh51h3xehZEUqu6LnfiLJlsheSdVNTsRlEAhhAbyXCwOmoyMCy3w1/5Awdd0Y4FiSbk4 1OOAe0VnuCpIT+4++x1+naUdQbl1m6gfQeJ72VoRTZD1a7fi8sl0DGItnnvNypm/fsOoUNm ZcwBJPOMYSA= X-QQ-GoodBg: 2 X-BIZMAIL-ID: 1399404257634165025 From: juzhe.zhong@rivai.ai To: gcc-patches@gcc.gnu.org Cc: richard.sandiford@arm.com, rguenther@suse.de, Juzhe-Zhong Subject: [PATCH V5] VECT: Add tree_code into "creat_iv" and allow it can handle MINUS_EXPR IV. Date: Thu, 11 May 2023 13:12:44 +0800 Message-Id: <20230511051244.1068441-1-juzhe.zhong@rivai.ai> X-Mailer: git-send-email 2.36.3 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz7a-one-0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765573410390244718?= X-GMAIL-MSGID: =?utf-8?q?1765573410390244718?= From: Juzhe-Zhong This is patch is a seperate patch preparing for supporting decrement IV. gcc/ChangeLog: * cfgloopmanip.cc (create_empty_loop_on_edge): Add PLUS_EXPR. * gimple-loop-interchange.cc (tree_loop_interchange::map_inductions_to_loop): Ditto. * tree-ssa-loop-ivcanon.cc (create_canonical_iv): Ditto. * tree-ssa-loop-ivopts.cc (create_new_iv): Ditto. * tree-ssa-loop-manip.cc (create_iv): Ditto. (tree_transform_and_unroll_loop): Ditto. (canonicalize_loop_ivs): Ditto. * tree-ssa-loop-manip.h (create_iv): Ditto. * tree-vect-data-refs.cc (vect_create_data_ref_ptr): Ditto. * tree-vect-loop-manip.cc (vect_set_loop_controls_directly): Ditto. (vect_set_loop_condition_normal): Ditto. * tree-vect-loop.cc (vect_create_epilog_for_reduction): Ditto. * tree-vect-stmts.cc (vectorizable_store): Ditto. (vectorizable_load): Ditto. --- gcc/cfgloopmanip.cc | 2 +- gcc/gimple-loop-interchange.cc | 2 +- gcc/tree-ssa-loop-ivcanon.cc | 2 +- gcc/tree-ssa-loop-ivopts.cc | 2 +- gcc/tree-ssa-loop-manip.cc | 18 +++++++++--------- gcc/tree-ssa-loop-manip.h | 4 ++-- gcc/tree-vect-data-refs.cc | 8 ++++---- gcc/tree-vect-loop-manip.cc | 7 ++++--- gcc/tree-vect-loop.cc | 2 +- gcc/tree-vect-stmts.cc | 4 ++-- 10 files changed, 26 insertions(+), 25 deletions(-) diff --git a/gcc/cfgloopmanip.cc b/gcc/cfgloopmanip.cc index 0e3ad8ed742..6e09dcbb0b1 100644 --- a/gcc/cfgloopmanip.cc +++ b/gcc/cfgloopmanip.cc @@ -826,7 +826,7 @@ create_empty_loop_on_edge (edge entry_edge, } gsi = gsi_last_bb (loop_header); - create_iv (initial_value, stride, iv, loop, &gsi, false, + create_iv (initial_value, PLUS_EXPR, stride, iv, loop, &gsi, false, iv_before, iv_after); /* Insert loop exit condition. */ diff --git a/gcc/gimple-loop-interchange.cc b/gcc/gimple-loop-interchange.cc index 1b77bfd46b2..e5590374e59 100644 --- a/gcc/gimple-loop-interchange.cc +++ b/gcc/gimple-loop-interchange.cc @@ -1185,7 +1185,7 @@ tree_loop_interchange::map_inductions_to_loop (loop_cand &src, loop_cand &tgt) tree var_before, var_after; tree base = unshare_expr (iv->init_expr); tree step = unshare_expr (iv->step); - create_iv (base, step, SSA_NAME_VAR (iv->var), + create_iv (base, PLUS_EXPR, step, SSA_NAME_VAR (iv->var), tgt.m_loop, &incr_pos, false, &var_before, &var_after); bitmap_set_bit (m_dce_seeds, SSA_NAME_VERSION (var_before)); bitmap_set_bit (m_dce_seeds, SSA_NAME_VERSION (var_after)); diff --git a/gcc/tree-ssa-loop-ivcanon.cc b/gcc/tree-ssa-loop-ivcanon.cc index f678de41cb0..6a962a9f503 100644 --- a/gcc/tree-ssa-loop-ivcanon.cc +++ b/gcc/tree-ssa-loop-ivcanon.cc @@ -113,7 +113,7 @@ create_canonical_iv (class loop *loop, edge exit, tree niter, niter, build_int_cst (type, 1)); incr_at = gsi_last_bb (in->src); - create_iv (niter, + create_iv (niter, PLUS_EXPR, build_int_cst (type, -1), NULL_TREE, loop, &incr_at, false, var_before, &var); diff --git a/gcc/tree-ssa-loop-ivopts.cc b/gcc/tree-ssa-loop-ivopts.cc index 324703054b5..6fbd2d59318 100644 --- a/gcc/tree-ssa-loop-ivopts.cc +++ b/gcc/tree-ssa-loop-ivopts.cc @@ -7267,7 +7267,7 @@ create_new_iv (struct ivopts_data *data, struct iv_cand *cand) base = unshare_expr (cand->iv->base); - create_iv (base, unshare_expr (cand->iv->step), + create_iv (base, PLUS_EXPR, unshare_expr (cand->iv->step), cand->var_before, data->current_loop, &incr_pos, after, &cand->var_before, &cand->var_after); } diff --git a/gcc/tree-ssa-loop-manip.cc b/gcc/tree-ssa-loop-manip.cc index 598e2189f6c..4a333ddf9e6 100644 --- a/gcc/tree-ssa-loop-manip.cc +++ b/gcc/tree-ssa-loop-manip.cc @@ -57,16 +57,16 @@ static bitmap_obstack loop_renamer_obstack; VAR_AFTER (unless they are NULL). */ void -create_iv (tree base, tree step, tree var, class loop *loop, - gimple_stmt_iterator *incr_pos, bool after, - tree *var_before, tree *var_after) +create_iv (tree base, tree_code incr_op, tree step, tree var, class loop *loop, + gimple_stmt_iterator *incr_pos, bool after, tree *var_before, + tree *var_after) { gassign *stmt; gphi *phi; tree initial, step1; gimple_seq stmts; tree vb, va; - enum tree_code incr_op = PLUS_EXPR; + gcc_assert (incr_op == PLUS_EXPR || incr_op == MINUS_EXPR); edge pe = loop_preheader_edge (loop); if (var != NULL_TREE) @@ -93,7 +93,7 @@ create_iv (tree base, tree step, tree var, class loop *loop, step1 = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step); if (tree_int_cst_lt (step1, step)) { - incr_op = MINUS_EXPR; + incr_op = (incr_op == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR); step = step1; } } @@ -104,7 +104,7 @@ create_iv (tree base, tree step, tree var, class loop *loop, if (!tree_expr_nonnegative_warnv_p (step, &ovf) && may_negate_without_overflow_p (step)) { - incr_op = MINUS_EXPR; + incr_op = (incr_op == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR); step = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step); } } @@ -1365,7 +1365,7 @@ tree_transform_and_unroll_loop (class loop *loop, unsigned factor, tree ctr_before, ctr_after; gimple_stmt_iterator bsi = gsi_last_nondebug_bb (new_exit->src); exit_if = as_a (gsi_stmt (bsi)); - create_iv (exit_base, exit_step, NULL_TREE, loop, + create_iv (exit_base, PLUS_EXPR, exit_step, NULL_TREE, loop, &bsi, false, &ctr_before, &ctr_after); gimple_cond_set_code (exit_if, exit_cmp); gimple_cond_set_lhs (exit_if, ctr_after); @@ -1580,8 +1580,8 @@ canonicalize_loop_ivs (class loop *loop, tree *nit, bool bump_in_latch) gsi = gsi_last_bb (loop->latch); else gsi = gsi_last_nondebug_bb (loop->header); - create_iv (build_int_cst_type (type, 0), build_int_cst (type, 1), NULL_TREE, - loop, &gsi, bump_in_latch, &var_before, NULL); + create_iv (build_int_cst_type (type, 0), PLUS_EXPR, build_int_cst (type, 1), + NULL_TREE, loop, &gsi, bump_in_latch, &var_before, NULL); rewrite_all_phi_nodes_with_iv (loop, var_before); diff --git a/gcc/tree-ssa-loop-manip.h b/gcc/tree-ssa-loop-manip.h index d49273a3987..bda09f51d56 100644 --- a/gcc/tree-ssa-loop-manip.h +++ b/gcc/tree-ssa-loop-manip.h @@ -22,8 +22,8 @@ along with GCC; see the file COPYING3. If not see typedef void (*transform_callback)(class loop *, void *); -extern void create_iv (tree, tree, tree, class loop *, gimple_stmt_iterator *, - bool, tree *, tree *); +extern void create_iv (tree, tree_code, tree, tree, class loop *, + gimple_stmt_iterator *, bool, tree *, tree *); extern void rewrite_into_loop_closed_ssa (bitmap, unsigned); extern void verify_loop_closed_ssa (bool, class loop * = NULL); diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc index 6721ab6efc4..5c9103b16e5 100644 --- a/gcc/tree-vect-data-refs.cc +++ b/gcc/tree-vect-data-refs.cc @@ -5099,7 +5099,7 @@ vect_create_data_ref_ptr (vec_info *vinfo, stmt_vec_info stmt_info, standard_iv_increment_position (loop, &incr_gsi, &insert_after); - create_iv (aggr_ptr_init, + create_iv (aggr_ptr_init, PLUS_EXPR, fold_convert (aggr_ptr_type, iv_step), aggr_ptr, loop, &incr_gsi, insert_after, &indx_before_incr, &indx_after_incr); @@ -5129,9 +5129,9 @@ vect_create_data_ref_ptr (vec_info *vinfo, stmt_vec_info stmt_info, { standard_iv_increment_position (containing_loop, &incr_gsi, &insert_after); - create_iv (aptr, fold_convert (aggr_ptr_type, DR_STEP (dr)), aggr_ptr, - containing_loop, &incr_gsi, insert_after, &indx_before_incr, - &indx_after_incr); + create_iv (aptr, PLUS_EXPR, fold_convert (aggr_ptr_type, DR_STEP (dr)), + aggr_ptr, containing_loop, &incr_gsi, insert_after, + &indx_before_incr, &indx_after_incr); incr = gsi_stmt (incr_gsi); /* Copy the points-to information if it exists. */ diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc index 44bd5f2c805..ff6159e08d5 100644 --- a/gcc/tree-vect-loop-manip.cc +++ b/gcc/tree-vect-loop-manip.cc @@ -468,8 +468,9 @@ vect_set_loop_controls_directly (class loop *loop, loop_vec_info loop_vinfo, gimple_stmt_iterator incr_gsi; bool insert_after; standard_iv_increment_position (loop, &incr_gsi, &insert_after); - create_iv (build_int_cst (iv_type, 0), nitems_step, NULL_TREE, loop, - &incr_gsi, insert_after, &index_before_incr, &index_after_incr); + create_iv (build_int_cst (iv_type, 0), PLUS_EXPR, nitems_step, NULL_TREE, + loop, &incr_gsi, insert_after, &index_before_incr, + &index_after_incr); tree zero_index = build_int_cst (compare_type, 0); tree test_index, test_limit, first_limit; @@ -893,7 +894,7 @@ vect_set_loop_condition_normal (class loop *loop, tree niters, tree step, } standard_iv_increment_position (loop, &incr_gsi, &insert_after); - create_iv (init, step, NULL_TREE, loop, + create_iv (init, PLUS_EXPR, step, NULL_TREE, loop, &incr_gsi, insert_after, &indx_before_incr, &indx_after_incr); indx_after_incr = force_gimple_operand_gsi (&loop_cond_gsi, indx_after_incr, true, NULL_TREE, true, diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 6ea0f21fd13..ed0166fedab 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -5567,7 +5567,7 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo, gimple_stmt_iterator incr_gsi; bool insert_after; standard_iv_increment_position (loop, &incr_gsi, &insert_after); - create_iv (series_vect, vec_step, NULL_TREE, loop, &incr_gsi, + create_iv (series_vect, PLUS_EXPR, vec_step, NULL_TREE, loop, &incr_gsi, insert_after, &indx_before_incr, &indx_after_incr); /* Next create a new phi node vector (NEW_PHI_TREE) which starts diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index 61a2da4ecee..7313191b0db 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -8286,7 +8286,7 @@ vectorizable_store (vec_info *vinfo, stride_base = cse_and_gimplify_to_preheader (loop_vinfo, stride_base); ivstep = cse_and_gimplify_to_preheader (loop_vinfo, ivstep); - create_iv (stride_base, ivstep, NULL, + create_iv (stride_base, PLUS_EXPR, ivstep, NULL, loop, &incr_gsi, insert_after, &offvar, NULL); incr = gsi_stmt (incr_gsi); @@ -9457,7 +9457,7 @@ vectorizable_load (vec_info *vinfo, stride_base = cse_and_gimplify_to_preheader (loop_vinfo, stride_base); ivstep = cse_and_gimplify_to_preheader (loop_vinfo, ivstep); - create_iv (stride_base, ivstep, NULL, + create_iv (stride_base, PLUS_EXPR, ivstep, NULL, loop, &incr_gsi, insert_after, &offvar, NULL);