On Wed, Dec 1, 2021 at 5:00 PM Aldy Hernandez <al...@redhat.com> wrote: > > On Wed, Dec 1, 2021 at 2:36 PM Richard Biener > <richard.guent...@gmail.com> wrote: > > > > On Tue, Nov 30, 2021 at 4:48 PM Aldy Hernandez via Gcc-patches > > <gcc-patches@gcc.gnu.org> wrote: > > > > > > We are currently restricting loop crossing paths in the generic copier > > > used by the back threader, but we should be able to handle them after > > > loop_done has completed. > > > > But this isn't a cost thing but a correctness (as in, can we update > > loops properly) > > thing. We are passing 'loop' down to copy_bbs and very much rely on > > seeing either BBs of that loop or copying complete subloops of it. > > > > You will likely see excess loop fixup caused by this or ICEs in case the > > caller of this function will not always set LOOPS_NEED_FIXUP > > (not that copy_bbs handling of loops is perfect). > > Ughh, fair enough. > > In which case at least I've commented in the PR what the problem is > here. Perhaps we could benefit from a BB copier that could handle > loops, which is way above my circle of competence ;-).
Well, more high level APIs exercising the copier are able to handle loops but it really depends on the high-level transform what you need to do ;) So for "loop-crossing" threadings it depends on the actual details what the "loop transform" is that you are doing. If you just rely on LOOPS_NEED_FIXUP then for example a #pragma GCC unroll 0 might be lost and that is - counter to PROP_after_loop_opts - also effective to prevent the RTL unroller from unrolling a loop. What's probably OK is for example changing the code to only prohibit copying loop headers: + /* We do not handle subloops, i.e. all the blocks must belong to the + same loop. */ + if (region[i]->loop_father != loop && region[i]->loop_father->header != region[i]) + return false; that should allow threadings covering an exit edge for example. It's reasonable (with some extra setup here!) to also handle the case of entering and exiting a loop (the "subloop" the comment mentions), but that requires us to do the loop structure copying/setup before copying the BBs (maybe look at gimple_duplicate_sese_tail). Note the above adjustment to handle exits does not necessarily result in correct ->loop_father assignment but LOOPS_NEED_FIXUP should be able to deal with it without using loop annotations. These kind of threads should also be OK when loop opts are not finished yet. Richard. > Aldy >