https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108685

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:713fa5db8ceb4ba8783a0d690ceb4c07f2ff03d0

commit r13-6731-g713fa5db8ceb4ba8783a0d690ceb4c07f2ff03d0
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Fri Mar 17 08:46:28 2023 +0100

    openmp: Fix up handling of doacross loops with noreturn body in loops
[PR108685]

    The following patch fixes an ICE with doacross loops which have a single
entry
    no exit body, at least one of the ordered > collapse loops isn't guaranteed
to
    have at least one iteration and the whole doacross loop is inside some
other loop.
    The OpenMP constructs aren't represented by struct loop until the omp
expansions,
    so for a normal doacross loop which doesn't have a noreturn body the
entry_bb
    with the GOMP_FOR statement and the first bb of the body typically have the
    same loop_father, and if the doacross loop isn't inside of some other loop
    and the body is noreturn as well, both are part of loop 0.  The problematic
    case is when the entry_bb is inside of some deeper loop, but the body,
because
    it falls through into EXIT, has loop 0 as loop_father.  l0_bb is created by
    splitting the entry_bb fallthru edge into l1_bb, and because the two basic
blocks
    have different loop_father, a common loop is found for those (which is loop
0).
    Now, if the doacross loop has collapse == ordered or all the ordered >
collapse
    loops are guaranteed to iterate at least once, all is still fine, because
all
    enter the l1_bb (body), which doesn't return and so doesn't loop further
either.
    But, if one of those loops could loop 0 times, the user written body
wouldn't be
    reached at all, so unlike the expectations the whole construct actually
wouldn't
    be noreturn if entry_bb is encountered and decides to handle at least one
    iteration.

    In this case, we need to fix up, move the l0_bb into the same loop as
entry_bb
    (initially) and for the extra added loops put them as children of that same
    loop, rather than of loop 0.

    2023-03-17  Jakub Jelinek  <ja...@redhat.com>

            PR middle-end/108685
            * omp-expand.cc (expand_omp_for_ordered_loops): Add L0_BB argument,
            use its loop_father rather than BODY_BB's loop_father.
            (expand_omp_for_generic): Adjust expand_omp_for_ordered_loops
caller.
            If broken_loop with ordered > collapse and at least one of those
            extra loops aren't guaranteed to have at least one iteration,
change
            l0_bb's loop_father to entry_bb's loop_father.  Set cont_bb's
            loop_father to l0_bb's loop_father rather than l1_bb's.

            * c-c++-common/gomp/doacross-8.c: New test.

Reply via email to