From: Victor Do Nascimento Date: Thu, 13 Nov 2025 13:54:05 +0000 (+0000) Subject: cfgloop: Modify loop_exits_{to,from}_bb_p return type to edge X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd1a0a437de220d0bced2856ee394478279ac51f;p=thirdparty%2Fgcc.git cfgloop: Modify loop_exits_{to,from}_bb_p return type to edge 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. --- diff --git a/gcc/cfgloop.cc b/gcc/cfgloop.cc index 84b92c78c33..6eaf4b479af 100644 --- a/gcc/cfgloop.cc +++ b/gcc/cfgloop.cc @@ -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. */ diff --git a/gcc/cfgloop.h b/gcc/cfgloop.h index 7820e0cc2bd..82d177f0442 100644 --- a/gcc/cfgloop.h +++ b/gcc/cfgloop.h @@ -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);