[PATCH] D80477: [LoopUnroll] Support loop with multiple exiting blocks

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 26 04:50:08 PDT 2020


Meinersbur added inline comments.


================
Comment at: llvm/lib/Transforms/Utils/LoopUnroll.cpp:339-340
   }
+  LLVM_DEBUG(dbgs() << "  Exiting Block = " << BI->getParent()->getName()
+                    << "\n");
 
----------------
Whitney wrote:
> Meinersbur wrote:
> > If this supports any number of exits, why the need to find a special one?
> The code expects one exiting block to be used to optimize away the conditional branch to the exit block.
> As mentioned by Florain, ideally we should apply it to all exiting block which conditions could be eliminated based on the unroll count.
> However, before this patch, if the latch is not one of the exiting blocks and there exists more than one exiting blocks, then it won't unroll.
> Now, these kind of loops can still be unrolled, and one of the exiting block conditional branch is optimized. 
IIUC, the only branch that could be optimized away are the branches that enforces the max trip count as determined by SCEV (`BackedgeTakenCount::getMax()`). There is no choice in optimizing an arbitrary branch. I am not sure about SCEV's capabilities here, whether it gives e.g. a `min(LimitByExit1,LimitByExit2)`. If so, then both of the exiting conditionals are necessary, as the trip count is computed in advance anyway.

If implemented more generally, we could partially unrolled even (potentially) infinite loops, but the exiting conditions has to be checked after every iteration.

In any case, arbitrarily choosing as single conditional is probably incorrect.


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