Skip to content

Construction of forest in LoopAnalysis::run missing loop headers? #1305

Description

@jelvani

Hi,

I am trying to use the forest populated by LoopAnalysis::run. At the end of the function I am printing out the loop headers in forest like so:

  for (auto &[root, nodes] : forest) {
    std::cout << "Loop header: " << root->getName() << std::endl;
    for (auto *node : nodes) {
      std::cout << "  Child: " << node->getName() << std::endl;
    }
  }

But it seems that some loop headers are not being populated in forest, consider these 3 nested loops:

define i32 @src() {
entry:
  br label %for.body
for.cond.cleanup:
  ret i32 undef
for.body:
  br label %for.body.inner
for.cond.cleanup.inner:
  br i1 undef, label %for.cond.cleanup, label %for.body
for.cond.cleanup.inner.inner:
  br i1 undef, label %for.cond.cleanup.inner, label %for.body.inner
for.body.inner:
  br label %for.body.inner.inner
for.body.inner.inner:
  br i1 undef, label %for.cond.cleanup.inner.inner, label %for.body.inner.inner
}

The print out of forest gives

Loop header: %for.body.inner
  Child: %for.body.inner.inner
  Child: %for.cond.cleanup.inner.inner
Loop header: %for.body
  Child: %for.body.inner
  Child: %for.cond.cleanup.inner

so the innermost loop %for.body.inner.inner is not populated as a loop header.

Is there something missing in the logic here?
Or is forest supposed to look like this?

You can also try running llvms loop analysis pass which correctly identifies 3 loop headers:

opt -passes='print<loops>' test.ll

I am asking this in the contex of #1300. I am using forest to obtain loop headers which individual unroll bounds are applied to in order. I was expecting all the loop headers to be available there, but it seems like they are not for some cases. I have a temporary fix for now but I am not sure if this is even the correct way of doing such a thing.
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions