From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id D8F0D3858022; Mon, 8 Nov 2021 15:30:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D8F0D3858022 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-v5)] Restore old code that can handle floating point types. X-Act-Checkin: gcc X-Git-Author: Martin Liska X-Git-Refname: refs/users/marxin/heads/loop-unswitching-switch-v5 X-Git-Oldrev: 5694683d39b49629ab1ab12cd1753bca31c28164 X-Git-Newrev: 5506d47cd1b34ed0748f9218d6856abc98c6e9a2 Message-Id: <20211108153054.D8F0D3858022@sourceware.org> Date: Mon, 8 Nov 2021 15:30: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: Mon, 08 Nov 2021 15:30:55 -0000 https://gcc.gnu.org/g:5506d47cd1b34ed0748f9218d6856abc98c6e9a2 commit 5506d47cd1b34ed0748f9218d6856abc98c6e9a2 Author: Martin Liska Date: Mon Nov 8 16:29:59 2021 +0100 Restore old code that can handle floating point types. Diff: --- gcc/tree-ssa-loop-unswitch.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/gcc/tree-ssa-loop-unswitch.c b/gcc/tree-ssa-loop-unswitch.c index 4b4bd471acd..1d169802252 100644 --- a/gcc/tree-ssa-loop-unswitch.c +++ b/gcc/tree-ssa-loop-unswitch.c @@ -300,6 +300,39 @@ tree_may_unswitch_on (basic_block bb, class loop *loop, edge *cond_edge) return NULL_TREE; } +/* Simplifies COND using checks in front of the entry of the LOOP. Just very + simplish (sufficient to prevent us from duplicating loop in unswitching + unnecessarily). */ + +static tree +simplify_using_entry_checks (class loop *loop, tree cond) +{ + edge e = loop_preheader_edge (loop); + gimple *stmt; + + while (1) + { + stmt = last_stmt (e->src); + if (stmt + && gimple_code (stmt) == GIMPLE_COND + && gimple_cond_code (stmt) == TREE_CODE (cond) + && operand_equal_p (gimple_cond_lhs (stmt), + TREE_OPERAND (cond, 0), 0) + && operand_equal_p (gimple_cond_rhs (stmt), + TREE_OPERAND (cond, 1), 0)) + return (e->flags & EDGE_TRUE_VALUE + ? boolean_true_node + : boolean_false_node); + + if (!single_pred_p (e->src)) + return cond; + + e = single_pred_edge (e->src); + if (e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun)) + return cond; + } +} + /* Unswitch single LOOP. NUM is number of unswitchings done; we do not allow it to grow too much, it is too easy to create example on that the code would grow exponentially. */ @@ -393,6 +426,25 @@ tree_unswitch_single_loop (class loop *loop, int num) update_stmt (condition); changed = true; } + else + { + /* FIXME: Remove legacy code for floating point type that + is currently not supported by ranger. */ + cond = simplify_using_entry_checks (loop, cond); + if (integer_nonzerop (cond)) + { + gimple_cond_set_condition_from_tree (condition, + boolean_true_node); + changed = true; + } + else if (integer_zerop (cond)) + { + /* Remove true path. */ + gimple_cond_set_condition_from_tree (condition, + boolean_false_node); + changed = true; + } + } } else if (swtch != NULL) {