public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/loop-unswitching-switch-v5)] Restore old code that can handle floating point types.
@ 2021-11-08 15:36 Martin Liska
0 siblings, 0 replies; 2+ messages in thread
From: Martin Liska @ 2021-11-08 15:36 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:31102db9992df9b12228e36cdc1b18cc7198a733
commit 31102db9992df9b12228e36cdc1b18cc7198a733
Author: Martin Liska <mliska@suse.cz>
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)
{
^ permalink raw reply [flat|nested] 2+ messages in thread
* [gcc(refs/users/marxin/heads/loop-unswitching-switch-v5)] Restore old code that can handle floating point types.
@ 2021-11-08 15:30 Martin Liska
0 siblings, 0 replies; 2+ messages in thread
From: Martin Liska @ 2021-11-08 15:30 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:5506d47cd1b34ed0748f9218d6856abc98c6e9a2
commit 5506d47cd1b34ed0748f9218d6856abc98c6e9a2
Author: Martin Liska <mliska@suse.cz>
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)
{
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-08 15:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-08 15:36 [gcc(refs/users/marxin/heads/loop-unswitching-switch-v5)] Restore old code that can handle floating point types Martin Liska
-- strict thread matches above, loose matches on Subject: below --
2021-11-08 15:30 Martin Liska
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).