Index: lib/Transforms/Utils/LoopUnrollPeel.cpp =================================================================== --- lib/Transforms/Utils/LoopUnrollPeel.cpp +++ lib/Transforms/Utils/LoopUnrollPeel.cpp @@ -229,6 +229,19 @@ if (!L->empty()) return; + // If the user provided a peel count, use that. + bool UserPeelCount = UnrollForcePeelCount.getNumOccurrences() > 0; + if (UserPeelCount) { + DEBUG(dbgs() << "Force-peeling first " << UnrollForcePeelCount + << " iterations.\n"); + UP.PeelCount = UnrollForcePeelCount; + return; + } + + // Skip peeling if it's disabled. + if (!UP.AllowPeeling) + return; + // Here we try to get rid of Phis which become invariants after 1, 2, ..., N // iterations of the loop. For this we compute the number for iterations after // which every Phi is guaranteed to become an invariant, and try to peel the @@ -274,21 +287,12 @@ if (TripCount) return; - // If the user provided a peel count, use that. - bool UserPeelCount = UnrollForcePeelCount.getNumOccurrences() > 0; - if (UserPeelCount) { - DEBUG(dbgs() << "Force-peeling first " << UnrollForcePeelCount - << " iterations.\n"); - UP.PeelCount = UnrollForcePeelCount; - return; - } - // If we don't know the trip count, but have reason to believe the average // trip count is low, peeling should be beneficial, since we will usually // hit the peeled section. // We only do this in the presence of profile information, since otherwise // our estimates of the trip count are not reliable enough. - if (UP.AllowPeeling && L->getHeader()->getParent()->hasProfileData()) { + if (L->getHeader()->getParent()->hasProfileData()) { Optional PeelCount = getLoopEstimatedTripCount(L); if (!PeelCount) return; Index: test/Transforms/LoopUnroll/peel-loop-not-forced.ll =================================================================== --- test/Transforms/LoopUnroll/peel-loop-not-forced.ll +++ test/Transforms/LoopUnroll/peel-loop-not-forced.ll @@ -1,4 +1,5 @@ ; RUN: opt < %s -S -loop-unroll -unroll-threshold=30 | FileCheck %s +; RUN: opt < %s -S -loop-unroll -unroll-threshold=30 -unroll-allow-peeling=false | FileCheck %s --check-prefix=DISABLE define i32 @invariant_backedge_1(i32 %a, i32 %b) { ; CHECK-LABEL: @invariant_backedge_1 @@ -7,6 +8,8 @@ ; CHECK: loop: ; CHECK: %i = phi ; CHECK: %sum = phi +; DISABLE-LABEL: @invariant_backedge_1 +; DISABLE-NOT: loop.peel: entry: br label %loop