[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 18:00:53 PDT 2020


efriedma added inline comments.


================
Comment at: llvm/lib/Transforms/Utils/LoopUnroll.cpp:315
 
-  // FIXME: Support loops without conditional latch and multiple exiting blocks.
-  if (!BI ||
-      (BI->isUnconditional() && (!HeaderBI || HeaderBI->isUnconditional() ||
-                                 L->getExitingBlock() != Header))) {
+  BranchInst *BI = nullptr;
+  if (L->isLoopExiting(LatchBlock))
----------------
Maybe call this ExitingBI?  And put a comment something like the following:

```
// A conditional branch which exits the loop, which can be optimized to an
// unconditional branch in the unrolled loop in some cases.
```

-----

We could probably allow unrolling even if ExitingBI is null, but we can leave that as a followup.


================
Comment at: llvm/lib/Transforms/Utils/LoopUnroll.cpp:316
+  BranchInst *BI = nullptr;
+  if (L->isLoopExiting(LatchBlock))
+    BI = dyn_cast_or_null<BranchInst>(LatchBlock->getTerminator());
----------------
Maybe `bool LatchIsExiting = L->isLoopExiting(LatchBlock);` 


================
Comment at: llvm/lib/Transforms/Utils/LoopUnroll.cpp:321
+  if (!BI) {
     LLVM_DEBUG(dbgs() << "  Can't unroll; loop not terminated by a conditional "
+                         "branch in latch or a single exiting block.\n");
----------------
The old code would reject any loop with a latch terminator that isn't a BranchInst.  You probably want to keep that check; I'm not sure the rest of the code handles that case correctly.


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