Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -549,7 +549,13 @@ /// Set the debug location in the builder using the debug location in /// the instruction. - void setDebugLocFromInst(IRBuilder<> &B, const Value *Ptr); + void setDebugLocFromInst(IRBuilder<> &B, const Value *Ptr) const; + + /// Set the debug location in this class' Builder object using the debug + /// location in \p Ptr. + void setDebugLocFromInst(const Value *Ptr) { + setDebugLocFromInst(Builder, Ptr); + } /// Fix the non-induction PHIs in the OrigPHIsToFix vector. void fixNonInductionPHIs(VPTransformState &State); @@ -1040,7 +1046,8 @@ return I; } -void InnerLoopVectorizer::setDebugLocFromInst(IRBuilder<> &B, const Value *Ptr) { +void InnerLoopVectorizer::setDebugLocFromInst(IRBuilder<> &B, + const Value *Ptr) const { if (const Instruction *Inst = dyn_cast_or_null(Ptr)) { const DILocation *DIL = Inst->getDebugLoc(); @@ -2718,7 +2725,7 @@ for (unsigned Part = 0; Part < UF; Part++) { Value *AddrPart = State.get(Addr, VPIteration(Part, 0)); - setDebugLocFromInst(Builder, AddrPart); + setDebugLocFromInst(AddrPart); // Notice current instruction could be any index. Need to adjust the address // to the member of index 0. @@ -2744,7 +2751,7 @@ AddrParts.push_back(Builder.CreateBitCast(AddrPart, PtrTy)); } - setDebugLocFromInst(Builder, Instr); + setDebugLocFromInst(Instr); Value *PoisonVec = PoisonValue::get(VecTy); Value *MaskForGaps = nullptr; @@ -2949,7 +2956,7 @@ // Handle Stores: if (SI) { - setDebugLocFromInst(Builder, SI); + setDebugLocFromInst(SI); for (unsigned Part = 0; Part < UF; ++Part) { Instruction *NewSI = nullptr; @@ -2981,7 +2988,7 @@ // Handle loads. assert(LI && "Must have a load instruction"); - setDebugLocFromInst(Builder, LI); + setDebugLocFromInst(LI); for (unsigned Part = 0; Part < UF; ++Part) { Value *NewLI; if (CreateGatherScatter) { @@ -3023,7 +3030,7 @@ if (!Instance.isFirstIteration()) return; - setDebugLocFromInst(Builder, Instr); + setDebugLocFromInst(Instr); // Does this instruction return a value ? bool IsVoidRetTy = Instr->getType()->isVoidTy(); @@ -3034,6 +3041,7 @@ State.Builder.SetInsertPoint(Builder.GetInsertBlock(), Builder.GetInsertPoint()); + // Replace the operands of the cloned instructions with their scalar // equivalents in the new loop. for (unsigned op = 0, e = User.getNumOperands(); op != e; ++op) { @@ -3075,11 +3083,11 @@ Builder.SetInsertPoint(&*Header->getFirstInsertionPt()); Instruction *OldInst = getDebugLocFromInstOrOperands(OldInduction); - setDebugLocFromInst(Builder, OldInst); + setDebugLocFromInst(OldInst); auto *Induction = Builder.CreatePHI(Start->getType(), 2, "index"); Builder.SetInsertPoint(Latch->getTerminator()); - setDebugLocFromInst(Builder, OldInst); + setDebugLocFromInst(OldInst); // Create i+1 and fill the PHINode. // @@ -4330,7 +4338,7 @@ RecurKind RK = RdxDesc.getRecurrenceKind(); TrackingVH ReductionStartValue = RdxDesc.getRecurrenceStartValue(); Instruction *LoopExitInst = RdxDesc.getLoopExitInstr(); - setDebugLocFromInst(Builder, ReductionStartValue); + setDebugLocFromInst(ReductionStartValue); bool IsInLoopReductionPhi = Cost->isInLoopReduction(OrigPhi); VPValue *LoopExitInstDef = State.Plan->getVPValue(LoopExitInst); @@ -4365,7 +4373,7 @@ // instructions. Builder.SetInsertPoint(&*LoopMiddleBlock->getFirstInsertionPt()); - setDebugLocFromInst(Builder, LoopExitInst); + setDebugLocFromInst(LoopExitInst); Type *PhiTy = OrigPhi->getType(); // If tail is folded by masking, the vector value to leave the loop should be @@ -4444,7 +4452,7 @@ // conditional branch, and (c) other passes may add new predecessors which // terminate on this line. This is the easiest way to ensure we don't // accidentally cause an extra step back into the loop while debugging. - setDebugLocFromInst(Builder, LoopMiddleBlock->getTerminator()); + setDebugLocFromInst(LoopMiddleBlock->getTerminator()); if (IsOrdered) ReducedPartRdx = State.get(LoopExitInstDef, UF - 1); else { @@ -4817,7 +4825,7 @@ assert(!Legal->isReductionVariable(P) && "reductions should be handled above"); - setDebugLocFromInst(Builder, P); + setDebugLocFromInst(P); // This PHINode must be an induction variable. // Make sure that we know about it. @@ -4984,7 +4992,7 @@ case Instruction::Or: case Instruction::Xor: { // Just widen unops and binops. - setDebugLocFromInst(Builder, &I); + setDebugLocFromInst(&I); for (unsigned Part = 0; Part < UF; ++Part) { SmallVector Ops; @@ -5008,7 +5016,7 @@ // Widen compares. Generate vector compares. bool FCmp = (I.getOpcode() == Instruction::FCmp); auto *Cmp = cast(&I); - setDebugLocFromInst(Builder, Cmp); + setDebugLocFromInst(Cmp); for (unsigned Part = 0; Part < UF; ++Part) { Value *A = State.get(User.getOperand(0), Part); Value *B = State.get(User.getOperand(1), Part); @@ -5041,7 +5049,7 @@ case Instruction::FPTrunc: case Instruction::BitCast: { auto *CI = cast(&I); - setDebugLocFromInst(Builder, CI); + setDebugLocFromInst(CI); /// Vectorize casts. Type *DestTy = @@ -5067,7 +5075,7 @@ VPTransformState &State) { assert(!isa(I) && "DbgInfoIntrinsic should have been dropped during VPlan construction"); - setDebugLocFromInst(Builder, &I); + setDebugLocFromInst(&I); Module *M = I.getParent()->getParent()->getParent(); auto *CI = cast(&I); @@ -5139,7 +5147,7 @@ VPUser &Operands, bool InvariantCond, VPTransformState &State) { - setDebugLocFromInst(Builder, &I); + setDebugLocFromInst(&I); // The condition can be loop invariant but still defined inside the // loop. This means that we can't just use the original 'cond' value.