Index: llvm/lib/Transforms/Utils/LoopPeel.cpp =================================================================== --- llvm/lib/Transforms/Utils/LoopPeel.cpp +++ llvm/lib/Transforms/Utils/LoopPeel.cpp @@ -13,6 +13,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" +#include "llvm/Analysis/IVDescriptors.h" #include "llvm/Analysis/Loads.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/LoopIterator.h" @@ -467,6 +468,101 @@ }); } +// When a loop contains an accumulator, an initial identity operation +// may be avoided by peeling a single time. For example, consider this loop +// int Total = 0; +// int Product = 1; +// for (I = 0; I < 100000; ++I) { +// Total += foo(I); +// Product *= bar(I); +// } +// Peeling a single time will avoid the initial addtion and multiplication: +// int Total = foo(I); +// int Product = bar(I); +// for (I = 1; I < 100000; ++I) { +// Total += foo(I); +// Product *= bar(I); +// } +// This may work for +=, *=, &&= and ||= depending on initial value. +// +class IdentityOpPeeler { +public: + IdentityOpPeeler(Loop &L, ScalarEvolution &SE) : L(L), SE(SE) { + assert(canPeel(&L) && L.getHeader() && "expected peelable loop"); + } + bool shouldPeelOnce() { + return any_of(L.getHeader()->phis(), + [&](PHINode &Phi) { return isAccumulatorPhi(Phi); }); + } + +protected: + // Return true if \p Phi in not an induction variable and is an accumulator + // that starts with an identity operation + bool isAccumulatorPhi(PHINode &Phi) const { + if (&Phi == L.getInductionVariable(SE)) + return false; + + // Return the incoming constant value from \p BB or nullptr + auto constIn = [&](BasicBlock *BB, bool) -> Constant * { + if (L.contains(BB)) + // not a value coming from outside the loop + return nullptr; + return dyn_cast(Phi.getIncomingValueForBlock(BB)); + }; + + // find a single constant value coming from outside the loop + if (Constant *C = find_singleton(Phi.blocks(), constIn, true)) { + if (ConstantFP *CFP = dyn_cast(C)) + return CFP->isZeroValue() && any_of(Phi.users(), [&](User *U) -> bool { + if (beneficial(*U, Phi, Instruction::FAdd)) + return true; + // M += may be expressed using the FMulAdd + // intrinsic with arguments (M, M, 0) + Instruction *I = dyn_cast(U); + return I && RecurrenceDescriptor::isFMulAddIntrinsic(I) && + I->getOperand(2) == Φ + }); + + if (ConstantInt *CI = dyn_cast(C)) { + BinaryOperator::BinaryOps Op; + if (CI->isZeroValue()) + Op = (CI->getBitWidth() == 1) ? Instruction::Or : Instruction::Add; + else if (CI->isOneValue()) + Op = (CI->getBitWidth() == 1) ? Instruction::And : Instruction::Mul; + else + return false; + + return any_of(Phi.users(), [&](const User *U) -> bool { + return beneficial(*U, Phi, Op); + }); + } + } + return false; + } + + // Peeling may be beneficial for a use in the loop with operator \p Op. + bool beneficial(const User &U, const PHINode &Phi, + const BinaryOperator::BinaryOps Op) const { + if (const Instruction *I = dyn_cast(&U)) + if (L.contains(I->getParent())) + if (const BinaryOperator *BO = dyn_cast(I)) + return (BO->getOpcode() == Op) && + // SCEV might not recognize an induction variable so assume it + // is only beneficial if the other operand is not a constant + (!isa( + BO->getOperand(BO->getOperand(0) == &Phi ? 1 : 0))) && + // try not to get in the way of the vectorizer by seeing if the + // count of the loop multiplied by the size is divisible by 128 + (SE.getSmallConstantMaxTripCount(&L) == 0 || + SE.getSmallConstantMaxTripCount(&L) * + Phi.getType()->getScalarSizeInBits() % 128 != + 0); + return false; + } + + const Loop &L; + ScalarEvolution &SE; +}; // Return the number of iterations we want to peel off. void llvm::computePeelCount(Loop *L, unsigned LoopSize, @@ -539,6 +635,9 @@ if (DesiredPeelCount == 0) DesiredPeelCount = peelToTurnInvariantLoadsDerefencebale(*L, DT, AC); + if (DesiredPeelCount == 0 && MaxPeelCount) + DesiredPeelCount = IdentityOpPeeler(*L, SE).shouldPeelOnce() ? 1 : 0; + if (DesiredPeelCount > 0) { DesiredPeelCount = std::min(DesiredPeelCount, MaxPeelCount); // Consider max peel count limitation. Index: llvm/test/Transforms/LoopUnroll/AArch64/runtime-loop.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/AArch64/runtime-loop.ll +++ llvm/test/Transforms/LoopUnroll/AArch64/runtime-loop.ll @@ -24,7 +24,7 @@ for.body: ; preds = %for.body, %entry %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ] - %sum.02 = phi i32 [ %add, %for.body ], [ 0, %entry ] + %sum.02 = phi i32 [ %add, %for.body ], [ 1, %entry ] %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv %0 = load i32, ptr %arrayidx, align 4 %add = add nsw i32 %0, %sum.02 Index: llvm/test/Transforms/LoopUnroll/ARM/multi-blocks.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/ARM/multi-blocks.ll +++ llvm/test/Transforms/LoopUnroll/ARM/multi-blocks.ll @@ -23,7 +23,7 @@ ; CHECK: for.cond.cleanup.loopexit.unr-lcssa: ; CHECK-NEXT: [[TEMP_1_LCSSA_PH:%.*]] = phi i32 [ undef, [[FOR_BODY_PREHEADER]] ], [ [[TEMP_1_LCSSA_PH_PH]], [[FOR_COND_CLEANUP_LOOPEXIT_UNR_LCSSA_LOOPEXIT:%.*]] ] ; CHECK-NEXT: [[J_010_UNR:%.*]] = phi i32 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[J_010_UNR_PH]], [[FOR_COND_CLEANUP_LOOPEXIT_UNR_LCSSA_LOOPEXIT]] ] -; CHECK-NEXT: [[TEMP_09_UNR:%.*]] = phi i32 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[TEMP_09_UNR_PH]], [[FOR_COND_CLEANUP_LOOPEXIT_UNR_LCSSA_LOOPEXIT]] ] +; CHECK-NEXT: [[TEMP_09_UNR:%.*]] = phi i32 [ 1, [[FOR_BODY_PREHEADER]] ], [ [[TEMP_09_UNR_PH]], [[FOR_COND_CLEANUP_LOOPEXIT_UNR_LCSSA_LOOPEXIT]] ] ; CHECK-NEXT: [[LCMP_MOD:%.*]] = icmp ne i32 [[XTRAITER]], 0 ; CHECK-NEXT: br i1 [[LCMP_MOD]], label [[FOR_BODY_EPIL_PREHEADER:%.*]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]] ; CHECK: for.body.epil.preheader: @@ -83,7 +83,7 @@ ; CHECK-NEXT: ret void ; CHECK: for.body: ; CHECK-NEXT: [[J_010:%.*]] = phi i32 [ 0, [[FOR_BODY_PREHEADER_NEW]] ], [ [[INC_3]], [[FOR_INC_3]] ] -; CHECK-NEXT: [[TEMP_09:%.*]] = phi i32 [ 0, [[FOR_BODY_PREHEADER_NEW]] ], [ [[TEMP_1_3]], [[FOR_INC_3]] ] +; CHECK-NEXT: [[TEMP_09:%.*]] = phi i32 [ 1, [[FOR_BODY_PREHEADER_NEW]] ], [ [[TEMP_1_3]], [[FOR_INC_3]] ] ; CHECK-NEXT: [[NITER:%.*]] = phi i32 [ 0, [[FOR_BODY_PREHEADER_NEW]] ], [ [[NITER_NEXT_3:%.*]], [[FOR_INC_3]] ] ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[CONDITION]], i32 [[J_010]] ; CHECK-NEXT: [[I:%.*]] = load i32, ptr [[ARRAYIDX]], align 4 @@ -154,7 +154,7 @@ for.body: ; preds = %for.inc, %for.body.preheader %j.010 = phi i32 [ %inc, %for.inc ], [ 0, %for.body.preheader ] - %temp.09 = phi i32 [ %temp.1, %for.inc ], [ 0, %for.body.preheader ] + %temp.09 = phi i32 [ %temp.1, %for.inc ], [ 1, %for.body.preheader ] %arrayidx = getelementptr inbounds i32, ptr %Condition, i32 %j.010 %i = load i32, ptr %arrayidx, align 4 %tobool = icmp eq i32 %i, 0 @@ -182,7 +182,7 @@ ; CHECK-NEXT: br label [[FOR_BODY:%.*]] ; CHECK: for.body: ; CHECK-NEXT: [[J_016:%.*]] = phi i32 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[INC_3:%.*]], [[IF_END_3:%.*]] ] -; CHECK-NEXT: [[TEMP_015:%.*]] = phi i32 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[TEMP_0_ADD_3:%.*]], [[IF_END_3]] ] +; CHECK-NEXT: [[TEMP_015:%.*]] = phi i32 [ 1, [[FOR_BODY_PREHEADER]] ], [ [[TEMP_0_ADD_3:%.*]], [[IF_END_3]] ] ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[INPUT:%.*]], i32 [[J_016]] ; CHECK-NEXT: [[I:%.*]] = load i32, ptr [[ARRAYIDX]], align 4 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i32 [[I]], 65535 @@ -255,7 +255,7 @@ for.body: ; preds = %if.end, %for.body.preheader %j.016 = phi i32 [ %inc, %if.end ], [ 0, %for.body.preheader ] - %temp.015 = phi i32 [ %temp.0.add, %if.end ], [ 0, %for.body.preheader ] + %temp.015 = phi i32 [ %temp.0.add, %if.end ], [ 1, %for.body.preheader ] %arrayidx = getelementptr inbounds i32, ptr %Input, i32 %j.016 %i = load i32, ptr %arrayidx, align 4 %cmp1 = icmp ugt i32 %i, 65535 @@ -286,7 +286,7 @@ ; CHECK-NEXT: br label [[FOR_BODY:%.*]] ; CHECK: for.body: ; CHECK-NEXT: [[J_022:%.*]] = phi i32 [ [[INC:%.*]], [[IF_END5:%.*]] ], [ 0, [[FOR_BODY_PREHEADER]] ] -; CHECK-NEXT: [[TEMP_021:%.*]] = phi i32 [ [[TEMP_0_ADD:%.*]], [[IF_END5]] ], [ 0, [[FOR_BODY_PREHEADER]] ] +; CHECK-NEXT: [[TEMP_021:%.*]] = phi i32 [ [[TEMP_0_ADD:%.*]], [[IF_END5]] ], [ 1, [[FOR_BODY_PREHEADER]] ] ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[CONDITION:%.*]], i32 [[J_022]] ; CHECK-NEXT: [[I:%.*]] = load i32, ptr [[ARRAYIDX]], align 4 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i32 [[I]], 65535 @@ -320,7 +320,7 @@ for.body: ; preds = %if.end5, %for.body.preheader %j.022 = phi i32 [ %inc, %if.end5 ], [ 0, %for.body.preheader ] - %temp.021 = phi i32 [ %temp.0.add, %if.end5 ], [ 0, %for.body.preheader ] + %temp.021 = phi i32 [ %temp.0.add, %if.end5 ], [ 1, %for.body.preheader ] %arrayidx = getelementptr inbounds i32, ptr %Condition, i32 %j.022 %i = load i32, ptr %arrayidx, align 4 %cmp1 = icmp ugt i32 %i, 65535 @@ -371,7 +371,7 @@ ; CHECK-NEXT: [[TEMP_1_LCSSA_PH:%.*]] = phi i32 [ undef, [[FOR_BODY_LR_PH]] ], [ [[TEMP_1_LCSSA_PH_PH]], [[FOR_COND_CLEANUP_LOOPEXIT_UNR_LCSSA_LOOPEXIT:%.*]] ] ; CHECK-NEXT: [[I_UNR:%.*]] = phi i32 [ [[DOTPRE]], [[FOR_BODY_LR_PH]] ], [ [[I_UNR_PH]], [[FOR_COND_CLEANUP_LOOPEXIT_UNR_LCSSA_LOOPEXIT]] ] ; CHECK-NEXT: [[J_027_UNR:%.*]] = phi i32 [ 1, [[FOR_BODY_LR_PH]] ], [ [[J_027_UNR_PH]], [[FOR_COND_CLEANUP_LOOPEXIT_UNR_LCSSA_LOOPEXIT]] ] -; CHECK-NEXT: [[TEMP_026_UNR:%.*]] = phi i32 [ 0, [[FOR_BODY_LR_PH]] ], [ [[TEMP_026_UNR_PH]], [[FOR_COND_CLEANUP_LOOPEXIT_UNR_LCSSA_LOOPEXIT]] ] +; CHECK-NEXT: [[TEMP_026_UNR:%.*]] = phi i32 [ 1, [[FOR_BODY_LR_PH]] ], [ [[TEMP_026_UNR_PH]], [[FOR_COND_CLEANUP_LOOPEXIT_UNR_LCSSA_LOOPEXIT]] ] ; CHECK-NEXT: [[LCMP_MOD:%.*]] = icmp ne i32 [[XTRAITER]], 0 ; CHECK-NEXT: br i1 [[LCMP_MOD]], label [[FOR_BODY_EPIL_PREHEADER:%.*]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]] ; CHECK: for.body.epil.preheader: @@ -462,7 +462,7 @@ ; CHECK: for.body: ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[DOTPRE]], [[FOR_BODY_LR_PH_NEW]] ], [ [[I2_3]], [[FOR_INC_3]] ] ; CHECK-NEXT: [[J_027:%.*]] = phi i32 [ 1, [[FOR_BODY_LR_PH_NEW]] ], [ [[INC_3]], [[FOR_INC_3]] ] -; CHECK-NEXT: [[TEMP_026:%.*]] = phi i32 [ 0, [[FOR_BODY_LR_PH_NEW]] ], [ [[TEMP_1_3]], [[FOR_INC_3]] ] +; CHECK-NEXT: [[TEMP_026:%.*]] = phi i32 [ 1, [[FOR_BODY_LR_PH_NEW]] ], [ [[TEMP_1_3]], [[FOR_INC_3]] ] ; CHECK-NEXT: [[NITER:%.*]] = phi i32 [ 0, [[FOR_BODY_LR_PH_NEW]] ], [ [[NITER_NEXT_3:%.*]], [[FOR_INC_3]] ] ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[CONDITION]], i32 [[J_027]] ; CHECK-NEXT: [[I1:%.*]] = load i32, ptr [[ARRAYIDX]], align 4 @@ -575,7 +575,7 @@ for.body: ; preds = %for.inc, %for.body.lr.ph %i = phi i32 [ %.pre, %for.body.lr.ph ], [ %i2, %for.inc ] %j.027 = phi i32 [ 1, %for.body.lr.ph ], [ %inc, %for.inc ] - %temp.026 = phi i32 [ 0, %for.body.lr.ph ], [ %temp.1, %for.inc ] + %temp.026 = phi i32 [ 1, %for.body.lr.ph ], [ %temp.1, %for.inc ] %arrayidx = getelementptr inbounds i32, ptr %Condition, i32 %j.027 %i1 = load i32, ptr %arrayidx, align 4 %cmp1 = icmp ugt i32 %i1, 65535 @@ -614,7 +614,7 @@ ; CHECK-NEXT: br label [[FOR_BODY:%.*]] ; CHECK: for.body: ; CHECK-NEXT: [[J_026:%.*]] = phi i32 [ [[INC:%.*]], [[FOR_INC:%.*]] ], [ 1, [[FOR_BODY_PREHEADER]] ] -; CHECK-NEXT: [[TEMP_025:%.*]] = phi i32 [ [[TEMP_1:%.*]], [[FOR_INC]] ], [ 0, [[FOR_BODY_PREHEADER]] ] +; CHECK-NEXT: [[TEMP_025:%.*]] = phi i32 [ [[TEMP_1:%.*]], [[FOR_INC]] ], [ 1, [[FOR_BODY_PREHEADER]] ] ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[INPUT:%.*]], i32 [[J_026]] ; CHECK-NEXT: [[I:%.*]] = load i32, ptr [[ARRAYIDX]], align 4 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[I]], [[TEMP_025]] @@ -658,7 +658,7 @@ for.body: ; preds = %for.inc, %for.body.preheader %j.026 = phi i32 [ %inc, %for.inc ], [ 1, %for.body.preheader ] - %temp.025 = phi i32 [ %temp.1, %for.inc ], [ 0, %for.body.preheader ] + %temp.025 = phi i32 [ %temp.1, %for.inc ], [ 1, %for.body.preheader ] %arrayidx = getelementptr inbounds i32, ptr %Input, i32 %j.026 %i = load i32, ptr %arrayidx, align 4 %add = add i32 %i, %temp.025 Index: llvm/test/Transforms/LoopUnroll/ARM/v6munroll.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/ARM/v6munroll.ll +++ llvm/test/Transforms/LoopUnroll/ARM/v6munroll.ll @@ -86,10 +86,10 @@ %x.addr.062 = phi ptr [ %incdec.ptr, %for.inc ], [ %x, %for.body.preheader ] %y.addr.061 = phi ptr [ %incdec.ptr19, %for.inc ], [ %y, %for.body.preheader ] %rhs_cols_idx.060 = phi i32 [ %dec, %for.inc ], [ %n, %for.body.preheader ] - %res11.059 = phi i32 [ %add18, %for.inc ], [ 0, %for.body.preheader ] - %res10.058 = phi i32 [ %add16, %for.inc ], [ 0, %for.body.preheader ] - %res01.057 = phi i32 [ %add8, %for.inc ], [ 0, %for.body.preheader ] - %res00.056 = phi i32 [ %add, %for.inc ], [ 0, %for.body.preheader ] + %res11.059 = phi i32 [ %add18, %for.inc ], [ 1, %for.body.preheader ] + %res10.058 = phi i32 [ %add16, %for.inc ], [ 1, %for.body.preheader ] + %res01.057 = phi i32 [ %add8, %for.inc ], [ 1, %for.body.preheader ] + %res00.056 = phi i32 [ %add, %for.inc ], [ 1, %for.body.preheader ] %0 = load i32, ptr %x.addr.062, align 4 %1 = load i32, ptr %y.addr.061, align 4 %conv5 = and i32 %1, 255 Index: llvm/test/Transforms/LoopUnroll/PowerPC/a2-unrolling.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/PowerPC/a2-unrolling.ll +++ llvm/test/Transforms/LoopUnroll/PowerPC/a2-unrolling.ll @@ -8,7 +8,7 @@ for.body: ; preds = %for.body, %entry %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ] - %sum.02 = phi i32 [ %add, %for.body ], [ 0, %entry ] + %sum.02 = phi i32 [ %add, %for.body ], [ 1, %entry ] %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv %0 = load i32, ptr %arrayidx, align 4 %add = add nsw i32 %0, %sum.02 Index: llvm/test/Transforms/LoopUnroll/X86/partial.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/X86/partial.ll +++ llvm/test/Transforms/LoopUnroll/X86/partial.ll @@ -77,7 +77,7 @@ for.body: ; preds = %entry, %for.body %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ] - %reduction.026 = phi i16 [ %add14, %for.body ], [ 0, %entry ] + %reduction.026 = phi i16 [ %add14, %for.body ], [ 1, %entry ] %arrayidx = getelementptr inbounds i16, ptr %arr, i64 %indvars.iv %0 = load i16, ptr %arrayidx, align 2 %mul = shl i16 %0, 1 Index: llvm/test/Transforms/LoopUnroll/followup.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/followup.ll +++ llvm/test/Transforms/LoopUnroll/followup.ll @@ -13,7 +13,7 @@ for.body: ; preds = %for.body, %entry %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ] - %sum.02 = phi i32 [ %add, %for.body ], [ 0, %entry ] + %sum.02 = phi i32 [ %add, %for.body ], [ 1, %entry ] %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv %0 = load i32, ptr %arrayidx, align 4 %add = add nsw i32 %0, %sum.02 Index: llvm/test/Transforms/LoopUnroll/partially-unroll-unconditional-latch.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/partially-unroll-unconditional-latch.ll +++ llvm/test/Transforms/LoopUnroll/partially-unroll-unconditional-latch.ll @@ -1,5 +1,5 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py -; RUN: opt -passes=loop-unroll -unroll-allow-partial -S %s -verify-loop-info -verify-dom-info -verify-loop-lcssa | FileCheck %s +; RUN: opt -passes=loop-unroll -unroll-allow-partial -S %s -verify-loop-info -verify-dom-info -verify-loop-lcssa -unroll-allow-peeling=false | FileCheck %s @table = internal unnamed_addr global [344 x i32] zeroinitializer, align 16 Index: llvm/test/Transforms/LoopUnroll/peel-loop-identity-op.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/LoopUnroll/peel-loop-identity-op.ll @@ -0,0 +1,57 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -S -passes=loop-unroll -unroll-allow-peeling | FileCheck %s + +declare i32 @g() + +define i32 @f() { +; Preheader: +; CHECK-LABEL: @f( +; CHECK-NEXT: entry: +; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]] +; CHECK: for.body.peel.begin: +; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]] +; CHECK: for.body.peel: +; CHECK-NEXT: [[CALL_PEEL:%.*]] = tail call signext i32 @g(i32 noundef signext 0) +; CHECK-NEXT: [[ADD_PEEL:%.*]] = add nsw i32 [[CALL_PEEL]], 0 +; CHECK-NEXT: [[INC_PEEL:%.*]] = add nuw nsw i32 0, 1 +; CHECK-NEXT: [[EXITCOND_PEEL:%.*]] = icmp ne i32 [[INC_PEEL]], 999 +; CHECK-NEXT: br i1 [[EXITCOND_PEEL]], label [[FOR_BODY_PEEL_NEXT:%.*]], label [[FOR_COND_CLEANUP:%.*]] +; CHECK: for.body.peel.next: +; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT1:%.*]] +; CHECK: for.body.peel.next1: +; CHECK-NEXT: br label [[ENTRY_PEEL_NEWPH:%.*]] +; CHECK: entry.peel.newph: +; CHECK-NEXT: br label [[FOR_BODY:%.*]] +; CHECK: for.body: +; CHECK-NEXT: [[J_05:%.*]] = phi i32 [ [[INC_PEEL]], [[ENTRY_PEEL_NEWPH]] ], [ [[INC:%.*]], [[FOR_BODY]] ] +; CHECK-NEXT: [[TOTAL_04:%.*]] = phi i32 [ [[ADD_PEEL]], [[ENTRY_PEEL_NEWPH]] ], [ [[ADD:%.*]], [[FOR_BODY]] ] +; CHECK-NEXT: [[CALL:%.*]] = tail call signext i32 @g(i32 noundef signext [[J_05]]) +; CHECK-NEXT: [[ADD]] = add nsw i32 [[CALL]], [[TOTAL_04]] +; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[J_05]], 1 +; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[INC]], 999 +; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], !llvm.loop [[LOOP0:![0-9]+]] +; CHECK: for.cond.cleanup.loopexit: +; CHECK-NEXT: [[ADD_LCSSA_PH:%.*]] = phi i32 [ [[ADD]], [[FOR_BODY]] ] +; CHECK-NEXT: br label [[FOR_COND_CLEANUP]] +; CHECK: for.cond.cleanup: +; CHECK-NEXT: [[ADD_LCSSA:%.*]] = phi i32 [ [[ADD_PEEL]], [[FOR_BODY_PEEL]] ], [ [[ADD_LCSSA_PH]], [[FOR_COND_CLEANUP_LOOPEXIT]] ] +; CHECK-NEXT: ret i32 [[ADD_LCSSA]] +; +entry: + br label %for.body + +; Loop: +for.body: ; preds = %entry, %for.body + %j.05 = phi i32 [ 0, %entry ], [ %inc, %for.body ] + %total.04 = phi i32 [ 0, %entry ], [ %add, %for.body ] + %call = tail call signext i32 @g(i32 noundef signext %j.05) + %add = add nsw i32 %call, %total.04 + %inc = add nuw nsw i32 %j.05, 1 + %exitcond = icmp ne i32 %inc, 999 + br i1 %exitcond, label %for.body, label %for.cond.cleanup + +; Exit blocks +for.cond.cleanup: ; preds = %for.body + %add.lcssa = phi i32 [ %add, %for.body ] + ret i32 %add.lcssa +} Index: llvm/test/Transforms/LoopUnroll/peel-loop-not-forced.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/peel-loop-not-forced.ll +++ llvm/test/Transforms/LoopUnroll/peel-loop-not-forced.ll @@ -187,7 +187,7 @@ %i = phi i32 [ 0, %entry ], [ %inc, %loop ] %phi.a = phi i32 [ %a, %entry ], [ %phi.b, %loop ] %phi.b = phi i32 [ %b, %entry ], [ %phi.a, %loop ] - %sum = phi i32 [ 0, %entry], [ %incsum, %loop ] + %sum = phi i32 [ 2, %entry], [ %incsum, %loop ] %incsum = add i32 %sum, %phi.a %inc = add i32 %i, 1 %cmp = icmp slt i32 %i, 1000 Index: llvm/test/Transforms/LoopUnroll/peel-to-turn-invariant-accesses-dereferenceable.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/peel-to-turn-invariant-accesses-dereferenceable.ll +++ llvm/test/Transforms/LoopUnroll/peel-to-turn-invariant-accesses-dereferenceable.ll @@ -90,7 +90,7 @@ ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]] ; CHECK: loop.header: ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ] -; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ] +; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ] ; CHECK-NEXT: br i1 [[C_1:%.*]], label [[THEN:%.*]], label [[EXIT_2:%.*]] ; CHECK: then: ; CHECK-NEXT: [[I:%.*]] = load i32, ptr [[INV:%.*]], align 4 @@ -122,7 +122,7 @@ loop.header: %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ] - %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop.latch ] + %sum = phi i32 [ 1, %entry ], [ %sum.next, %loop.latch ] br i1 %c.1, label %then, label %exit.2 then: @@ -162,7 +162,7 @@ ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]] ; CHECK: loop.header: ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ] -; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ] +; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ] ; CHECK-NEXT: [[I:%.*]] = load i32, ptr [[INV:%.*]], align 4 ; CHECK-NEXT: [[C_2:%.*]] = icmp ult i32 [[I]], 2 ; CHECK-NEXT: br i1 [[C_2]], label [[THEN:%.*]], label [[UNREACHABLE_EXIT:%.*]] @@ -187,7 +187,7 @@ loop.header: %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ] - %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop.latch ] + %sum = phi i32 [ 1, %entry ], [ %sum.next, %loop.latch ] %i = load i32, ptr %inv %c.2 = icmp ult i32 %i, 2 br i1 %c.2, label %then, label %unreachable.exit @@ -217,7 +217,7 @@ ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]] ; CHECK: loop.header: ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ] -; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ] +; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ] ; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[IV]], [[X:%.*]] ; CHECK-NEXT: br i1 [[C_1]], label [[THEN:%.*]], label [[ELSE:%.*]] ; CHECK: then: @@ -247,7 +247,7 @@ loop.header: %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ] - %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop.latch ] + %sum = phi i32 [ 1, %entry ], [ %sum.next, %loop.latch ] %c.1 = icmp eq i32 %iv, %x br i1 %c.1, label %then, label %else @@ -283,7 +283,7 @@ ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]] ; CHECK: loop.header: ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ] -; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ] +; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ] ; CHECK-NEXT: br i1 [[C_1:%.*]], label [[THEN:%.*]], label [[UNREACHABLE_EXIT:%.*]] ; CHECK: then: ; CHECK-NEXT: [[I:%.*]] = load i32, ptr [[INV:%.*]], align 4 @@ -309,7 +309,7 @@ loop.header: %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ] - %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop.latch ] + %sum = phi i32 [ 1, %entry ], [ %sum.next, %loop.latch ] br i1 %c.1, label %then, label %unreachable.exit then: @@ -340,7 +340,7 @@ ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]] ; CHECK: loop.header: ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ] -; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ] +; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ] ; CHECK-NEXT: [[I:%.*]] = load i32, ptr [[INV:%.*]], align 4 ; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[I]], 20 ; CHECK-NEXT: br i1 [[C_1]], label [[THEN:%.*]], label [[ELSE:%.*]] @@ -369,7 +369,7 @@ loop.header: %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ] - %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop.latch ] + %sum = phi i32 [ 1, %entry ], [ %sum.next, %loop.latch ] %i = load i32, ptr %inv %c.1 = icmp eq i32 %i, 20 br i1 %c.1, label %then, label %else @@ -406,7 +406,7 @@ ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]] ; CHECK: loop.header: ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ] -; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ] +; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ] ; CHECK-NEXT: br i1 [[C_1:%.*]], label [[THEN:%.*]], label [[DEOPT_EXIT:%.*]] ; CHECK: then: ; CHECK-NEXT: [[I:%.*]] = load i32, ptr [[INV:%.*]], align 4 @@ -432,7 +432,7 @@ loop.header: %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ] - %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop.latch ] + %sum = phi i32 [ 1, %entry ], [ %sum.next, %loop.latch ] br i1 %c.1, label %then, label %deopt.exit then: @@ -462,7 +462,7 @@ ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]] ; CHECK: loop.header: ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ] -; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ] +; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ] ; CHECK-NEXT: [[C_1:%.*]] = icmp ult i32 [[IV]], 1000 ; CHECK-NEXT: br i1 [[C_1]], label [[THEN:%.*]], label [[EXIT:%.*]] ; CHECK: then: @@ -487,7 +487,7 @@ loop.header: %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ] - %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop.latch ] + %sum = phi i32 [ 1, %entry ], [ %sum.next, %loop.latch ] %c.1 = icmp ult i32 %iv, 1000 br i1 %c.1, label %then, label %exit @@ -517,7 +517,7 @@ ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]] ; CHECK: loop.header: ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ] -; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ] +; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ] ; CHECK-NEXT: br i1 [[C_1:%.*]], label [[THEN:%.*]], label [[UNREACHABLE_EXIT:%.*]] ; CHECK: then: ; CHECK-NEXT: [[I:%.*]] = load i32, ptr [[INV:%.*]], align 4 @@ -542,7 +542,7 @@ loop.header: %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ] - %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop.latch ] + %sum = phi i32 [ 1, %entry ], [ %sum.next, %loop.latch ] br i1 %c.1, label %then, label %unreachable.exit then: @@ -574,7 +574,7 @@ ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]] ; CHECK: loop.header: ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ] -; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ] +; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP_LATCH]] ] ; CHECK-NEXT: br i1 [[C_1:%.*]], label [[THEN:%.*]], label [[UNREACHABLE_EXIT:%.*]] ; CHECK: then: ; CHECK-NEXT: [[I:%.*]] = load i32, ptr @glob, align 4 @@ -599,7 +599,7 @@ loop.header: %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ] - %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop.latch ] + %sum = phi i32 [ 1, %entry ], [ %sum.next, %loop.latch ] br i1 %c.1, label %then, label %unreachable.exit then: Index: llvm/test/Transforms/LoopUnroll/runtime-epilog-debuginfo.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/runtime-epilog-debuginfo.ll +++ llvm/test/Transforms/LoopUnroll/runtime-epilog-debuginfo.ll @@ -1,4 +1,4 @@ -; RUN: opt -passes=loop-unroll -unroll-runtime -unroll-runtime-epilog -S %s | FileCheck %s +; RUN: opt -passes=loop-unroll -unroll-runtime -unroll-runtime-epilog -unroll-allow-peeling=false -S %s | FileCheck %s ; Test that epilogue is tagged with the same debug information as original loop body rather than original loop exit. Index: llvm/test/Transforms/LoopUnroll/runtime-loop-at-most-two-exits.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/runtime-loop-at-most-two-exits.ll +++ llvm/test/Transforms/LoopUnroll/runtime-loop-at-most-two-exits.ll @@ -15,7 +15,7 @@ ; ENABLED-NEXT: br label [[HEADER:%.*]] ; ENABLED: header: ; ENABLED-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[ENTRY_NEW]] ], [ [[INDVARS_IV_NEXT_7:%.*]], [[FOR_BODY_7:%.*]] ] -; ENABLED-NEXT: [[SUM_02:%.*]] = phi i32 [ 0, [[ENTRY_NEW]] ], [ [[ADD_7:%.*]], [[FOR_BODY_7]] ] +; ENABLED-NEXT: [[SUM_02:%.*]] = phi i32 [ 1, [[ENTRY_NEW]] ], [ [[ADD_7:%.*]], [[FOR_BODY_7]] ] ; ENABLED-NEXT: [[NITER:%.*]] = phi i64 [ 0, [[ENTRY_NEW]] ], [ [[NITER_NEXT_7:%.*]], [[FOR_BODY_7]] ] ; ENABLED-NEXT: [[CMP:%.*]] = icmp eq i64 [[N]], 42 ; ENABLED-NEXT: br i1 [[CMP]], label [[FOR_EXIT2_LOOPEXIT:%.*]], label [[FOR_BODY:%.*]] @@ -91,7 +91,7 @@ ; ENABLED: for.end.unr-lcssa: ; ENABLED-NEXT: [[SUM_0_LCSSA_PH:%.*]] = phi i32 [ undef, [[ENTRY:%.*]] ], [ [[SUM_0_LCSSA_PH_PH]], [[FOR_END_UNR_LCSSA_LOOPEXIT]] ] ; ENABLED-NEXT: [[INDVARS_IV_UNR:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[INDVARS_IV_UNR_PH]], [[FOR_END_UNR_LCSSA_LOOPEXIT]] ] -; ENABLED-NEXT: [[SUM_02_UNR:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_02_UNR_PH]], [[FOR_END_UNR_LCSSA_LOOPEXIT]] ] +; ENABLED-NEXT: [[SUM_02_UNR:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[SUM_02_UNR_PH]], [[FOR_END_UNR_LCSSA_LOOPEXIT]] ] ; ENABLED-NEXT: [[LCMP_MOD:%.*]] = icmp ne i64 [[XTRAITER]], 0 ; ENABLED-NEXT: br i1 [[LCMP_MOD]], label [[HEADER_EPIL_PREHEADER:%.*]], label [[FOR_END:%.*]] ; ENABLED: header.epil.preheader: @@ -132,7 +132,7 @@ ; DISABLED-NEXT: br label [[HEADER:%.*]] ; DISABLED: header: ; DISABLED-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY:%.*]] ], [ 0, [[ENTRY:%.*]] ] -; DISABLED-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[FOR_BODY]] ], [ 0, [[ENTRY]] ] +; DISABLED-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[FOR_BODY]] ], [ 1, [[ENTRY]] ] ; DISABLED-NEXT: [[CMP:%.*]] = icmp eq i64 [[N:%.*]], 42 ; DISABLED-NEXT: br i1 [[CMP]], label [[FOR_EXIT2:%.*]], label [[FOR_BODY]] ; DISABLED: for.body: @@ -154,7 +154,7 @@ header: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ] - %sum.02 = phi i32 [ %add, %for.body ], [ 0, %entry ] + %sum.02 = phi i32 [ %add, %for.body ], [ 1, %entry ] %cmp = icmp eq i64 %n, 42 br i1 %cmp, label %for.exit2, label %for.body Index: llvm/test/Transforms/LoopUnroll/runtime-loop-multiple-exits.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/runtime-loop-multiple-exits.ll +++ llvm/test/Transforms/LoopUnroll/runtime-loop-multiple-exits.ll @@ -1,8 +1,8 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: -p -; RUN: opt < %s -passes=loop-unroll -unroll-runtime=true -unroll-runtime-epilog=true -unroll-runtime-multi-exit=true -verify-loop-lcssa -verify-dom-info -verify-loop-info -S | FileCheck %s -check-prefixes=CHECK,EPILOG -; RUN: opt < %s -passes=loop-unroll -unroll-runtime -unroll-count=2 -unroll-runtime-epilog=true -unroll-runtime-multi-exit=true -verify-loop-lcssa -verify-dom-info -verify-loop-info -S | FileCheck %s -check-prefixes=CHECK,EPILOG-BLOCK -; RUN: opt < %s -passes=loop-unroll -unroll-runtime=true -unroll-runtime-epilog=false -unroll-runtime-multi-exit=true -verify-loop-lcssa -verify-dom-info -verify-loop-info -S | FileCheck %s -check-prefixes=CHECK,PROLOG -; RUN: opt < %s -passes=loop-unroll -unroll-runtime -unroll-runtime-epilog=false -unroll-count=2 -unroll-runtime-multi-exit=true -verify-loop-lcssa -verify-dom-info -verify-loop-info -S | FileCheck %s -check-prefixes=CHECK,PROLOG-BLOCK +; RUN: opt < %s -passes=loop-unroll -unroll-runtime=true -unroll-runtime-epilog=true -unroll-runtime-multi-exit=true -verify-loop-lcssa -verify-dom-info -verify-loop-info -S -unroll-allow-peeling=false | FileCheck %s -check-prefixes=CHECK,EPILOG +; RUN: opt < %s -passes=loop-unroll -unroll-runtime -unroll-count=2 -unroll-runtime-epilog=true -unroll-runtime-multi-exit=true -verify-loop-lcssa -verify-dom-info -verify-loop-info -S -unroll-allow-peeling=false | FileCheck %s -check-prefixes=CHECK,EPILOG-BLOCK +; RUN: opt < %s -passes=loop-unroll -unroll-runtime=true -unroll-runtime-epilog=false -unroll-runtime-multi-exit=true -verify-loop-lcssa -verify-dom-info -verify-loop-info -S -unroll-allow-peeling=false | FileCheck %s -check-prefixes=CHECK,PROLOG +; RUN: opt < %s -passes=loop-unroll -unroll-runtime -unroll-runtime-epilog=false -unroll-count=2 -unroll-runtime-multi-exit=true -verify-loop-lcssa -verify-dom-info -verify-loop-info -S -unroll-allow-peeling=false | FileCheck %s -check-prefixes=CHECK,PROLOG-BLOCK ; REQUIRES: asserts Index: llvm/test/Transforms/LoopUnroll/runtime-loop.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/runtime-loop.ll +++ llvm/test/Transforms/LoopUnroll/runtime-loop.ll @@ -56,7 +56,7 @@ for.body: ; preds = %for.body, %entry %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ] - %sum.02 = phi i32 [ %add, %for.body ], [ 0, %entry ] + %sum.02 = phi i32 [ %add, %for.body ], [ 1, %entry ] %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv %0 = load i32, ptr %arrayidx, align 4 %add = add nsw i32 %0, %sum.02 @@ -66,7 +66,7 @@ br i1 %exitcond, label %for.end, label %for.body for.end: ; preds = %for.body, %entry - %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.body ] + %sum.0.lcssa = phi i32 [ 1, %entry ], [ %add, %for.body ] ret i32 %sum.0.lcssa } @@ -85,7 +85,7 @@ for.body: ; preds = %for.body, %entry %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] - %sum.01 = phi i32 [ 0, %entry ], [ %add, %for.body ] + %sum.01 = phi i32 [ 1, %entry ], [ %add, %for.body ] %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv %0 = load i32, ptr %arrayidx, align 4 %add = add nsw i32 %0, %sum.01 @@ -148,7 +148,7 @@ for.body: ; preds = %for.body, %entry %p.addr.05 = phi ptr [ %incdec.ptr, %for.body ], [ %p, %entry ] %len.addr.04 = phi i32 [ %sub, %for.body ], [ %len, %entry ] - %res.03 = phi i32 [ %add, %for.body ], [ 0, %entry ] + %res.03 = phi i32 [ %add, %for.body ], [ 1, %entry ] %incdec.ptr = getelementptr inbounds i16, ptr %p.addr.05, i64 1 %0 = load i16, ptr %p.addr.05, align 2 %conv = zext i16 %0 to i32 @@ -189,7 +189,7 @@ for.body: ; preds = %for.body, %entry %p.addr.05 = phi ptr [ %incdec.ptr, %for.body ], [ %p, %entry ] %len.addr.04 = phi i32 [ %sub, %for.body ], [ %len, %entry ] - %res.03 = phi i32 [ %add, %for.body ], [ 0, %entry ] + %res.03 = phi i32 [ %add, %for.body ], [ 1, %entry ] %incdec.ptr = getelementptr inbounds i16, ptr %p.addr.05, i64 1 %0 = load i16, ptr %p.addr.05, align 2 %conv = zext i16 %0 to i32 Index: llvm/test/Transforms/LoopUnroll/runtime-loop2.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/runtime-loop2.ll +++ llvm/test/Transforms/LoopUnroll/runtime-loop2.ll @@ -24,7 +24,7 @@ for.body: ; preds = %for.body, %entry %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ] - %sum.02 = phi i32 [ %add, %for.body ], [ 0, %entry ] + %sum.02 = phi i32 [ %add, %for.body ], [ 1, %entry ] %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv %0 = load i32, ptr %arrayidx, align 4 %add = add nsw i32 %0, %sum.02 Index: llvm/test/Transforms/LoopUnroll/runtime-loop3.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/runtime-loop3.ll +++ llvm/test/Transforms/LoopUnroll/runtime-loop3.ll @@ -21,7 +21,7 @@ br i1 %cmp28, label %for.body3, label %for.inc5 for.body3: ; preds = %for.cond1.preheader, %for.body3 - %indvars.iv = phi i64 [ %indvars.iv.next, %for.body3 ], [ 0, %for.cond1.preheader ] + %indvars.iv = phi i64 [ %indvars.iv.next, %for.body3 ], [ 1, %for.cond1.preheader ] %sum.19 = phi i32 [ %add4, %for.body3 ], [ %sum.012, %for.cond1.preheader ] %0 = add nsw i64 %indvars.iv, %indvars.iv16 %arrayidx = getelementptr inbounds i32, ptr %a, i64 %0 Index: llvm/test/Transforms/LoopUnroll/runtime-multiexit-heuristic.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/runtime-multiexit-heuristic.ll +++ llvm/test/Transforms/LoopUnroll/runtime-multiexit-heuristic.ll @@ -25,7 +25,7 @@ ; CHECK-NEXT: br label [[HEADER:%.*]] ; CHECK: header: ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[ENTRY_NEW]] ], [ [[INDVARS_IV_NEXT_7:%.*]], [[LATCH_7:%.*]] ] -; CHECK-NEXT: [[SUM_02:%.*]] = phi i32 [ 0, [[ENTRY_NEW]] ], [ [[ADD_7:%.*]], [[LATCH_7]] ] +; CHECK-NEXT: [[SUM_02:%.*]] = phi i32 [ 1, [[ENTRY_NEW]] ], [ [[ADD_7:%.*]], [[LATCH_7]] ] ; CHECK-NEXT: [[NITER:%.*]] = phi i64 [ 0, [[ENTRY_NEW]] ], [ [[NITER_NEXT_7:%.*]], [[LATCH_7]] ] ; CHECK-NEXT: br label [[FOR_EXITING_BLOCK:%.*]] ; CHECK: for.exiting_block: @@ -107,7 +107,7 @@ ; CHECK: latchexit.unr-lcssa: ; CHECK-NEXT: [[SUM_0_LCSSA_PH:%.*]] = phi i32 [ undef, [[ENTRY:%.*]] ], [ [[ADD_7]], [[LATCHEXIT_UNR_LCSSA_LOOPEXIT]] ] ; CHECK-NEXT: [[INDVARS_IV_UNR:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[INDVARS_IV_NEXT_7]], [[LATCHEXIT_UNR_LCSSA_LOOPEXIT]] ] -; CHECK-NEXT: [[SUM_02_UNR:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[ADD_7]], [[LATCHEXIT_UNR_LCSSA_LOOPEXIT]] ] +; CHECK-NEXT: [[SUM_02_UNR:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[ADD_7]], [[LATCHEXIT_UNR_LCSSA_LOOPEXIT]] ] ; CHECK-NEXT: [[LCMP_MOD_NOT:%.*]] = icmp eq i64 [[XTRAITER]], 0 ; CHECK-NEXT: br i1 [[LCMP_MOD_NOT]], label [[LATCHEXIT:%.*]], label [[HEADER_EPIL_PREHEADER:%.*]] ; CHECK: header.epil.preheader: @@ -148,7 +148,7 @@ ; NOUNROLL-NEXT: br label [[HEADER:%.*]] ; NOUNROLL: header: ; NOUNROLL-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LATCH:%.*]] ], [ 0, [[ENTRY:%.*]] ] -; NOUNROLL-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[LATCH]] ], [ 0, [[ENTRY]] ] +; NOUNROLL-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[LATCH]] ], [ 1, [[ENTRY]] ] ; NOUNROLL-NEXT: br label [[FOR_EXITING_BLOCK:%.*]] ; NOUNROLL: for.exiting_block: ; NOUNROLL-NEXT: [[CMP:%.*]] = icmp eq i64 [[N:%.*]], 42 @@ -180,7 +180,7 @@ ; ENABLED-NEXT: br label [[HEADER:%.*]] ; ENABLED: header: ; ENABLED-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[ENTRY_NEW]] ], [ [[INDVARS_IV_NEXT_7:%.*]], [[LATCH_7:%.*]] ] -; ENABLED-NEXT: [[SUM_02:%.*]] = phi i32 [ 0, [[ENTRY_NEW]] ], [ [[ADD_7:%.*]], [[LATCH_7]] ] +; ENABLED-NEXT: [[SUM_02:%.*]] = phi i32 [ 1, [[ENTRY_NEW]] ], [ [[ADD_7:%.*]], [[LATCH_7]] ] ; ENABLED-NEXT: [[NITER:%.*]] = phi i64 [ 0, [[ENTRY_NEW]] ], [ [[NITER_NEXT_7:%.*]], [[LATCH_7]] ] ; ENABLED-NEXT: br label [[FOR_EXITING_BLOCK:%.*]] ; ENABLED: for.exiting_block: @@ -272,7 +272,7 @@ ; ENABLED: latchexit.unr-lcssa: ; ENABLED-NEXT: [[SUM_0_LCSSA_PH:%.*]] = phi i32 [ undef, [[ENTRY:%.*]] ], [ [[SUM_0_LCSSA_PH_PH]], [[LATCHEXIT_UNR_LCSSA_LOOPEXIT]] ] ; ENABLED-NEXT: [[INDVARS_IV_UNR:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[INDVARS_IV_UNR_PH]], [[LATCHEXIT_UNR_LCSSA_LOOPEXIT]] ] -; ENABLED-NEXT: [[SUM_02_UNR:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_02_UNR_PH]], [[LATCHEXIT_UNR_LCSSA_LOOPEXIT]] ] +; ENABLED-NEXT: [[SUM_02_UNR:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[SUM_02_UNR_PH]], [[LATCHEXIT_UNR_LCSSA_LOOPEXIT]] ] ; ENABLED-NEXT: [[LCMP_MOD:%.*]] = icmp ne i64 [[XTRAITER]], 0 ; ENABLED-NEXT: br i1 [[LCMP_MOD]], label [[HEADER_EPIL_PREHEADER:%.*]], label [[LATCHEXIT:%.*]] ; ENABLED: header.epil.preheader: @@ -316,7 +316,7 @@ header: %indvars.iv = phi i64 [ %indvars.iv.next, %latch ], [ 0, %entry ] - %sum.02 = phi i32 [ %add, %latch ], [ 0, %entry ] + %sum.02 = phi i32 [ %add, %latch ], [ 1, %entry ] br label %for.exiting_block for.exiting_block: @@ -348,7 +348,7 @@ ; CHECK-NEXT: br label [[HEADER:%.*]] ; CHECK: header: ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LATCH:%.*]] ], [ 0, [[ENTRY:%.*]] ] -; CHECK-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[LATCH]] ], [ 0, [[ENTRY]] ] +; CHECK-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[LATCH]] ], [ 1, [[ENTRY]] ] ; CHECK-NEXT: br label [[FOR_EXITING_BLOCK:%.*]] ; CHECK: for.exiting_block: ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[N:%.*]], 42 @@ -370,7 +370,7 @@ ; NOUNROLL-NEXT: br label [[HEADER:%.*]] ; NOUNROLL: header: ; NOUNROLL-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LATCH:%.*]] ], [ 0, [[ENTRY:%.*]] ] -; NOUNROLL-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[LATCH]] ], [ 0, [[ENTRY]] ] +; NOUNROLL-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[LATCH]] ], [ 1, [[ENTRY]] ] ; NOUNROLL-NEXT: br label [[FOR_EXITING_BLOCK:%.*]] ; NOUNROLL: for.exiting_block: ; NOUNROLL-NEXT: [[CMP:%.*]] = icmp eq i64 [[N:%.*]], 42 @@ -401,7 +401,7 @@ ; ENABLED-NEXT: br label [[HEADER:%.*]] ; ENABLED: header: ; ENABLED-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[ENTRY_NEW]] ], [ [[INDVARS_IV_NEXT_7:%.*]], [[LATCH_7:%.*]] ] -; ENABLED-NEXT: [[SUM_02:%.*]] = phi i32 [ 0, [[ENTRY_NEW]] ], [ [[ADD_7:%.*]], [[LATCH_7]] ] +; ENABLED-NEXT: [[SUM_02:%.*]] = phi i32 [ 1, [[ENTRY_NEW]] ], [ [[ADD_7:%.*]], [[LATCH_7]] ] ; ENABLED-NEXT: [[NITER:%.*]] = phi i64 [ 0, [[ENTRY_NEW]] ], [ [[NITER_NEXT_7:%.*]], [[LATCH_7]] ] ; ENABLED-NEXT: br label [[FOR_EXITING_BLOCK:%.*]] ; ENABLED: for.exiting_block: @@ -493,7 +493,7 @@ ; ENABLED: latchexit.unr-lcssa: ; ENABLED-NEXT: [[SUM_0_LCSSA_PH:%.*]] = phi i32 [ undef, [[ENTRY:%.*]] ], [ [[SUM_0_LCSSA_PH_PH]], [[LATCHEXIT_UNR_LCSSA_LOOPEXIT]] ] ; ENABLED-NEXT: [[INDVARS_IV_UNR:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[INDVARS_IV_UNR_PH]], [[LATCHEXIT_UNR_LCSSA_LOOPEXIT]] ] -; ENABLED-NEXT: [[SUM_02_UNR:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[SUM_02_UNR_PH]], [[LATCHEXIT_UNR_LCSSA_LOOPEXIT]] ] +; ENABLED-NEXT: [[SUM_02_UNR:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[SUM_02_UNR_PH]], [[LATCHEXIT_UNR_LCSSA_LOOPEXIT]] ] ; ENABLED-NEXT: [[LCMP_MOD:%.*]] = icmp ne i64 [[XTRAITER]], 0 ; ENABLED-NEXT: br i1 [[LCMP_MOD]], label [[HEADER_EPIL_PREHEADER:%.*]], label [[LATCHEXIT:%.*]] ; ENABLED: header.epil.preheader: @@ -536,7 +536,7 @@ header: %indvars.iv = phi i64 [ %indvars.iv.next, %latch ], [ 0, %entry ] - %sum.02 = phi i32 [ %add, %latch ], [ 0, %entry ] + %sum.02 = phi i32 [ %add, %latch ], [ 1, %entry ] br label %for.exiting_block for.exiting_block: @@ -569,7 +569,7 @@ ; CHECK-NEXT: br label [[HEADER:%.*]] ; CHECK: header: ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LATCH:%.*]] ], [ 0, [[ENTRY:%.*]] ] -; CHECK-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[LATCH]] ], [ 0, [[ENTRY]] ] +; CHECK-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[LATCH]] ], [ 1, [[ENTRY]] ] ; CHECK-NEXT: br label [[FOR_EXITING_BLOCK:%.*]] ; CHECK: for.exiting_block: ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[N:%.*]], 42 @@ -591,7 +591,7 @@ ; NOUNROLL-NEXT: br label [[HEADER:%.*]] ; NOUNROLL: header: ; NOUNROLL-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LATCH:%.*]] ], [ 0, [[ENTRY:%.*]] ] -; NOUNROLL-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[LATCH]] ], [ 0, [[ENTRY]] ] +; NOUNROLL-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[LATCH]] ], [ 1, [[ENTRY]] ] ; NOUNROLL-NEXT: br label [[FOR_EXITING_BLOCK:%.*]] ; NOUNROLL: for.exiting_block: ; NOUNROLL-NEXT: [[CMP:%.*]] = icmp eq i64 [[N:%.*]], 42 @@ -614,7 +614,7 @@ ; ENABLED-NEXT: br label [[HEADER:%.*]] ; ENABLED: header: ; ENABLED-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LATCH:%.*]] ], [ 0, [[ENTRY:%.*]] ] -; ENABLED-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[LATCH]] ], [ 0, [[ENTRY]] ] +; ENABLED-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[LATCH]] ], [ 1, [[ENTRY]] ] ; ENABLED-NEXT: br label [[FOR_EXITING_BLOCK:%.*]] ; ENABLED: for.exiting_block: ; ENABLED-NEXT: [[CMP:%.*]] = icmp eq i64 [[N:%.*]], 42 @@ -637,7 +637,7 @@ header: %indvars.iv = phi i64 [ %indvars.iv.next, %latch ], [ 0, %entry ] - %sum.02 = phi i32 [ %add, %latch ], [ 0, %entry ] + %sum.02 = phi i32 [ %add, %latch ], [ 1, %entry ] br label %for.exiting_block for.exiting_block: @@ -669,7 +669,7 @@ ; CHECK-NEXT: br label [[HEADER:%.*]] ; CHECK: header: ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LATCH:%.*]] ], [ 0, [[ENTRY:%.*]] ] -; CHECK-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[LATCH]] ], [ 0, [[ENTRY]] ] +; CHECK-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[LATCH]] ], [ 1, [[ENTRY]] ] ; CHECK-NEXT: br label [[FOR_EXITING_BLOCK:%.*]] ; CHECK: for.exiting_block: ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[INDVARS_IV]], 4096 @@ -691,7 +691,7 @@ ; NOUNROLL-NEXT: br label [[HEADER:%.*]] ; NOUNROLL: header: ; NOUNROLL-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LATCH:%.*]] ], [ 0, [[ENTRY:%.*]] ] -; NOUNROLL-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[LATCH]] ], [ 0, [[ENTRY]] ] +; NOUNROLL-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[LATCH]] ], [ 1, [[ENTRY]] ] ; NOUNROLL-NEXT: br label [[FOR_EXITING_BLOCK:%.*]] ; NOUNROLL: for.exiting_block: ; NOUNROLL-NEXT: [[CMP:%.*]] = icmp eq i64 [[INDVARS_IV]], 4096 @@ -714,7 +714,7 @@ ; ENABLED-NEXT: br label [[HEADER:%.*]] ; ENABLED: header: ; ENABLED-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LATCH:%.*]] ], [ 0, [[ENTRY:%.*]] ] -; ENABLED-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[LATCH]] ], [ 0, [[ENTRY]] ] +; ENABLED-NEXT: [[SUM_02:%.*]] = phi i32 [ [[ADD:%.*]], [[LATCH]] ], [ 1, [[ENTRY]] ] ; ENABLED-NEXT: br label [[FOR_EXITING_BLOCK:%.*]] ; ENABLED: for.exiting_block: ; ENABLED-NEXT: [[CMP:%.*]] = icmp eq i64 [[INDVARS_IV]], 4096 @@ -737,7 +737,7 @@ header: %indvars.iv = phi i64 [ %indvars.iv.next, %latch ], [ 0, %entry ] - %sum.02 = phi i32 [ %add, %latch ], [ 0, %entry ] + %sum.02 = phi i32 [ %add, %latch ], [ 1, %entry ] br label %for.exiting_block for.exiting_block: Index: llvm/test/Transforms/LoopUnroll/unroll-cost-symbolic-execute.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/unroll-cost-symbolic-execute.ll +++ llvm/test/Transforms/LoopUnroll/unroll-cost-symbolic-execute.ll @@ -1,5 +1,5 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py -; RUN: opt -passes=loop-unroll -S -unroll-threshold=120 -unroll-max-iteration-count-to-analyze=100 < %s | FileCheck %s +; RUN: opt -passes=loop-unroll -S -unroll-threshold=120 -unroll-max-iteration-count-to-analyze=100 -unroll-allow-peeling=false < %s | FileCheck %s ; TODO: None of the if.false blocks are reachable, it would be nice if ; the output of unrolling made this obvious and didn't rely on other Index: llvm/test/Transforms/LoopUnroll/unroll-heuristics-pgo.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/unroll-heuristics-pgo.ll +++ llvm/test/Transforms/LoopUnroll/unroll-heuristics-pgo.ll @@ -15,7 +15,7 @@ loop: %iv = phi i64 [ 0, %entry ], [ %inc, %loop ] - %r = phi i32 [ 0, %entry ], [ %add, %loop ] + %r = phi i32 [ 1, %entry ], [ %add, %loop ] %arrayidx = getelementptr inbounds i32, ptr %src, i64 %iv %src_element = load i32, ptr %arrayidx, align 4 %array_const_idx = getelementptr inbounds [9 x i32], ptr @known_constant, i64 0, i64 %iv @@ -39,7 +39,7 @@ loop: %iv = phi i64 [ 0, %entry ], [ %inc, %loop ] - %r = phi i32 [ 0, %entry ], [ %add, %loop ] + %r = phi i32 [ 1, %entry ], [ %add, %loop ] %arrayidx = getelementptr inbounds i32, ptr %src, i64 %iv %src_element = load i32, ptr %arrayidx, align 4 %array_const_idx = getelementptr inbounds [9 x i32], ptr @known_constant, i64 0, i64 %iv Index: llvm/test/Transforms/PhaseOrdering/ARM/arm_mean_q7.ll =================================================================== --- llvm/test/Transforms/PhaseOrdering/ARM/arm_mean_q7.ll +++ llvm/test/Transforms/PhaseOrdering/ARM/arm_mean_q7.ll @@ -16,7 +16,7 @@ ; CHECK-NEXT: [[TMP0:%.*]] = and i32 [[BLOCKSIZE]], -16 ; CHECK-NEXT: br label [[WHILE_BODY:%.*]] ; CHECK: while.body: -; CHECK-NEXT: [[SUM_013:%.*]] = phi i32 [ [[TMP3:%.*]], [[WHILE_BODY]] ], [ 0, [[WHILE_BODY_PREHEADER]] ] +; CHECK-NEXT: [[SUM_013:%.*]] = phi i32 [ [[TMP3:%.*]], [[WHILE_BODY]] ], [ 1, [[WHILE_BODY_PREHEADER]] ] ; CHECK-NEXT: [[PSRC_ADDR_012:%.*]] = phi ptr [ [[ADD_PTR:%.*]], [[WHILE_BODY]] ], [ [[PSRC:%.*]], [[WHILE_BODY_PREHEADER]] ] ; CHECK-NEXT: [[BLKCNT_011:%.*]] = phi i32 [ [[DEC:%.*]], [[WHILE_BODY]] ], [ [[SHR]], [[WHILE_BODY_PREHEADER]] ] ; CHECK-NEXT: [[TMP1:%.*]] = load <16 x i8>, ptr [[PSRC_ADDR_012]], align 1 @@ -31,7 +31,7 @@ ; CHECK-NEXT: br label [[WHILE_END]] ; CHECK: while.end: ; CHECK-NEXT: [[PSRC_ADDR_0_LCSSA:%.*]] = phi ptr [ [[PSRC]], [[ENTRY:%.*]] ], [ [[UGLYGEP]], [[WHILE_END_LOOPEXIT]] ] -; CHECK-NEXT: [[SUM_0_LCSSA:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[TMP3]], [[WHILE_END_LOOPEXIT]] ] +; CHECK-NEXT: [[SUM_0_LCSSA:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[TMP3]], [[WHILE_END_LOOPEXIT]] ] ; CHECK-NEXT: [[AND:%.*]] = and i32 [[BLOCKSIZE]], 15 ; CHECK-NEXT: [[CMP2_NOT15:%.*]] = icmp eq i32 [[AND]], 0 ; CHECK-NEXT: br i1 [[CMP2_NOT15]], label [[WHILE_END5:%.*]], label [[VECTOR_BODY:%.*]] @@ -63,7 +63,7 @@ call void @llvm.lifetime.start.p0(i64 4, ptr %blkCnt) #3 call void @llvm.lifetime.start.p0(i64 16, ptr %vecSrc) #3 call void @llvm.lifetime.start.p0(i64 4, ptr %sum) #3 - store i32 0, ptr %sum, align 4 + store i32 1, ptr %sum, align 4 %0 = load i32, ptr %blockSize.addr, align 4 %shr = lshr i32 %0, 4 store i32 %shr, ptr %blkCnt, align 4 Index: llvm/test/Transforms/PhaseOrdering/SystemZ/sub-xor.ll =================================================================== --- llvm/test/Transforms/PhaseOrdering/SystemZ/sub-xor.ll +++ llvm/test/Transforms/PhaseOrdering/SystemZ/sub-xor.ll @@ -18,7 +18,7 @@ ; CHECK-NEXT: br label [[FOR_BODY4:%.*]] ; CHECK: for.body4: ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDVARS_IV_NEXT_7:%.*]], [[FOR_BODY4]] ] -; CHECK-NEXT: [[SUM_11:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[ADD_7:%.*]], [[FOR_BODY4]] ] +; CHECK-NEXT: [[SUM_11:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[ADD_7:%.*]], [[FOR_BODY4]] ] ; CHECK-NEXT: [[IDX_NEG:%.*]] = sub nsw i64 0, [[INDVARS_IV]] ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i32, ptr getelementptr inbounds ([100 x i32], ptr @ARR, i64 0, i64 99), i64 [[IDX_NEG]] ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[ADD_PTR]], align 4, !tbaa [[TBAA3:![0-9]+]] @@ -155,7 +155,7 @@ for.cond: ; preds = %for.inc5, %entry %j.0 = phi i32 [ 1, %entry ], [ %inc6, %for.inc5 ] - %sum.0 = phi i32 [ 0, %entry ], [ %sum.1, %for.inc5 ] + %sum.0 = phi i32 [ 1, %entry ], [ %sum.1, %for.inc5 ] %cmp = icmp slt i32 %j.0, 4 br i1 %cmp, label %for.body, label %for.cond.cleanup Index: llvm/test/Transforms/PhaseOrdering/X86/ctlz-loop.ll =================================================================== --- llvm/test/Transforms/PhaseOrdering/X86/ctlz-loop.ll +++ llvm/test/Transforms/PhaseOrdering/X86/ctlz-loop.ll @@ -29,13 +29,13 @@ ; CHECK-NEXT: br label [[WHILE_BODY:%.*]] ; CHECK: while.body: ; CHECK-NEXT: [[N_ADDR_03:%.*]] = phi i32 [ [[TMP1:%.*]], [[WHILE_BODY]] ], [ [[TMP0]], [[WHILE_BODY_PREHEADER]] ] -; CHECK-NEXT: [[I_02:%.*]] = phi i32 [ [[INC:%.*]], [[WHILE_BODY]] ], [ 0, [[WHILE_BODY_PREHEADER]] ] +; CHECK-NEXT: [[I_02:%.*]] = phi i32 [ [[INC:%.*]], [[WHILE_BODY]] ], [ 1, [[WHILE_BODY_PREHEADER]] ] ; CHECK-NEXT: [[TMP1]] = lshr i32 [[N_ADDR_03]], 1 ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_02]], 1 ; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp ult i32 [[N_ADDR_03]], 2 ; CHECK-NEXT: br i1 [[TOBOOL_NOT]], label [[WHILE_END]], label [[WHILE_BODY]] ; CHECK: while.end: -; CHECK-NEXT: [[I_0_LCSSA:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC]], [[WHILE_BODY]] ] +; CHECK-NEXT: [[I_0_LCSSA:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[INC]], [[WHILE_BODY]] ] ; CHECK-NEXT: ret i32 [[I_0_LCSSA]] ; entry: @@ -54,7 +54,7 @@ br label %while.cond while.cond: ; preds = %while.body, %cond.end - %i.0 = phi i32 [ 0, %cond.end ], [ %inc, %while.body ] + %i.0 = phi i32 [ 1, %cond.end ], [ %inc, %while.body ] %n.addr.0 = phi i32 [ %cond, %cond.end ], [ %shr, %while.body ] %tobool = icmp ne i32 %n.addr.0, 0 br i1 %tobool, label %while.body, label %while.end Index: llvm/test/Transforms/PhaseOrdering/pr44461-br-to-switch-rotate.ll =================================================================== --- llvm/test/Transforms/PhaseOrdering/pr44461-br-to-switch-rotate.ll +++ llvm/test/Transforms/PhaseOrdering/pr44461-br-to-switch-rotate.ll @@ -11,7 +11,7 @@ ; CHECK: bb10: ; CHECK-NEXT: [[ITER1_SROA_5_0:%.*]] = phi i64 [ 100000, [[START:%.*]] ], [ [[SPEC_SELECT:%.*]], [[BB3_I_I:%.*]] ] ; CHECK-NEXT: [[ITER1_SROA_9_0:%.*]] = phi i8 [ 2, [[START]] ], [ [[TMP3:%.*]], [[BB3_I_I]] ] -; CHECK-NEXT: [[COUNT_1:%.*]] = phi i64 [ 0, [[START]] ], [ [[TMP4:%.*]], [[BB3_I_I]] ] +; CHECK-NEXT: [[COUNT_1:%.*]] = phi i64 [ 1, [[START]] ], [ [[TMP4:%.*]], [[BB3_I_I]] ] ; CHECK-NEXT: switch i8 [[ITER1_SROA_9_0]], label [[BB12:%.*]] [ ; CHECK-NEXT: i8 2, label [[BB3_I_I]] ; CHECK-NEXT: i8 0, label [[BB3_I_I]] @@ -31,7 +31,7 @@ bb10: ; preds = %bb3.i.i, %bb6 %iter1.sroa.5.0 = phi i64 [ 100000, %start ], [ %spec.select, %bb3.i.i ] %iter1.sroa.9.0 = phi i8 [ 2, %start ], [ %tmp3, %bb3.i.i ] - %count.1 = phi i64 [ 0, %start ], [ %tmp4, %bb3.i.i ] + %count.1 = phi i64 [ 1, %start ], [ %tmp4, %bb3.i.i ] %c1 = icmp eq i8 %iter1.sroa.9.0, 2 %c2 = icmp eq i8 %iter1.sroa.9.0, 0 %c3 = or i1 %c1, %c2