[PATCH] D93665: [LoopNest] Allow empty basic blocks without loops

Whitney Tsang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 22 15:26:18 PST 2020


Whitney added a comment.

> Alternatively, we could rely on SimplifyCFG to remote such empty BBs?

SimplifyCFG could be used to fold empty blocks, but we may want to know if the loop nest is perfect in between SimplifyCFG invocations. 
And there are times where we intentionally have empty blocks, e.g. dedicated exits.

> Would we want to allow such empty blocks between outer header and inner preheader as well?

It is being allowed in this patch,

  if (OuterLoopHeader != InnerLoopPreHeader) {
    const BasicBlock &SingleSucc =
        skipEmptyBlockUntil(OuterLoopHeader, InnerLoopPreHeader);
  
    // no conditional branch present
    if (&SingleSucc != InnerLoopPreHeader) {



================
Comment at: llvm/lib/Analysis/LoopNestAnalysis.cpp:223
+
+  SmallPtrSet<const BasicBlock *, 4> Visited;
+  const BasicBlock *BB = From->getSingleSuccessor();
----------------
Meinersbur wrote:
> To clarify: the `Visited` set is used to detect an infinite loop?
Yes, to avoid running into an infinite loop.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93665/new/

https://reviews.llvm.org/D93665



More information about the llvm-commits mailing list