]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cfgloop: Modify loop_exits_{to,from}_bb_p return type to edge
authorVictor Do Nascimento <vicdon01@ip-10-248-139-187.eu-west-1.compute.internal>
Thu, 13 Nov 2025 13:54:05 +0000 (13:54 +0000)
committerVictor Do Nascimento <victor.donascimento@arm.com>
Mon, 17 Nov 2025 10:44:53 +0000 (10:44 +0000)
Given that when finding whether the predicate in question is satisfied
or not we already do the heavy-lifting of identifying the specific
edge that matches the particular criterion, it is wasteful to throw
the edge information away, only to potentially have to recalculate it
when true is returned.

Rather, given the ability of treating a valid pointer as true and,
conversely, the NULL pointer as false, we can return the edge for
should we wish to use it, while keeping the function's existing calls
in the code as is.

gcc/ChangeLog:

* cfgloop.cc (loop_exits_to_bb_p): Change return type.
(loop_exits_from_bb_p): Likewise.
* cfgloop.h: (loop_exits_to_bb_p): Likewise.
(loop_exits_from_bb_p): Likewise.

gcc/cfgloop.cc
gcc/cfgloop.h

index 84b92c78c333d6ffcc7e85c6ee6db072fdc1ce45..6eaf4b479af7e8805e09359044650586f1f7a05b 100644 (file)
@@ -1805,9 +1805,10 @@ single_exit (const class loop *loop)
     return NULL;
 }
 
-/* Returns true when BB has an incoming edge exiting LOOP.  */
+/* Returns incoming edge when BB has an incoming edge exiting LOOP, else return
+   NULL.  */
 
-bool
+edge
 loop_exits_to_bb_p (class loop *loop, basic_block bb)
 {
   edge e;
@@ -1815,14 +1816,15 @@ loop_exits_to_bb_p (class loop *loop, basic_block bb)
 
   FOR_EACH_EDGE (e, ei, bb->preds)
     if (loop_exit_edge_p (loop, e))
-      return true;
+      return e;
 
-  return false;
+  return NULL;
 }
 
-/* Returns true when BB has an outgoing edge exiting LOOP.  */
+/* Returns outgoing edge when BB has an outgoing edge exiting LOOP, else return
+   NULL.  */
 
-bool
+edge
 loop_exits_from_bb_p (class loop *loop, basic_block bb)
 {
   edge e;
@@ -1830,9 +1832,9 @@ loop_exits_from_bb_p (class loop *loop, basic_block bb)
 
   FOR_EACH_EDGE (e, ei, bb->succs)
     if (loop_exit_edge_p (loop, e))
-      return true;
+      return e;
 
-  return false;
+  return NULL;
 }
 
 /* Return location corresponding to the loop control condition if possible.  */
index 7820e0cc2bd6a744eab0f63b7af14ecf0b6add67..82d177f0442a71f828124ce42a9161e8ab94346e 100644 (file)
@@ -370,8 +370,8 @@ extern int num_loop_insns (const class loop *);
 extern int average_num_loop_insns (const class loop *);
 extern unsigned get_loop_level (const class loop *);
 extern bool loop_exit_edge_p (const class loop *, const_edge);
-extern bool loop_exits_to_bb_p (class loop *, basic_block);
-extern bool loop_exits_from_bb_p (class loop *, basic_block);
+extern edge loop_exits_to_bb_p (class loop *, basic_block);
+extern edge loop_exits_from_bb_p (class loop *, basic_block);
 extern void mark_loop_exit_edges (void);
 extern dump_user_location_t get_loop_location (class loop *loop);