[PATCH] D80477: [LoopUnroll] Support loops with exiting block that is neither header nor latch.

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 26 21:46:24 PDT 2020


efriedma accepted this revision.
efriedma added a comment.

LGTM with a couple minor comments, but please give a little time for the other people who have looked at this to chime in.



================
Comment at: llvm/lib/Transforms/Utils/LoopUnroll.cpp:314
   BasicBlock *Header = L->getHeader();
-  BranchInst *HeaderBI = dyn_cast<BranchInst>(Header->getTerminator());
-  BranchInst *BI = dyn_cast<BranchInst>(LatchBlock->getTerminator());
-
-  // FIXME: Support loops without conditional latch and multiple exiting blocks.
-  if (!BI ||
-      (BI->isUnconditional() && (!HeaderBI || HeaderBI->isUnconditional() ||
-                                 L->getExitingBlock() != Header))) {
+  BranchInst *LatchBI =
+      dyn_cast_or_null<BranchInst>(LatchBlock->getTerminator());
----------------
Just `dyn_cast<>`: the latch always has a terminator


================
Comment at: llvm/lib/Transforms/Utils/LoopUnroll.cpp:324
+  else if (BasicBlock *ExitingBlock = L->getExitingBlock())
+    ExitingBI = dyn_cast_or_null<BranchInst>(ExitingBlock->getTerminator());
+  if (!LatchBI || !ExitingBI) {
----------------
Also `dyn_cast<>` here.  You only need dyn_cast_or_null if the argument can be null.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80477





More information about the llvm-commits mailing list