[tree-ssa-loop] Remove redundant check for number of loops in pass_vectorize::execute
Message ID | CAAgBjMmv2vNwB+BL+UXD7W8JWiXJ8dmyx7Ds_3dFm2wTaxX68A@mail.gmail.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 21177385800F for <patchwork@sourceware.org>; Mon, 8 Nov 2021 11:06:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 21177385800F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636369570; bh=LLP62wikYKNJx422vX3hQDiUo2sbyWQGNpqulGej9Uk=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=hoBH3HhpO7w5NAlZN7NOc/N/gcYpNNiTaAeYYZaSgH+KfFlIdzp4mTke6P7IZ3I65 66r+zkJut6a61YW2zdnfuz4UPViE+uW95zIBlpml+FIfl49W8xMqi1DQq2LOl0TM2U 6pvbjKurBJa6x+tkQUoT4DDwUjdn+BQY8WQD5lbY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 9245D3858401 for <gcc-patches@gcc.gnu.org>; Mon, 8 Nov 2021 11:05:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9245D3858401 Received: by mail-ed1-x52b.google.com with SMTP id g14so60216472edz.2 for <gcc-patches@gcc.gnu.org>; Mon, 08 Nov 2021 03:05:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=LLP62wikYKNJx422vX3hQDiUo2sbyWQGNpqulGej9Uk=; b=BNpTVVVKPBXJHVnj+nHgHz5PjsgRhIOt5n0jsQFlrwJZ2pr2lGNGoLJ6aggY6DX4Hz GLvxQQM5FsDH7GOOVxD4wCWIyoRYDafmSJyQVHFQg1X3sVFHBkCE5LrIDxmV1k/uCyyf umCTDkH67bOZbxHcjuwphkCOvgwlFTMBLdCd1r42LlAK2pC1ABmFtnaBEYc+JKP5OjnV Sf+9ng0RQ6UIRkzb01rXN5cCj3qQXyo/QAiHZ/rxnR6X2Ze0ajMqsV6c3AIvXa7WIRbY TX6qiWPB87jTIeeeX53Yf1KAMo/hXAqrMFwGfc1hxB35yrOYd8TpV2rqpCPxAzbK5X4U 0zTQ== X-Gm-Message-State: AOAM532GopQmgMU+bAfjIoSNWc0H5awUawGvnGVay+BnyuByK8wNGOlH HQ4jzWWfk/lGds2/6C/JVbkN8xg0TRGf87W6PjkfUITPw/IR6A== X-Google-Smtp-Source: ABdhPJx+wGIerwj9Xz9WKobKsY1Mr71LYtvud0RGaJ6MPp/ETfC3b86rp1So9eAji7ruIQ7WevsIrx5YsvCTvZ3/16o= X-Received: by 2002:a05:6402:5190:: with SMTP id q16mr68158123edd.12.1636369539290; Mon, 08 Nov 2021 03:05:39 -0800 (PST) MIME-Version: 1.0 Date: Mon, 8 Nov 2021 16:35:04 +0530 Message-ID: <CAAgBjMmv2vNwB+BL+UXD7W8JWiXJ8dmyx7Ds_3dFm2wTaxX68A@mail.gmail.com> Subject: [tree-ssa-loop] Remove redundant check for number of loops in pass_vectorize::execute To: gcc Patches <gcc-patches@gcc.gnu.org> Content-Type: multipart/mixed; boundary="0000000000001ca38b05d044f9eb" X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Prathamesh Kulkarni via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
[tree-ssa-loop] Remove redundant check for number of loops in pass_vectorize::execute
|
|
Commit Message
Prathamesh Kulkarni
Nov. 8, 2021, 11:05 a.m. UTC
Hi, The attached patch removes redundant check for number of loops in pass_vectorize::execute, since it only calls vectorize_loops, and in vectorize_loops, we immediately bail out if no loops are present: vect_loops_num = number_of_loops (cfun); /* Bail out if there are no loops. */ if (vect_loops_num <= 1) return 0; Is the patch OK to commit ? Thanks, Prathamesh
Comments
On Mon, Nov 8, 2021 at 12:06 PM Prathamesh Kulkarni via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > Hi, > The attached patch removes redundant check for number of loops in > pass_vectorize::execute, > since it only calls vectorize_loops, and in vectorize_loops, we > immediately bail out if no loops are present: > vect_loops_num = number_of_loops (cfun); > /* Bail out if there are no loops. */ > if (vect_loops_num <= 1) > return 0; > > Is the patch OK to commit ? Can you please merge both functions then, keeping only pass_vectorize::execute (and replacing 'cfun' occurrences by 'fun' as passed as argument)? Thanks, Richard. > > Thanks, > Prathamesh
On Mon, 8 Nov 2021 at 16:42, Richard Biener <richard.guenther@gmail.com> wrote: > > On Mon, Nov 8, 2021 at 12:06 PM Prathamesh Kulkarni via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: > > > > Hi, > > The attached patch removes redundant check for number of loops in > > pass_vectorize::execute, > > since it only calls vectorize_loops, and in vectorize_loops, we > > immediately bail out if no loops are present: > > vect_loops_num = number_of_loops (cfun); > > /* Bail out if there are no loops. */ > > if (vect_loops_num <= 1) > > return 0; > > > > Is the patch OK to commit ? > > Can you please merge both functions then, keeping only > pass_vectorize::execute (and replacing 'cfun' occurrences > by 'fun' as passed as argument)? Done in the attached patch, does it look OK ? Thanks, Prathamesh > > Thanks, > Richard. > > > > > Thanks, > > Prathamesh diff --git a/gcc/tree-ssa-loop.c b/gcc/tree-ssa-loop.c index 1bbf2f1fb2c..6b54e2bccfc 100644 --- a/gcc/tree-ssa-loop.c +++ b/gcc/tree-ssa-loop.c @@ -370,57 +370,6 @@ make_pass_tree_loop_init (gcc::context *ctxt) return new pass_tree_loop_init (ctxt); } -/* Loop autovectorization. */ - -namespace { - -const pass_data pass_data_vectorize = -{ - GIMPLE_PASS, /* type */ - "vect", /* name */ - OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */ - TV_TREE_VECTORIZATION, /* tv_id */ - ( PROP_cfg | PROP_ssa ), /* properties_required */ - 0, /* properties_provided */ - 0, /* properties_destroyed */ - 0, /* todo_flags_start */ - 0, /* todo_flags_finish */ -}; - -class pass_vectorize : public gimple_opt_pass -{ -public: - pass_vectorize (gcc::context *ctxt) - : gimple_opt_pass (pass_data_vectorize, ctxt) - {} - - /* opt_pass methods: */ - virtual bool gate (function *fun) - { - return flag_tree_loop_vectorize || fun->has_force_vectorize_loops; - } - - virtual unsigned int execute (function *); - -}; // class pass_vectorize - -unsigned int -pass_vectorize::execute (function *fun) -{ - if (number_of_loops (fun) <= 1) - return 0; - - return vectorize_loops (); -} - -} // anon namespace - -gimple_opt_pass * -make_pass_vectorize (gcc::context *ctxt) -{ - return new pass_vectorize (ctxt); -} - /* Propagation of constants using scev. */ namespace { diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c index a2e13acb6d2..67d6e7de326 100644 --- a/gcc/tree-vectorizer.c +++ b/gcc/tree-vectorizer.c @@ -251,11 +251,11 @@ simd_array_to_simduid::equal (const simd_array_to_simduid *p1, IFN_GOMP_SIMD_ORDERED_{START,END}. */ static void -adjust_simduid_builtins (hash_table<simduid_to_vf> *htab) +adjust_simduid_builtins (hash_table<simduid_to_vf> *htab, function *fun) { basic_block bb; - FOR_EACH_BB_FN (bb, cfun) + FOR_EACH_BB_FN (bb, fun) { gimple_stmt_iterator i; @@ -383,7 +383,7 @@ note_simd_array_uses_cb (tree *tp, int *walk_subtrees, void *data) simduid. */ static void -note_simd_array_uses (hash_table<simd_array_to_simduid> **htab) +note_simd_array_uses (hash_table<simd_array_to_simduid> **htab, function *fun) { basic_block bb; gimple_stmt_iterator gsi; @@ -394,7 +394,7 @@ note_simd_array_uses (hash_table<simd_array_to_simduid> **htab) wi.info = &ns; ns.htab = htab; - FOR_EACH_BB_FN (bb, cfun) + FOR_EACH_BB_FN (bb, fun) for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) { gimple *stmt = gsi_stmt (gsi); @@ -881,7 +881,7 @@ vect_loop_vectorized_call (class loop *loop, gcond **cond) internal call. */ static gimple * -vect_loop_dist_alias_call (class loop *loop) +vect_loop_dist_alias_call (class loop *loop, function *fun) { basic_block bb; basic_block entry; @@ -892,7 +892,7 @@ vect_loop_dist_alias_call (class loop *loop) if (loop->orig_loop_num == 0) return NULL; - orig = get_loop (cfun, loop->orig_loop_num); + orig = get_loop (fun, loop->orig_loop_num); if (orig == NULL) { /* The original loop is somehow destroyed. Clear the information. */ @@ -906,7 +906,7 @@ vect_loop_dist_alias_call (class loop *loop) bb = loop_preheader_edge (loop)->src; outer = bb->loop_father; - entry = ENTRY_BLOCK_PTR_FOR_FN (cfun); + entry = ENTRY_BLOCK_PTR_FOR_FN (fun); /* Look upward in dominance tree. */ for (; bb != entry && flow_bb_inside_loop_p (outer, bb); @@ -935,12 +935,13 @@ vect_loop_dist_alias_call (class loop *loop) represented by LOOP_VINFO. LOOP_VECTORIZED_CALL is the internal call guarding the loop which has been if converted. */ static void -set_uid_loop_bbs (loop_vec_info loop_vinfo, gimple *loop_vectorized_call) +set_uid_loop_bbs (loop_vec_info loop_vinfo, gimple *loop_vectorized_call, + function *fun) { tree arg = gimple_call_arg (loop_vectorized_call, 1); basic_block *bbs; unsigned int i; - class loop *scalar_loop = get_loop (cfun, tree_to_shwi (arg)); + class loop *scalar_loop = get_loop (fun, tree_to_shwi (arg)); LOOP_VINFO_SCALAR_LOOP (loop_vinfo) = scalar_loop; gcc_checking_assert (vect_loop_vectorized_call (scalar_loop) @@ -955,7 +956,7 @@ set_uid_loop_bbs (loop_vec_info loop_vinfo, gimple *loop_vectorized_call) if (g) { arg = gimple_call_arg (g, 0); - get_loop (cfun, tree_to_shwi (arg))->dont_vectorize = true; + get_loop (fun, tree_to_shwi (arg))->dont_vectorize = true; fold_loop_internal_call (g, boolean_false_node); } } @@ -982,12 +983,13 @@ set_uid_loop_bbs (loop_vec_info loop_vinfo, gimple *loop_vectorized_call) static void vect_transform_loops (hash_table<simduid_to_vf> *&simduid_to_vf_htab, - loop_p loop, gimple *loop_vectorized_call) + loop_p loop, gimple *loop_vectorized_call, + function *fun) { loop_vec_info loop_vinfo = loop_vec_info_for_loop (loop); if (loop_vectorized_call) - set_uid_loop_bbs (loop_vinfo, loop_vectorized_call); + set_uid_loop_bbs (loop_vinfo, loop_vectorized_call, fun); unsigned HOST_WIDE_INT bytes; if (dump_enabled_p ()) @@ -1019,7 +1021,7 @@ vect_transform_loops (hash_table<simduid_to_vf> *&simduid_to_vf_htab, /* Epilogue of vectorized loop must be vectorized too. */ if (new_loop) - vect_transform_loops (simduid_to_vf_htab, new_loop, NULL); + vect_transform_loops (simduid_to_vf_htab, new_loop, NULL, fun); } /* Try to vectorize LOOP. */ @@ -1028,7 +1030,8 @@ static unsigned try_vectorize_loop_1 (hash_table<simduid_to_vf> *&simduid_to_vf_htab, unsigned *num_vectorized_loops, loop_p loop, gimple *loop_vectorized_call, - gimple *loop_dist_alias_call) + gimple *loop_dist_alias_call, + function *fun) { unsigned ret = 0; vec_info_shared shared; @@ -1099,7 +1102,7 @@ try_vectorize_loop_1 (hash_table<simduid_to_vf> *&simduid_to_vf_htab, if (!require_loop_vectorize) { tree arg = gimple_call_arg (loop_vectorized_call, 1); - class loop *scalar_loop = get_loop (cfun, tree_to_shwi (arg)); + class loop *scalar_loop = get_loop (fun, tree_to_shwi (arg)); if (vect_slp_if_converted_bb (bb, scalar_loop)) { fold_loop_internal_call (loop_vectorized_call, @@ -1129,7 +1132,7 @@ try_vectorize_loop_1 (hash_table<simduid_to_vf> *&simduid_to_vf_htab, (*num_vectorized_loops)++; /* Transform LOOP and its epilogues. */ - vect_transform_loops (simduid_to_vf_htab, loop, loop_vectorized_call); + vect_transform_loops (simduid_to_vf_htab, loop, loop_vectorized_call, fun); if (loop_vectorized_call) { @@ -1150,7 +1153,8 @@ try_vectorize_loop_1 (hash_table<simduid_to_vf> *&simduid_to_vf_htab, static unsigned try_vectorize_loop (hash_table<simduid_to_vf> *&simduid_to_vf_htab, - unsigned *num_vectorized_loops, loop_p loop) + unsigned *num_vectorized_loops, loop_p loop, + function *fun) { if (!((flag_tree_loop_vectorize && optimize_loop_nest_for_speed_p (loop)) @@ -1159,16 +1163,50 @@ try_vectorize_loop (hash_table<simduid_to_vf> *&simduid_to_vf_htab, return try_vectorize_loop_1 (simduid_to_vf_htab, num_vectorized_loops, loop, vect_loop_vectorized_call (loop), - vect_loop_dist_alias_call (loop)); + vect_loop_dist_alias_call (loop, fun), fun); } +/* Loop autovectorization. */ + +namespace { + +const pass_data pass_data_vectorize = +{ + GIMPLE_PASS, /* type */ + "vect", /* name */ + OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */ + TV_TREE_VECTORIZATION, /* tv_id */ + ( PROP_cfg | PROP_ssa ), /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + 0, /* todo_flags_finish */ +}; + +class pass_vectorize : public gimple_opt_pass +{ +public: + pass_vectorize (gcc::context *ctxt) + : gimple_opt_pass (pass_data_vectorize, ctxt) + {} + + /* opt_pass methods: */ + virtual bool gate (function *fun) + { + return flag_tree_loop_vectorize || fun->has_force_vectorize_loops; + } + + virtual unsigned int execute (function *); + +}; // class pass_vectorize + /* Function vectorize_loops. Entry point to loop vectorization phase. */ unsigned -vectorize_loops (void) +pass_vectorize::execute (function *fun) { unsigned int i; unsigned int num_vectorized_loops = 0; @@ -1179,7 +1217,7 @@ vectorize_loops (void) bool any_ifcvt_loops = false; unsigned ret = 0; - vect_loops_num = number_of_loops (cfun); + vect_loops_num = number_of_loops (fun); /* Bail out if there are no loops. */ if (vect_loops_num <= 1) @@ -1187,15 +1225,15 @@ vectorize_loops (void) vect_slp_init (); - if (cfun->has_simduid_loops) - note_simd_array_uses (&simd_array_to_simduid_htab); + if (fun->has_simduid_loops) + note_simd_array_uses (&simd_array_to_simduid_htab, fun); /* ----------- Analyze loops. ----------- */ /* If some loop was duplicated, it gets bigger number than all previously defined loops. This fact allows us to run only over initial loops skipping newly generated ones. */ - for (auto loop : loops_list (cfun, 0)) + for (auto loop : loops_list (fun, 0)) if (loop->dont_vectorize) { any_ifcvt_loops = true; @@ -1227,25 +1265,25 @@ vectorize_loops (void) { tree arg = gimple_call_arg (loop_vectorized_call, 0); class loop *vector_loop - = get_loop (cfun, tree_to_shwi (arg)); + = get_loop (fun, tree_to_shwi (arg)); if (vector_loop && vector_loop != loop) { /* Make sure we don't vectorize it twice. */ vector_loop->dont_vectorize = true; ret |= try_vectorize_loop (simduid_to_vf_htab, &num_vectorized_loops, - vector_loop); + vector_loop, fun); } } } } else ret |= try_vectorize_loop (simduid_to_vf_htab, &num_vectorized_loops, - loop); + loop, fun); vect_location = dump_user_location_t (); - statistics_counter_event (cfun, "Vectorized loops", num_vectorized_loops); + statistics_counter_event (fun, "Vectorized loops", num_vectorized_loops); if (dump_enabled_p () || (num_vectorized_loops > 0 && dump_enabled_p ())) dump_printf_loc (MSG_NOTE, vect_location, @@ -1255,9 +1293,9 @@ vectorize_loops (void) /* ----------- Finalize. ----------- */ if (any_ifcvt_loops) - for (i = 1; i < number_of_loops (cfun); i++) + for (i = 1; i < number_of_loops (fun); i++) { - loop = get_loop (cfun, i); + loop = get_loop (fun, i); if (loop && loop->dont_vectorize) { gimple *g = vect_loop_vectorized_call (loop); @@ -1268,7 +1306,7 @@ vectorize_loops (void) g = NULL; } else - g = vect_loop_dist_alias_call (loop); + g = vect_loop_dist_alias_call (loop, fun); if (g) { @@ -1278,12 +1316,12 @@ vectorize_loops (void) } } - for (i = 1; i < number_of_loops (cfun); i++) + for (i = 1; i < number_of_loops (fun); i++) { loop_vec_info loop_vinfo; bool has_mask_store; - loop = get_loop (cfun, i); + loop = get_loop (fun, i); if (!loop || !loop->aux) continue; loop_vinfo = (loop_vec_info) loop->aux; @@ -1296,9 +1334,9 @@ vectorize_loops (void) } /* Fold IFN_GOMP_SIMD_{VF,LANE,LAST_LANE,ORDERED_{START,END}} builtins. */ - if (cfun->has_simduid_loops) + if (fun->has_simduid_loops) { - adjust_simduid_builtins (simduid_to_vf_htab); + adjust_simduid_builtins (simduid_to_vf_htab, fun); /* Avoid stale SCEV cache entries for the SIMD_LANE defs. */ scev_reset (); } @@ -1308,7 +1346,7 @@ vectorize_loops (void) if (simd_array_to_simduid_htab) shrink_simd_arrays (simd_array_to_simduid_htab, simduid_to_vf_htab); delete simduid_to_vf_htab; - cfun->has_simduid_loops = false; + fun->has_simduid_loops = false; vect_slp_fini (); if (num_vectorized_loops > 0) @@ -1323,6 +1361,13 @@ vectorize_loops (void) return ret; } +} // anon namespace + +gimple_opt_pass * +make_pass_vectorize (gcc::context *ctxt) +{ + return new pass_vectorize (ctxt); +} /* Entry point to the simduid cleanup pass. */ @@ -1360,10 +1405,10 @@ pass_simduid_cleanup::execute (function *fun) { hash_table<simd_array_to_simduid> *simd_array_to_simduid_htab = NULL; - note_simd_array_uses (&simd_array_to_simduid_htab); + note_simd_array_uses (&simd_array_to_simduid_htab, fun); /* Fold IFN_GOMP_SIMD_{VF,LANE,LAST_LANE,ORDERED_{START,END}} builtins. */ - adjust_simduid_builtins (NULL); + adjust_simduid_builtins (NULL, fun); /* Shrink any "omp array simd" temporary arrays to the actual vectorization factors. */
On Tue, Nov 9, 2021 at 7:34 AM Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org> wrote: > > On Mon, 8 Nov 2021 at 16:42, Richard Biener <richard.guenther@gmail.com> wrote: > > > > On Mon, Nov 8, 2021 at 12:06 PM Prathamesh Kulkarni via Gcc-patches > > <gcc-patches@gcc.gnu.org> wrote: > > > > > > Hi, > > > The attached patch removes redundant check for number of loops in > > > pass_vectorize::execute, > > > since it only calls vectorize_loops, and in vectorize_loops, we > > > immediately bail out if no loops are present: > > > vect_loops_num = number_of_loops (cfun); > > > /* Bail out if there are no loops. */ > > > if (vect_loops_num <= 1) > > > return 0; > > > > > > Is the patch OK to commit ? > > > > Can you please merge both functions then, keeping only > > pass_vectorize::execute (and replacing 'cfun' occurrences > > by 'fun' as passed as argument)? > Done in the attached patch, does it look OK ? OK. Thanks, Richard. > Thanks, > Prathamesh > > > > Thanks, > > Richard. > > > > > > > > Thanks, > > > Prathamesh
diff --git a/gcc/tree-ssa-loop.c b/gcc/tree-ssa-loop.c index 1bbf2f1fb2c..d10e2dc0d54 100644 --- a/gcc/tree-ssa-loop.c +++ b/gcc/tree-ssa-loop.c @@ -407,9 +407,6 @@ public: unsigned int pass_vectorize::execute (function *fun) { - if (number_of_loops (fun) <= 1) - return 0; - return vectorize_loops (); }