diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index b3fe0ab8b5cb4..7db0586386506 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -1494,8 +1494,14 @@ processInternalGlobal(GlobalVariable *GV, const GlobalStatus &GS, // FIXME: Pass Global's alignment when globals have alignment AllocaInst *Alloca = new AllocaInst(ElemTy, DL.getAllocaAddrSpace(), nullptr, GV->getName(), FirstI); - if (!isa(GV->getInitializer())) - new StoreInst(GV->getInitializer(), Alloca, FirstI); + Alloca->setDebugLoc(DebugLoc::getCompilerGenerated()); + if (!isa(GV->getInitializer())) { + auto *SI = new StoreInst(GV->getInitializer(), Alloca, FirstI); + // FIXME: We're localizing a global and creating a store instruction for + // the initial value of that global. Could we logically use the global + // variable's (if one exists) line for this? + SI->setDebugLoc(DebugLoc::getCompilerGenerated()); + } GV->replaceAllUsesWith(Alloca); GV->eraseFromParent(); diff --git a/llvm/lib/Transforms/IPO/IROutliner.cpp b/llvm/lib/Transforms/IPO/IROutliner.cpp index ff66a518be752..cb18b55ae2183 100644 --- a/llvm/lib/Transforms/IPO/IROutliner.cpp +++ b/llvm/lib/Transforms/IPO/IROutliner.cpp @@ -730,7 +730,7 @@ static void moveFunctionData(Function &Old, Function &New, // other outlined instructions. if (!isa(&Val)) { // Remove the debug information for outlined functions. - Val.setDebugLoc(DebugLoc()); + Val.setDebugLoc(DebugLoc::getDropped()); // Loop info metadata may contain line locations. Update them to have no // value in the new subprogram since the outlined code could be from @@ -1864,7 +1864,7 @@ replaceArgumentUses(OutlinableRegion &Region, Value *ValueOperand = SI->getValueOperand(); StoreInst *NewI = cast(I->clone()); - NewI->setDebugLoc(DebugLoc()); + NewI->setDebugLoc(DebugLoc::getDropped()); BasicBlock *OutputBB = VBBIt->second; NewI->insertInto(OutputBB, OutputBB->end()); LLVM_DEBUG(dbgs() << "Move store for instruction " << *I << " to " diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp index a842a5edcb8a3..6477141ab095f 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp @@ -870,7 +870,14 @@ Instruction *InstCombinerImpl::foldPHIArgZextsIntoPHI(PHINode &Phi) { NewPhi->addIncoming(NewIncoming[I], Phi.getIncomingBlock(I)); InsertNewInstBefore(NewPhi, Phi.getIterator()); - return CastInst::CreateZExtOrBitCast(NewPhi, Phi.getType()); + auto *CI = CastInst::CreateZExtOrBitCast(NewPhi, Phi.getType()); + + // We use a dropped location here because the new ZExt is necessarily a merge + // of ZExtInsts and at least one constant from incoming branches; the presence + // of the constant means we have no viable DebugLoc from that branch, and + // therefore we must use a dropped location. + CI->setDebugLoc(DebugLoc::getDropped()); + return CI; } /// If all operands to a PHI node are the same "unary" operator and they all are diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index b95a851c99b49..4627f537dc16b 100644 --- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -432,7 +432,8 @@ static bool processSwitch(SwitchInst *I, LazyValueInfo *LVI, BasicBlock *NewUnreachableBB = BasicBlock::Create(BB->getContext(), "default.unreachable", BB->getParent(), DefaultDest); - new UnreachableInst(BB->getContext(), NewUnreachableBB); + auto *UI = new UnreachableInst(BB->getContext(), NewUnreachableBB); + UI->setDebugLoc(DebugLoc::getTemporary()); DefaultDest->removePredecessor(BB); SI->setDefaultDest(NewUnreachableBB); diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index 95d52b9b4e189..334c911191cb8 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -1506,6 +1506,9 @@ bool IndVarSimplify::canonicalizeExitCondition(Loop *L) { auto *NewRHS = CastInst::Create( Instruction::Trunc, RHS, LHSOp->getType(), "", L->getLoopPreheader()->getTerminator()->getIterator()); + // NewRHS is an operation that has been hoisted out of the loop, and + // therefore should have a dropped location. + NewRHS->setDebugLoc(DebugLoc::getDropped()); ICmp->setOperand(Swapped ? 1 : 0, LHSOp); ICmp->setOperand(Swapped ? 0 : 1, NewRHS); // Samesign flag cannot be preserved after narrowing the compare. diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index 9449b4cb35b93..37b85bf9de811 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -3001,8 +3001,10 @@ bool JumpThreadingPass::tryToUnfoldSelectInCurrBB(BasicBlock *BB) { continue; // Expand the select. Value *Cond = SI->getCondition(); - if (!isGuaranteedNotToBeUndefOrPoison(Cond, nullptr, SI)) + if (!isGuaranteedNotToBeUndefOrPoison(Cond, nullptr, SI)) { Cond = new FreezeInst(Cond, "cond.fr", SI->getIterator()); + cast(Cond)->setDebugLoc(DebugLoc::getTemporary()); + } MDNode *BranchWeights = getBranchWeightMDNode(*SI); Instruction *Term = SplitBlockAndInsertIfThen(Cond, SI, false, BranchWeights); diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index 9773ef778b690..3024ccb330b1a 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -2248,7 +2248,7 @@ bool llvm::promoteLoopAccessesToScalars( if (SawUnorderedAtomic) PreheaderLoad->setOrdering(AtomicOrdering::Unordered); PreheaderLoad->setAlignment(Alignment); - PreheaderLoad->setDebugLoc(DebugLoc()); + PreheaderLoad->setDebugLoc(DebugLoc::getDropped()); if (AATags && LoadIsGuaranteedToExecute) PreheaderLoad->setAAMetadata(AATags); @@ -2808,6 +2808,7 @@ static bool hoistMulAddAssociation(Instruction &I, Loop &L, auto *NewBO = BinaryOperator::Create(Ins->getOpcode(), LHS, RHS, Ins->getName() + ".reass", Ins->getIterator()); + NewBO->setDebugLoc(DebugLoc::getDropped()); NewBO->copyIRFlags(Ins); if (VariantOp == Ins) VariantOp = NewBO; @@ -2864,6 +2865,7 @@ static bool hoistBOAssociation(Instruction &I, Loop &L, auto *NewBO = BinaryOperator::Create( Opcode, LV, Inv, BO->getName() + ".reass", BO->getIterator()); + NewBO->setDebugLoc(DebugLoc::getDropped()); if (Opcode == Instruction::FAdd || Opcode == Instruction::FMul) { // Intersect FMF flags for FADD and FMUL. diff --git a/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp b/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp index 39e8d702a692e..6bdf76f789a49 100644 --- a/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp +++ b/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp @@ -442,7 +442,7 @@ class LoadEliminationForLoop { assert(PH && "Preheader should exist!"); Value *InitialPtr = SEE.expandCodeFor(PtrSCEV->getStart(), Ptr->getType(), PH->getTerminator()); - Value *Initial = + Instruction *Initial = new LoadInst(Cand.Load->getType(), InitialPtr, "load_initial", /* isVolatile */ false, Cand.Load->getAlign(), PH->getTerminator()->getIterator()); @@ -450,6 +450,7 @@ class LoadEliminationForLoop { // into the loop's preheader. A debug location inside the loop will cause // a misleading stepping when debugging. The test update-debugloc-store // -forwarded.ll checks this. + Initial->setDebugLoc(DebugLoc::getDropped()); PHINode *PHI = PHINode::Create(Initial->getType(), 2, "store_forwarded"); PHI->insertBefore(L->getHeader()->begin()); diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp index 0bf90036b8b82..9b40fc03da6bb 100644 --- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp @@ -274,6 +274,7 @@ static void buildPartialUnswitchConditionalBranch( BasicBlock &UnswitchedSucc, BasicBlock &NormalSucc, bool InsertFreeze, const Instruction *I, AssumptionCache *AC, const DominatorTree &DT) { IRBuilder<> IRB(&BB); + IRB.SetCurrentDebugLocation(DebugLoc::getCompilerGenerated()); SmallVector FrozenInvariants; for (Value *Inv : Invariants) { @@ -330,6 +331,7 @@ static void buildPartialInvariantUnswitchConditionalBranch( } IRBuilder<> IRB(&BB); + IRB.SetCurrentDebugLocation(DebugLoc::getCompilerGenerated()); Value *Cond = VMap[ToDuplicate[0]]; IRB.CreateCondBr(Cond, Direction ? &UnswitchedSucc : &NormalSucc, Direction ? &NormalSucc : &UnswitchedSucc); @@ -2369,6 +2371,7 @@ static void unswitchNontrivialInvariants( // BI (`dyn_cast(TI)`) is an in-loop instruction hoisted // out of the loop. Cond = new FreezeInst(Cond, Cond->getName() + ".fr", BI->getIterator()); + cast(Cond)->setDebugLoc(DebugLoc::getDropped()); } BI->setCondition(Cond); DTUpdates.push_back({DominatorTree::Insert, SplitBB, ClonedPH}); diff --git a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp index 7dd6c60370ed9..c71c5a70a12fd 100644 --- a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp +++ b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp @@ -515,7 +515,8 @@ void TailRecursionEliminator::createTailRecurseLoopHeader(CallInst *CI) { BasicBlock *NewEntry = BasicBlock::Create(F.getContext(), "", &F, HeaderBB); NewEntry->takeName(HeaderBB); HeaderBB->setName("tailrecurse"); - BranchInst::Create(HeaderBB, NewEntry); + auto *BI = BranchInst::Create(HeaderBB, NewEntry); + BI->setDebugLoc(DebugLoc::getCompilerGenerated()); // If the new branch preserves the debug location of CI, it could result in // misleading stepping, if CI is located in a conditional branch. // So, here we don't give any debug location to the new branch. @@ -801,6 +802,7 @@ void TailRecursionEliminator::cleanupAndFinalize() { SelectInst *SI = SelectInst::Create(RetKnownPN, RetPN, RI->getOperand(0), "current.ret.tr", RI->getIterator()); + SI->setDebugLoc(DebugLoc::getCompilerGenerated()); RetSelects.push_back(SI); RI->setOperand(0, SI); } diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index 7a9605bf5f8d4..f47c467d15140 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1775,6 +1775,7 @@ static Value *HandleByValArgument(Type *ByValType, Value *Arg, AllocaInst *NewAlloca = new AllocaInst(ByValType, Arg->getType()->getPointerAddressSpace(), nullptr, Alignment, Arg->getName()); + NewAlloca->setDebugLoc(DebugLoc::getCompilerGenerated()); NewAlloca->insertBefore(Caller->begin()->begin()); IFI.StaticAllocas.push_back(NewAlloca); @@ -3258,6 +3259,8 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, // Add an unconditional branch to make this look like the CallInst case... CreatedBranchToNormalDest = BranchInst::Create(II->getNormalDest(), CB.getIterator()); + // We intend to replace this DebugLoc with another later. + CreatedBranchToNormalDest->setDebugLoc(DebugLoc::getTemporary()); // Split the basic block. This guarantees that no PHI nodes will have to be // updated due to new incoming edges, and make the invoke case more @@ -3359,6 +3362,12 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, Returns[0]->eraseFromParent(); ReturnBB->eraseFromParent(); } else if (!CB.use_empty()) { + // In this case there are no returns to use, so there is no clear source + // location for the "return". + // FIXME: It may be correct to use the scope end line of the function here, + // since this likely means we are falling out of the function. + if (CreatedBranchToNormalDest) + CreatedBranchToNormalDest->setDebugLoc(DebugLoc::getUnknown()); // No returns, but something is using the return value of the call. Just // nuke the result. CB.replaceAllUsesWith(PoisonValue::get(CB.getType())); diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index be71cb69ad8cc..007b26c803d8c 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -3136,7 +3136,8 @@ static bool markAliveBlocks(Function &F, BasicBlock *UnreachableNormalDest = BasicBlock::Create( Ctx, OrigNormalDest->getName() + ".unreachable", II->getFunction(), OrigNormalDest); - new UnreachableInst(Ctx, UnreachableNormalDest); + auto *UI = new UnreachableInst(Ctx, UnreachableNormalDest); + UI->setDebugLoc(DebugLoc::getTemporary()); II->setNormalDest(UnreachableNormalDest); if (DTU) DTU->applyUpdates( diff --git a/llvm/lib/Transforms/Utils/SCCPSolver.cpp b/llvm/lib/Transforms/Utils/SCCPSolver.cpp index 1a2e422356270..f4b378b82daec 100644 --- a/llvm/lib/Transforms/Utils/SCCPSolver.cpp +++ b/llvm/lib/Transforms/Utils/SCCPSolver.cpp @@ -348,7 +348,9 @@ bool SCCPSolver::removeNonFeasibleEdges(BasicBlock *BB, DomTreeUpdater &DTU, NewUnreachableBB = BasicBlock::Create(DefaultDest->getContext(), "default.unreachable", DefaultDest->getParent(), DefaultDest); - new UnreachableInst(DefaultDest->getContext(), NewUnreachableBB); + auto *UI = + new UnreachableInst(DefaultDest->getContext(), NewUnreachableBB); + UI->setDebugLoc(DebugLoc::getTemporary()); } DefaultDest->removePredecessor(BB); diff --git a/llvm/lib/Transforms/Utils/SSAUpdater.cpp b/llvm/lib/Transforms/Utils/SSAUpdater.cpp index 48d9528f0c3df..5db7fc956c497 100644 --- a/llvm/lib/Transforms/Utils/SSAUpdater.cpp +++ b/llvm/lib/Transforms/Utils/SSAUpdater.cpp @@ -318,6 +318,11 @@ class SSAUpdaterTraits { SSAUpdater *Updater) { PHINode *PHI = PHINode::Create(Updater->ProtoType, NumPreds, Updater->ProtoName); + // FIXME: Ordinarily we don't care about or try to assign DebugLocs to PHI + // nodes, but loop optimizations may try to use a PHI node as a DebugLoc + // source (e.g. if this is an induction variable), and it's not clear what + // location we could attach here, so mark this unknown for now. + PHI->setDebugLoc(DebugLoc::getUnknown()); PHI->insertBefore(BB->begin()); return PHI; } diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index e221022bb8361..975ce3bef5176 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1137,7 +1137,7 @@ static void cloneInstructionsIntoPredecessorBlockAndUpdateSSAUses( // branch, drop it. When we fold the bonus instructions we want to make // sure we reset their debug locations in order to avoid stepping on // dead code caused by folding dead branches. - NewBonusInst->setDebugLoc(DebugLoc()); + NewBonusInst->setDebugLoc(DebugLoc::getDropped()); } else if (const DebugLoc &DL = NewBonusInst->getDebugLoc()) { mapAtomInstance(DL, VMap); } @@ -2821,7 +2821,8 @@ static void mergeCompatibleInvokesImpl(ArrayRef Invokes, // so just form a new block with unreachable terminator. BasicBlock *MergedNormalDest = BasicBlock::Create( Ctx, II0BB->getName() + ".cont", Func, InsertBeforeBlock); - new UnreachableInst(Ctx, MergedNormalDest); + auto *UI = new UnreachableInst(Ctx, MergedNormalDest); + UI->setDebugLoc(DebugLoc::getTemporary()); MergedInvoke->setNormalDest(MergedNormalDest); } @@ -3389,7 +3390,7 @@ bool SimplifyCFGOpt::speculativelyExecuteBB(BranchInst *BI, if (!SpeculatedStoreValue || &I != SpeculatedStore) { // Don't update the DILocation of dbg.assign intrinsics. if (!isa(&I)) - I.setDebugLoc(DebugLoc()); + I.setDebugLoc(DebugLoc::getDropped()); } I.dropUBImplyingAttrsAndMetadata(); @@ -5707,7 +5708,8 @@ static void createUnreachableSwitchDefault(SwitchInst *Switch, BasicBlock *NewDefaultBlock = BasicBlock::Create( BB->getContext(), BB->getName() + ".unreachabledefault", BB->getParent(), OrigDefaultBlock); - new UnreachableInst(Switch->getContext(), NewDefaultBlock); + auto *UI = new UnreachableInst(Switch->getContext(), NewDefaultBlock); + UI->setDebugLoc(DebugLoc::getTemporary()); Switch->setDefaultDest(&*NewDefaultBlock); if (DTU) { SmallVector Updates; diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h index b81d582f07e88..70f541d64b305 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h +++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h @@ -153,7 +153,7 @@ class VPBuilder { VPInstruction *createNaryOp(unsigned Opcode, ArrayRef Operands, Instruction *Inst = nullptr, const Twine &Name = "") { - DebugLoc DL; + DebugLoc DL = DebugLoc::getUnknown(); if (Inst) DL = Inst->getDebugLoc(); VPInstruction *NewVPInst = createInstruction(Opcode, Operands, DL, Name); @@ -165,7 +165,8 @@ class VPBuilder { return createInstruction(Opcode, Operands, DL, Name); } VPInstruction *createNaryOp(unsigned Opcode, ArrayRef Operands, - const VPIRFlags &Flags, DebugLoc DL = {}, + const VPIRFlags &Flags, + DebugLoc DL = DebugLoc::getUnknown(), const Twine &Name = "") { return tryInsertInstruction( new VPInstruction(Opcode, Operands, Flags, DL, Name)); @@ -174,7 +175,8 @@ class VPBuilder { VPInstruction *createNaryOp(unsigned Opcode, std::initializer_list Operands, Type *ResultTy, const VPIRFlags &Flags = {}, - DebugLoc DL = {}, const Twine &Name = "") { + DebugLoc DL = DebugLoc::getUnknown(), + const Twine &Name = "") { return tryInsertInstruction( new VPInstructionWithType(Opcode, Operands, ResultTy, Flags, DL, Name)); } @@ -182,22 +184,25 @@ class VPBuilder { VPInstruction *createOverflowingOp(unsigned Opcode, std::initializer_list Operands, VPRecipeWithIRFlags::WrapFlagsTy WrapFlags, - DebugLoc DL = {}, const Twine &Name = "") { + DebugLoc DL = DebugLoc::getUnknown(), + const Twine &Name = "") { return tryInsertInstruction( new VPInstruction(Opcode, Operands, WrapFlags, DL, Name)); } - VPValue *createNot(VPValue *Operand, DebugLoc DL = {}, + VPValue *createNot(VPValue *Operand, DebugLoc DL = DebugLoc::getUnknown(), const Twine &Name = "") { return createInstruction(VPInstruction::Not, {Operand}, DL, Name); } - VPValue *createAnd(VPValue *LHS, VPValue *RHS, DebugLoc DL = {}, + VPValue *createAnd(VPValue *LHS, VPValue *RHS, + DebugLoc DL = DebugLoc::getUnknown(), const Twine &Name = "") { return createInstruction(Instruction::BinaryOps::And, {LHS, RHS}, DL, Name); } - VPValue *createOr(VPValue *LHS, VPValue *RHS, DebugLoc DL = {}, + VPValue *createOr(VPValue *LHS, VPValue *RHS, + DebugLoc DL = DebugLoc::getUnknown(), const Twine &Name = "") { return tryInsertInstruction(new VPInstruction( @@ -205,14 +210,16 @@ class VPBuilder { VPRecipeWithIRFlags::DisjointFlagsTy(false), DL, Name)); } - VPValue *createLogicalAnd(VPValue *LHS, VPValue *RHS, DebugLoc DL = {}, + VPValue *createLogicalAnd(VPValue *LHS, VPValue *RHS, + DebugLoc DL = DebugLoc::getUnknown(), const Twine &Name = "") { return tryInsertInstruction( new VPInstruction(VPInstruction::LogicalAnd, {LHS, RHS}, DL, Name)); } VPValue *createSelect(VPValue *Cond, VPValue *TrueVal, VPValue *FalseVal, - DebugLoc DL = {}, const Twine &Name = "", + DebugLoc DL = DebugLoc::getUnknown(), + const Twine &Name = "", std::optional FMFs = std::nullopt) { auto *Select = FMFs ? new VPInstruction(Instruction::Select, {Cond, TrueVal, FalseVal}, @@ -226,20 +233,23 @@ class VPBuilder { /// and \p B. /// TODO: add createFCmp when needed. VPValue *createICmp(CmpInst::Predicate Pred, VPValue *A, VPValue *B, - DebugLoc DL = {}, const Twine &Name = "") { + DebugLoc DL = DebugLoc::getUnknown(), + const Twine &Name = "") { assert(Pred >= CmpInst::FIRST_ICMP_PREDICATE && Pred <= CmpInst::LAST_ICMP_PREDICATE && "invalid predicate"); return tryInsertInstruction( new VPInstruction(Instruction::ICmp, {A, B}, Pred, DL, Name)); } - VPInstruction *createPtrAdd(VPValue *Ptr, VPValue *Offset, DebugLoc DL = {}, + VPInstruction *createPtrAdd(VPValue *Ptr, VPValue *Offset, + DebugLoc DL = DebugLoc::getUnknown(), const Twine &Name = "") { return tryInsertInstruction( new VPInstruction(VPInstruction::PtrAdd, {Ptr, Offset}, GEPNoWrapFlags::none(), DL, Name)); } - VPValue *createInBoundsPtrAdd(VPValue *Ptr, VPValue *Offset, DebugLoc DL = {}, + VPValue *createInBoundsPtrAdd(VPValue *Ptr, VPValue *Offset, + DebugLoc DL = DebugLoc::getUnknown(), const Twine &Name = "") { return tryInsertInstruction( new VPInstruction(VPInstruction::PtrAdd, {Ptr, Offset}, diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index fc8ebebcf21b7..ca923e4e0b495 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -775,7 +775,7 @@ class EpilogueVectorizerEpilogueLoop : public InnerLoopAndEpilogueVectorizer { /// Look for a meaningful debug location on the instruction or its operands. static DebugLoc getDebugLocFromInstOrOperands(Instruction *I) { if (!I) - return DebugLoc(); + return DebugLoc::getUnknown(); DebugLoc Empty; if (I->getDebugLoc() != Empty) @@ -1884,13 +1884,15 @@ class GeneratedRTChecks { if (SCEVCheckBlock) { SCEVCheckBlock->getTerminator()->moveBefore( Preheader->getTerminator()->getIterator()); - new UnreachableInst(Preheader->getContext(), SCEVCheckBlock); + auto *UI = new UnreachableInst(Preheader->getContext(), SCEVCheckBlock); + UI->setDebugLoc(DebugLoc::getTemporary()); Preheader->getTerminator()->eraseFromParent(); } if (MemCheckBlock) { MemCheckBlock->getTerminator()->moveBefore( Preheader->getTerminator()->getIterator()); - new UnreachableInst(Preheader->getContext(), MemCheckBlock); + auto *UI = new UnreachableInst(Preheader->getContext(), MemCheckBlock); + UI->setDebugLoc(DebugLoc::getTemporary()); Preheader->getTerminator()->eraseFromParent(); } diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index ec40124c57a6a..c3ca22dce0cc4 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -17434,6 +17434,12 @@ static Instruction *propagateMetadata(Instruction *Inst, ArrayRef VL) { return llvm::propagateMetadata(Inst, Insts); } +static DebugLoc getDebugLocFromPHI(PHINode &PN) { + if (DebugLoc DL = PN.getDebugLoc()) + return DL; + return DebugLoc::getUnknown(); +} + Value *BoUpSLP::vectorizeTree(TreeEntry *E) { IRBuilderBase::InsertPointGuard Guard(Builder); @@ -17599,14 +17605,14 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) { auto *PH = cast(VL0); Builder.SetInsertPoint(PH->getParent(), PH->getParent()->getFirstNonPHIIt()); - Builder.SetCurrentDebugLocation(PH->getDebugLoc()); + Builder.SetCurrentDebugLocation(getDebugLocFromPHI(*PH)); PHINode *NewPhi = Builder.CreatePHI(VecTy, PH->getNumIncomingValues()); Value *V = NewPhi; // Adjust insertion point once all PHI's have been generated. Builder.SetInsertPoint(PH->getParent(), PH->getParent()->getFirstInsertionPt()); - Builder.SetCurrentDebugLocation(PH->getDebugLoc()); + Builder.SetCurrentDebugLocation(getDebugLocFromPHI(*PH)); V = FinalShuffle(V, E); @@ -17638,7 +17644,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) { } Builder.SetInsertPoint(IBB->getTerminator()); - Builder.SetCurrentDebugLocation(PH->getDebugLoc()); + Builder.SetCurrentDebugLocation(getDebugLocFromPHI(*PH)); Value *Vec = vectorizeOperand(E, I); if (VecTy != Vec->getType()) { assert((It != MinBWs.end() || getOperandEntry(E, I)->isGather() || diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index 273df55188c16..870e171ae608b 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -1812,9 +1812,9 @@ class VPVectorPointerRecipe : public VPRecipeWithIRFlags, class VPHeaderPHIRecipe : public VPSingleDefRecipe, public VPPhiAccessors { protected: VPHeaderPHIRecipe(unsigned char VPDefID, Instruction *UnderlyingInstr, - VPValue *Start, DebugLoc DL = {}) - : VPSingleDefRecipe(VPDefID, ArrayRef({Start}), UnderlyingInstr, DL) { - } + VPValue *Start, DebugLoc DL = DebugLoc::getUnknown()) + : VPSingleDefRecipe(VPDefID, ArrayRef({Start}), + UnderlyingInstr, DL) {} const VPRecipeBase *getAsRecipe() const override { return this; }