diff options
author | Davide Italiano <davide@freebsd.org> | 2017-08-28 20:29:33 +0000 |
---|---|---|
committer | Davide Italiano <davide@freebsd.org> | 2017-08-28 20:29:33 +0000 |
commit | 20cb7e887f00b097b632b9732ea40710ba6a8bba (patch) | |
tree | 5739601d3f9b85e3ab08fdd74c1cbb3f9dedf6a0 /llvm/lib/Transforms/Utils/LoopUnroll.cpp | |
parent | 0f76a35c5e3c2585179e7787f046519ce241129d (diff) | |
download | llvm-20cb7e887f00b097b632b9732ea40710ba6a8bba.zip llvm-20cb7e887f00b097b632b9732ea40710ba6a8bba.tar.gz llvm-20cb7e887f00b097b632b9732ea40710ba6a8bba.tar.bz2 |
[LoopUnroll] Properly update loop structure in case of successful peeling.
When peeling kicks in, it updates the loop preheader.
Later, a successful full unroll of the loop needs to update a PHI
which i-th argument comes from the loop preheader, so it'd better look
at the correct block. Fixes PR33437.
Differential Revision: https://reviews.llvm.org/D37153
llvm-svn: 311922
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUnroll.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUnroll.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp index 835f439..7759ac7 100644 --- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp @@ -396,8 +396,19 @@ bool llvm::UnrollLoop(Loop *L, unsigned Count, unsigned TripCount, bool Force, "Did not expect runtime trip-count unrolling " "and peeling for the same loop"); - if (PeelCount) - peelLoop(L, PeelCount, LI, SE, DT, AC, PreserveLCSSA); + if (PeelCount) { + bool Peeled = peelLoop(L, PeelCount, LI, SE, DT, AC, PreserveLCSSA); + + // Successful peeling may result in a change in the loop preheader/trip + // counts. If we later unroll the loop, we want these to be updated. + if (Peeled) { + BasicBlock *ExitingBlock = L->getExitingBlock(); + assert(ExitingBlock && "Loop without exiting block?"); + Preheader = L->getLoopPreheader(); + TripCount = SE->getSmallConstantTripCount(L, ExitingBlock); + TripMultiple = SE->getSmallConstantTripMultiple(L, ExitingBlock); + } + } // Loops containing convergent instructions must have a count that divides // their TripMultiple. |