[llvm-dev] SimplifyCFG, llvm.loop and latch blocks

Michael Kruse via llvm-dev llvm-dev at lists.llvm.org
Sat Apr 10 20:10:29 PDT 2021


Preserving loop metadata like all metadata is only done on a
best-effort basis and there are several ways it can get disassociated
with the loop (see e.g. previous discussion
https://lists.llvm.org/pipermail/llvm-dev/2020-March/140121.html or
https://reviews.llvm.org/D95789). But that semantics, preservation is
just quality-of-implementation since we cannot make loop metadata
"more special" than other metadata. Which is unfortunate because some
loop properties can be seen as semantic requirement, such as the
vectorizer metadata that is emitted by `#pragma omp simd`. It should
not just be dropped without warning the user that the loop has not
been vectorized.

Michael


Am Do., 8. Apr. 2021 um 11:55 Uhr schrieb Jeroen Dobbelaere via
llvm-dev <llvm-dev at lists.llvm.org>:
>
> Hi Hiroshi,
>
> thank you for the reply.
>
> I am aware of the general rule that Metadata can be dropped.
> I am wondering if that should still hold for (at least) some of the loop annotations.
>
> In this particular case, there is also a 'real bug' where loop metadata indicating that a loop
> that is 'progressing but should not be unrolled' is, after some transformations, suddenly attached to
> a different, infinite loop (aka not progressing).
>
> Greetings,
>
> Jeroen Dobbelaere
>
> > From: Hiroshi Yamauchi
> >
> > I think that metadata / annotation preservation isn't perfect and is on a best-effort basis in general,
> > unfortunately, as the IR spec may say that >it's okay to drop them. But contributions would be welcome to improve it.
> >
> >> On Wed, Apr 7, 2021 at 10:17 AM Jeroen Dobbelaere via llvm-dev <mailto:llvm-dev at lists.llvm.org> wrote:
> >> Hi all,
> >>
> >> https://llvm.org/docs/LangRef.html#llvm-loop  states that a llvm.loop is put on the 'branch instruction of the loop's latch block'.
> >>
> >> With 'SimplifyCFG', I have come in a situation where a !llvm.loop is associated to
> >> a basicblock that is found to be a latch block for two different loops.
> >>
> >> The original annotation of one of those loops disappeared in the process.
> >> (See  https://www.godbolt.org/z/5r1T5e9fs and look for the disappearing !llvm.loop !10  in BB 'do.cond')
> >>
> >> Then later on,  'Canonicalize natural loops' splits the latch block up, so that it now is only
> >> the latch block for a single loop, but the original annotation is moved to the wrong loop.
> >>
> >> Questions:
> >> - The branch in 'do.cond' is simplified, but I have the impression that at the same time, the loop annotation is omitted.
> >>   This sounds like a bug ?
> >> - Is it a correct assumption that we should not merge blocks if both have a branch instruction with a !llvm.loop annotation set ?
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


More information about the llvm-dev mailing list