public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/loop-unswitch-improvement-v6)] WIP xx.
@ 2021-12-06 14:34 Martin Liska
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Liska @ 2021-12-06 14:34 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ea644aa840ebfe215d6c3d105964b6a0b7aeb969

commit ea644aa840ebfe215d6c3d105964b6a0b7aeb969
Author: Martin Liska <mliska@suse.cz>
Date:   Wed Dec 1 10:03:35 2021 +0100

    WIP xx.

Diff:
---
 gcc/tree-ssa-loop-unswitch.c | 42 ++++++++++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/gcc/tree-ssa-loop-unswitch.c b/gcc/tree-ssa-loop-unswitch.c
index b808a350542..f7660a1f9ac 100644
--- a/gcc/tree-ssa-loop-unswitch.c
+++ b/gcc/tree-ssa-loop-unswitch.c
@@ -355,30 +355,40 @@ find_unswitching_predicates_for_bb (basic_block bb, class loop *loop,
 }
 
 static void
-combine_range (predicate_vector &predicate_path, tree index, irange &path_range)
+merge_last (predicate_vector &predicate_path)
 {
-  bool first = true;
+  unswitch_predicate *last_predicate = predicate_path.last ().first;
 
-  for (auto p: predicate_path)
+  for (int i = predicate_path.length () - 2; i >= 0; i--)
     {
-      unswitch_predicate *predicate = p.first;
-      bool true_edge = p.second;
+      unswitch_predicate *predicate = predicate_path[i].first;
+      bool true_edge = predicate_path[i].second;
 
-      if (operand_equal_p (predicate->lhs, index, 0))
+      if (operand_equal_p (predicate->lhs, last_predicate->lhs, 0))
 	{
 	  irange &other
 	    = true_edge ? predicate->true_range : predicate->false_range;
-	  if (first)
-	    {
-	      first = false;
-	      path_range = other;
-	    }
-	  else
-	    path_range.intersect (other);
+	  last_predicate->true_range.intersect (other);
+	  last_predicate->false_range.intersect (other);
+	  return;
 	}
     }
 }
 
+void
+find_range_for_lhs (predicate_vector &predicate_path, tree lhs,
+		    int_range_max &range)
+{
+  for (int i = predicate_path.length () - 1; i >= 0; i--)
+    {
+      unswitch_predicate *predicate = predicate_path[i].first;
+      bool true_edge = predicate_path[i].second;
+
+      if (operand_equal_p (predicate->lhs, lhs, 0))
+	range = true_edge ? predicate->true_range : predicate->false_range;
+    }
+}
+
 /* Simplifies COND using checks in front of the entry of the LOOP.
    Utilize both symbolic expressions and value ranges calculated by Ranger.  */
 
@@ -404,7 +414,7 @@ evaluate_control_stmt_using_entry_checks (gimple *stmt,
 	{
 	  int_range_max r;
 	  int_range_max path_range;
-	  combine_range (predicate_path, lhs, path_range);
+	  find_range_for_lhs (predicate_path, lhs, path_range);
 	  if (!path_range.undefined_p ()
 	      && fold_range (r, stmt, path_range)
 	      && r.singleton_p ())
@@ -541,11 +551,13 @@ evaluate_loop_insns_for_predicate (class loop *loop, basic_block *bbs,
   predicate_path.safe_push (std::make_pair (predicate, true));
   unsigned true_loop_cost = evaluate_insns (loop, bbs, predicate_path,
 					    reachable_flag);
+  merge_last (predicate_path);
   predicate_path.pop ();
 
   predicate_path.safe_push (std::make_pair (predicate, false));
   unsigned false_loop_cost = evaluate_insns (loop, bbs, predicate_path,
 					     reachable_flag);
+  merge_last (predicate_path);
   predicate_path.pop ();
 
   return true_loop_cost + false_loop_cost;
@@ -665,11 +677,13 @@ tree_unswitch_single_loop (class loop *loop, int num,
 
       /* Invoke itself on modified loops.  */
       predicate_path.safe_push (std::make_pair (predicate, false));
+      merge_last (predicate_path);
       changed |= simplify_loop_version (nloop, predicate_path);
       tree_unswitch_single_loop (nloop, num + 1, predicate_path, budget);
       predicate_path.pop ();
 
       predicate_path.safe_push (std::make_pair (predicate, true));
+      merge_last (predicate_path);
       changed |= simplify_loop_version (loop, predicate_path);
       tree_unswitch_single_loop (loop, num + 1, predicate_path, budget);
       predicate_path.pop ();


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [gcc(refs/users/marxin/heads/loop-unswitch-improvement-v6)] WIP xx.
@ 2021-12-07 15:21 Martin Liska
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Liska @ 2021-12-07 15:21 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2d9a2caee5e03e843f790f114f3699f167427f24

commit 2d9a2caee5e03e843f790f114f3699f167427f24
Author: Martin Liska <mliska@suse.cz>
Date:   Wed Dec 1 10:03:35 2021 +0100

    WIP xx.

Diff:
---
 gcc/tree-ssa-loop-unswitch.c | 42 ++++++++++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/gcc/tree-ssa-loop-unswitch.c b/gcc/tree-ssa-loop-unswitch.c
index b808a350542..f7660a1f9ac 100644
--- a/gcc/tree-ssa-loop-unswitch.c
+++ b/gcc/tree-ssa-loop-unswitch.c
@@ -355,30 +355,40 @@ find_unswitching_predicates_for_bb (basic_block bb, class loop *loop,
 }
 
 static void
-combine_range (predicate_vector &predicate_path, tree index, irange &path_range)
+merge_last (predicate_vector &predicate_path)
 {
-  bool first = true;
+  unswitch_predicate *last_predicate = predicate_path.last ().first;
 
-  for (auto p: predicate_path)
+  for (int i = predicate_path.length () - 2; i >= 0; i--)
     {
-      unswitch_predicate *predicate = p.first;
-      bool true_edge = p.second;
+      unswitch_predicate *predicate = predicate_path[i].first;
+      bool true_edge = predicate_path[i].second;
 
-      if (operand_equal_p (predicate->lhs, index, 0))
+      if (operand_equal_p (predicate->lhs, last_predicate->lhs, 0))
 	{
 	  irange &other
 	    = true_edge ? predicate->true_range : predicate->false_range;
-	  if (first)
-	    {
-	      first = false;
-	      path_range = other;
-	    }
-	  else
-	    path_range.intersect (other);
+	  last_predicate->true_range.intersect (other);
+	  last_predicate->false_range.intersect (other);
+	  return;
 	}
     }
 }
 
+void
+find_range_for_lhs (predicate_vector &predicate_path, tree lhs,
+		    int_range_max &range)
+{
+  for (int i = predicate_path.length () - 1; i >= 0; i--)
+    {
+      unswitch_predicate *predicate = predicate_path[i].first;
+      bool true_edge = predicate_path[i].second;
+
+      if (operand_equal_p (predicate->lhs, lhs, 0))
+	range = true_edge ? predicate->true_range : predicate->false_range;
+    }
+}
+
 /* Simplifies COND using checks in front of the entry of the LOOP.
    Utilize both symbolic expressions and value ranges calculated by Ranger.  */
 
@@ -404,7 +414,7 @@ evaluate_control_stmt_using_entry_checks (gimple *stmt,
 	{
 	  int_range_max r;
 	  int_range_max path_range;
-	  combine_range (predicate_path, lhs, path_range);
+	  find_range_for_lhs (predicate_path, lhs, path_range);
 	  if (!path_range.undefined_p ()
 	      && fold_range (r, stmt, path_range)
 	      && r.singleton_p ())
@@ -541,11 +551,13 @@ evaluate_loop_insns_for_predicate (class loop *loop, basic_block *bbs,
   predicate_path.safe_push (std::make_pair (predicate, true));
   unsigned true_loop_cost = evaluate_insns (loop, bbs, predicate_path,
 					    reachable_flag);
+  merge_last (predicate_path);
   predicate_path.pop ();
 
   predicate_path.safe_push (std::make_pair (predicate, false));
   unsigned false_loop_cost = evaluate_insns (loop, bbs, predicate_path,
 					     reachable_flag);
+  merge_last (predicate_path);
   predicate_path.pop ();
 
   return true_loop_cost + false_loop_cost;
@@ -665,11 +677,13 @@ tree_unswitch_single_loop (class loop *loop, int num,
 
       /* Invoke itself on modified loops.  */
       predicate_path.safe_push (std::make_pair (predicate, false));
+      merge_last (predicate_path);
       changed |= simplify_loop_version (nloop, predicate_path);
       tree_unswitch_single_loop (nloop, num + 1, predicate_path, budget);
       predicate_path.pop ();
 
       predicate_path.safe_push (std::make_pair (predicate, true));
+      merge_last (predicate_path);
       changed |= simplify_loop_version (loop, predicate_path);
       tree_unswitch_single_loop (loop, num + 1, predicate_path, budget);
       predicate_path.pop ();


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-07 15:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-06 14:34 [gcc(refs/users/marxin/heads/loop-unswitch-improvement-v6)] WIP xx Martin Liska
2021-12-07 15:21 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).