This is an archive of the discontinued LLVM Phabricator instance.

Introduce fix-irreducible pass
ClosedPublic

Authored by sameerds on Apr 1 2020, 1:28 AM.

Details

Summary

An irreducible SCC is one which has multiple "header" blocks, i.e., blocks
with control-flow edges incident from outside the SCC. This pass converts an
irreducible SCC into a natural loop by introducing a single new header
block and redirecting all the edges on the original headers to this
new block.

This is a useful workaround for a limitation in the structurizer
which, which produces incorrect control flow in the presence of
irreducible regions. The AMDGPU backend provides an option to
enable this pass before the structurizer, which may eventually be
enabled by default.

Diff Detail

Event Timeline

sameerds created this revision.Apr 1 2020, 1:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 1 2020, 1:28 AM
arsenm added inline comments.Apr 1 2020, 9:06 AM
llvm/lib/Transforms/Utils/UnifyLoopExits.cpp
186 ↗(On Diff #254106)

Unrelated change

sameerds updated this revision to Diff 255223.Apr 5 2020, 10:54 PM

removed unrelated change; refactored out a dubious nullptr assignment

sameerds updated this revision to Diff 255224.Apr 5 2020, 11:00 PM

missing clang-format; sorry about that noise!

sameerds marked an inline comment as done.Apr 5 2020, 11:02 PM
sameerds updated this revision to Diff 255910.Apr 8 2020, 12:05 AM

added an ascii diagram illustrating the transformation

nhaehnle accepted this revision.Apr 14 2020, 2:57 AM

Two minor nitpicks, apart from that it LGTM

llvm/lib/Transforms/Utils/FixIrreducible.cpp
82

Nitpick: it's common to use 'class' for passes (not that it makes a real difference especially here...)

231–234

#ifndef NDEBUG for the verifyLoop calls?

This revision is now accepted and ready to land.Apr 14 2020, 2:57 AM
sameerds marked 2 inline comments as done.Apr 14 2020, 11:03 PM
sameerds added inline comments.
llvm/lib/Transforms/Utils/FixIrreducible.cpp
82

There are other examples with a struct, and some with a class whose entire body is public anyway. So decided to keep the struct.

231–234

The body of verifyLoop() is itself guarded with NDEBUG. There are places where it is called without guards, including LoopPass itself.

This revision was automatically updated to reflect the committed changes.

@sameerds Please can you take a look at http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/23136 - I think you introduced a crash on the nested.ll test on the windows EXPENSIVE_CHECK build bot

@sameerds Please can you take a look at http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/23136 - I think you introduced a crash on the nested.ll test on the windows EXPENSIVE_CHECK build bot

Yeah. The fix is up for review: https://reviews.llvm.org/D78544