On Thu, Nov 13, 2025 at 9:01 AM Victor Do Nascimento
<[email protected]> wrote:
>
> 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.
>
> Boostrapped and regtested on aarch64, all clean.
>
> gcc/ChangeLog:
>
> * cfgloop.cc (loop_exits_to_bb_p): Change return type.
> (loop_exits_from_bb_p): Likewise.
> ---
> gcc/cfgloop.cc | 12 ++++++------
> gcc/cfgloop.h | 4 ++--
> 2 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/gcc/cfgloop.cc b/gcc/cfgloop.cc
> index 84b92c78c33..4a8de022508 100644
> --- a/gcc/cfgloop.cc
> +++ b/gcc/cfgloop.cc
> @@ -1807,7 +1807,7 @@ single_exit (const class loop *loop)
>
> /* Returns true when BB has an incoming edge exiting LOOP. */
The comment needs to be updated.
Like:
Returns the edge of the incoming edge of BB exiting the LOOP. NULL is
returned when there is no such edge.
Thanks,
Andrew
>
> -bool
> +edge
> loop_exits_to_bb_p (class loop *loop, basic_block bb)
> {
> edge e;
> @@ -1815,14 +1815,14 @@ 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. */
>
> -bool
> +edge
> loop_exits_from_bb_p (class loop *loop, basic_block bb)
> {
> edge e;
> @@ -1830,9 +1830,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);
>
> --
> 2.43.0
>