From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id 7F4C33857C56; Tue, 31 Aug 2021 14:33:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7F4C33857C56 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Martin Liska To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/marxin/heads/loop-unswitching-switch)] WIP changes. X-Act-Checkin: gcc X-Git-Author: Martin Liska X-Git-Refname: refs/users/marxin/heads/loop-unswitching-switch X-Git-Oldrev: b33750e2970d087e31bd4b6b99c094545d54fcac X-Git-Newrev: 9a2cb6a46aac3bf69e7158d876d1f6391c7d7229 Message-Id: <20210831143354.7F4C33857C56@sourceware.org> Date: Tue, 31 Aug 2021 14:33:54 +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: Tue, 31 Aug 2021 14:33:54 -0000 https://gcc.gnu.org/g:9a2cb6a46aac3bf69e7158d876d1f6391c7d7229 commit 9a2cb6a46aac3bf69e7158d876d1f6391c7d7229 Author: Martin Liska Date: Tue Aug 31 11:50:33 2021 +0200 WIP changes. Diff: --- gcc/tree-ssa-loop-unswitch.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/gcc/tree-ssa-loop-unswitch.c b/gcc/tree-ssa-loop-unswitch.c index c2100489b7f..c7cf0223501 100644 --- a/gcc/tree-ssa-loop-unswitch.c +++ b/gcc/tree-ssa-loop-unswitch.c @@ -391,14 +391,25 @@ tree_unswitch_single_loop (class loop *loop, int num) tree lab = gimple_switch_label (gs, 1); basic_block dest = label_to_block (cfun, CASE_LABEL (lab)); edge e = find_edge (gimple_bb (stmt), dest); + unsigned nlabels = gimple_switch_num_labels (gs); + for (unsigned i = 1; i < nlabels - 1; i++) + { + tree next_label = gimple_switch_label (gs, i + 1); + gimple_switch_set_label (gs, i, next_label); + basic_block next_dest + = label_to_block (cfun, CASE_LABEL (next_label)); + + /* Shared edge among multiple cases. */ + if (e != NULL && e->dest == next_dest) + e = NULL; + } // modifying the CFG here may play havoc on things like // dominators and we really would like to prevent doing // full update_ssa for each individual unswitching as well - remove_edge (e); - if (gimple_switch_num_labels (gs) > 1) - gimple_switch_set_label (gs, 1, - gimple_switch_label (gs, gimple_switch_num_labels (gs) - 1)); - gimple_switch_set_num_labels (gs, gimple_switch_num_labels (gs) - 1); + if (e != NULL) + remove_edge (e); + + gimple_switch_set_num_labels (gs, nlabels - 1); end_recording_case_labels (); /* Update based on the adjusted switch. */ cond = tree_may_unswitch_on (bbs[i], loop); @@ -406,7 +417,7 @@ tree_unswitch_single_loop (class loop *loop, int num) changed = true; } // As said, it's a bit hackish to do it this way. */ - if (TREE_CODE (cond) == INTEGER_CST) + if (cond == NULL_TREE || TREE_CODE (cond) == INTEGER_CST) ; /* Do not unswitch too much. */ else if (num > param_max_unswitch_level) @@ -524,8 +535,10 @@ tree_unswitch_single_loop (class loop *loop, int num) free_original_copy_tables (); /* Invoke itself on modified loops. */ - tree_unswitch_single_loop (nloop, num + 1); - tree_unswitch_single_loop (loop, num + 1); + if (nloop->aux != (void *)0xa5a5a5a5a5a5a5a5) + tree_unswitch_single_loop (nloop, num + 1); + if (loop->aux != (void *)0xa5a5a5a5a5a5a5a5) + tree_unswitch_single_loop (loop, num + 1); free (bbs); return true; }