Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -547,9 +547,9 @@ VPValue *Def, VPValue *Addr, VPValue *StoredValue, VPValue *BlockInMask); - /// Set the debug location in the builder using the debug location in - /// the instruction. - void setDebugLocFromInst(IRBuilder<> &B, const Value *Ptr); + /// Set the debug location in the builder \p Ptr using the debug location in + /// \p V. If \p Ptr is None then it uses the class member's Builder. + void setDebugLocFromInst(Optional *> Ptr, const Value *V); /// Fix the non-induction PHIs in the OrigPHIsToFix vector. void fixNonInductionPHIs(VPTransformState &State); @@ -1040,8 +1040,10 @@ return I; } -void InnerLoopVectorizer::setDebugLocFromInst(IRBuilder<> &B, const Value *Ptr) { - if (const Instruction *Inst = dyn_cast_or_null(Ptr)) { +void InnerLoopVectorizer::setDebugLocFromInst(Optional *> Ptr, + const Value *V) { + IRBuilder<> *B = (Ptr == None) ? &Builder : *Ptr; + if (const Instruction *Inst = dyn_cast_or_null(V)) { const DILocation *DIL = Inst->getDebugLoc(); // When a FSDiscriminator is enabled, we don't need to add the multiply @@ -1052,15 +1054,15 @@ auto NewDIL = DIL->cloneByMultiplyingDuplicationFactor(UF * VF.getKnownMinValue()); if (NewDIL) - B.SetCurrentDebugLocation(NewDIL.getValue()); + B->SetCurrentDebugLocation(NewDIL.getValue()); else LLVM_DEBUG(dbgs() << "Failed to create new discriminator: " << DIL->getFilename() << " Line: " << DIL->getLine()); } else - B.SetCurrentDebugLocation(DIL); + B->SetCurrentDebugLocation(DIL); } else - B.SetCurrentDebugLocation(DebugLoc()); + B->SetCurrentDebugLocation(DebugLoc()); } /// Write a \p DebugMsg about vectorization to the debug output stream. If \p I @@ -2718,7 +2720,7 @@ for (unsigned Part = 0; Part < UF; Part++) { Value *AddrPart = State.get(Addr, VPIteration(Part, 0)); - setDebugLocFromInst(Builder, AddrPart); + setDebugLocFromInst(None, AddrPart); // Notice current instruction could be any index. Need to adjust the address // to the member of index 0. @@ -2744,7 +2746,7 @@ AddrParts.push_back(Builder.CreateBitCast(AddrPart, PtrTy)); } - setDebugLocFromInst(Builder, Instr); + setDebugLocFromInst(None, Instr); Value *PoisonVec = PoisonValue::get(VecTy); Value *MaskForGaps = nullptr; @@ -2949,7 +2951,7 @@ // Handle Stores: if (SI) { - setDebugLocFromInst(Builder, SI); + setDebugLocFromInst(None, SI); for (unsigned Part = 0; Part < UF; ++Part) { Instruction *NewSI = nullptr; @@ -2981,7 +2983,7 @@ // Handle loads. assert(LI && "Must have a load instruction"); - setDebugLocFromInst(Builder, LI); + setDebugLocFromInst(None, LI); for (unsigned Part = 0; Part < UF; ++Part) { Value *NewLI; if (CreateGatherScatter) { @@ -3023,7 +3025,7 @@ if (!Instance.isFirstIteration()) return; - setDebugLocFromInst(Builder, Instr); + setDebugLocFromInst(None, Instr); // Does this instruction return a value ? bool IsVoidRetTy = Instr->getType()->isVoidTy(); @@ -3034,6 +3036,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) { @@ -3073,11 +3076,11 @@ IRBuilder<> B(&*Header->getFirstInsertionPt()); Instruction *OldInst = getDebugLocFromInstOrOperands(OldInduction); - setDebugLocFromInst(B, OldInst); + setDebugLocFromInst(&B, OldInst); auto *Induction = B.CreatePHI(Start->getType(), 2, "index"); B.SetInsertPoint(Latch->getTerminator()); - setDebugLocFromInst(B, OldInst); + setDebugLocFromInst(&B, OldInst); // Create i+1 and fill the PHINode. // @@ -4322,7 +4325,7 @@ RecurKind RK = RdxDesc.getRecurrenceKind(); TrackingVH ReductionStartValue = RdxDesc.getRecurrenceStartValue(); Instruction *LoopExitInst = RdxDesc.getLoopExitInstr(); - setDebugLocFromInst(Builder, ReductionStartValue); + setDebugLocFromInst(None, ReductionStartValue); bool IsInLoopReductionPhi = Cost->isInLoopReduction(OrigPhi); VPValue *LoopExitInstDef = State.Plan->getVPValue(LoopExitInst); @@ -4357,7 +4360,7 @@ // instructions. Builder.SetInsertPoint(&*LoopMiddleBlock->getFirstInsertionPt()); - setDebugLocFromInst(Builder, LoopExitInst); + setDebugLocFromInst(None, LoopExitInst); Type *PhiTy = OrigPhi->getType(); // If tail is folded by masking, the vector value to leave the loop should be @@ -4436,7 +4439,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(None, LoopMiddleBlock->getTerminator()); if (IsOrdered) ReducedPartRdx = State.get(LoopExitInstDef, UF - 1); else { @@ -4809,7 +4812,7 @@ assert(!Legal->isReductionVariable(P) && "reductions should be handled above"); - setDebugLocFromInst(Builder, P); + setDebugLocFromInst(None, P); // This PHINode must be an induction variable. // Make sure that we know about it. @@ -4976,7 +4979,7 @@ case Instruction::Or: case Instruction::Xor: { // Just widen unops and binops. - setDebugLocFromInst(Builder, &I); + setDebugLocFromInst(None, &I); for (unsigned Part = 0; Part < UF; ++Part) { SmallVector Ops; @@ -5000,7 +5003,7 @@ // Widen compares. Generate vector compares. bool FCmp = (I.getOpcode() == Instruction::FCmp); auto *Cmp = cast(&I); - setDebugLocFromInst(Builder, Cmp); + setDebugLocFromInst(None, Cmp); for (unsigned Part = 0; Part < UF; ++Part) { Value *A = State.get(User.getOperand(0), Part); Value *B = State.get(User.getOperand(1), Part); @@ -5033,7 +5036,7 @@ case Instruction::FPTrunc: case Instruction::BitCast: { auto *CI = cast(&I); - setDebugLocFromInst(Builder, CI); + setDebugLocFromInst(None, CI); /// Vectorize casts. Type *DestTy = @@ -5059,7 +5062,7 @@ VPTransformState &State) { assert(!isa(I) && "DbgInfoIntrinsic should have been dropped during VPlan construction"); - setDebugLocFromInst(Builder, &I); + setDebugLocFromInst(None, &I); Module *M = I.getParent()->getParent()->getParent(); auto *CI = cast(&I); @@ -5131,7 +5134,7 @@ VPUser &Operands, bool InvariantCond, VPTransformState &State) { - setDebugLocFromInst(Builder, &I); + setDebugLocFromInst(None, &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. @@ -9484,7 +9487,7 @@ } void VPBlendRecipe::execute(VPTransformState &State) { - State.ILV->setDebugLocFromInst(State.Builder, Phi); + State.ILV->setDebugLocFromInst(&State.Builder, Phi); // We know that all PHIs in non-header blocks are converted into // selects, so we don't have to worry about the insertion order and we // can just use the builder.