[llvm] r301239 - [LoopUnroll] Don't try to unroll non canonical loops.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 24 13:31:17 PDT 2017


On Mon, Apr 24, 2017 at 1:14 PM, Davide Italiano via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: davide
> Date: Mon Apr 24 15:14:11 2017
> New Revision: 301239
>
> URL: http://llvm.org/viewvc/llvm-project?rev=301239&view=rev
> Log:
> [LoopUnroll] Don't try to unroll non canonical loops.
>
> The current Loop Unroll implementation works with loops having a
> single latch that contains a conditional branch to a block outside
> the loop (the other successor is, by defition of latch, the header).
> If this precondition doesn't hold, avoid unrolling the loop as
> the code is not ready to handle such circumstances.
>
> Differential Revision:  https://reviews.llvm.org/D32261
>
> Added:
>     llvm/trunk/test/Transforms/LoopUnroll/not-rotated.ll
> Modified:
>     llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp
>
> Modified: llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp?rev=301239&r1=301238&r2=301239&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp (original)
> +++ llvm/trunk/lib/Transforms/Utils/LoopUnroll.cpp Mon Apr 24 15:14:11 2017
> @@ -318,6 +318,10 @@ bool llvm::UnrollLoop(Loop *L, unsigned
>      return false;
>    }
>
> +  // The current loop unroll pass can only unroll loops with a single latch
> +  // that's a conditional branch exiting the loop.
> +  // FIXME: The implementation can be extended to work with more complicated
> +  // cases, e.g. loops with multiple latches.
>    BasicBlock *Header = L->getHeader();
>    BranchInst *BI = dyn_cast<BranchInst>(LatchBlock->getTerminator());
>
> @@ -328,6 +332,17 @@ bool llvm::UnrollLoop(Loop *L, unsigned
>      return false;
>    }
>
> +  auto CheckSuccessors = [&](unsigned S1, unsigned S2) {
> +    return BI->getSuccessor(S1) == Header && !L->contains(BI->getSuccessor(S2));
> +
> +  };

Failed to squash commits properly.  r301241 should fix the newline.

-- 
Davide

"There are no solved problems; there are only problems that are more
or less solved" -- Henri Poincare


More information about the llvm-commits mailing list