Skip to content

Commit f4230b4

Browse files
committed
[VPlan] Add and use debug location for VPScalarCastRecipe.
Update the recipe it always take a debug location and set it.
1 parent 0fc8fc7 commit f4230b4

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ class VPBuilder {
243243
}
244244

245245
VPScalarCastRecipe *createScalarCast(Instruction::CastOps Opcode, VPValue *Op,
246-
Type *ResultTy) {
247-
return tryInsertInstruction(new VPScalarCastRecipe(Opcode, Op, ResultTy));
246+
Type *ResultTy, DebugLoc DL) {
247+
return tryInsertInstruction(
248+
new VPScalarCastRecipe(Opcode, Op, ResultTy, DL));
248249
}
249250

250251
VPWidenCastRecipe *createWidenCast(Instruction::CastOps Opcode, VPValue *Op,

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8903,7 +8903,8 @@ static VPValue *addResumePhiRecipeForInduction(VPWidenInductionRecipe *WideIV,
89038903
Type *ScalarTypeOfWideIV = TypeInfo.inferScalarType(WideIV);
89048904
if (ScalarTypeOfWideIV != TypeInfo.inferScalarType(EndValue)) {
89058905
EndValue = VectorPHBuilder.createScalarCast(Instruction::Trunc, EndValue,
8906-
ScalarTypeOfWideIV);
8906+
ScalarTypeOfWideIV,
8907+
WideIV->getDebugLoc());
89078908
}
89088909

89098910
auto *ResumePhiRecipe =

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,14 +1580,16 @@ class VPScalarCastRecipe : public VPSingleDefRecipe {
15801580
Value *generate(VPTransformState &State);
15811581

15821582
public:
1583-
VPScalarCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy)
1584-
: VPSingleDefRecipe(VPDef::VPScalarCastSC, {Op}), Opcode(Opcode),
1583+
VPScalarCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy,
1584+
DebugLoc DL)
1585+
: VPSingleDefRecipe(VPDef::VPScalarCastSC, {Op}, DL), Opcode(Opcode),
15851586
ResultTy(ResultTy) {}
15861587

15871588
~VPScalarCastRecipe() override = default;
15881589

15891590
VPScalarCastRecipe *clone() override {
1590-
return new VPScalarCastRecipe(Opcode, getOperand(0), ResultTy);
1591+
return new VPScalarCastRecipe(Opcode, getOperand(0), ResultTy,
1592+
getDebugLoc());
15911593
}
15921594

15931595
VP_CLASSOF_IMPL(VPDef::VPScalarCastSC)

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,6 +2328,7 @@ void VPReplicateRecipe::print(raw_ostream &O, const Twine &Indent,
23282328
#endif
23292329

23302330
Value *VPScalarCastRecipe ::generate(VPTransformState &State) {
2331+
State.setDebugLocFrom(getDebugLoc());
23312332
assert(vputils::onlyFirstLaneUsed(this) &&
23322333
"Codegen only implemented for first lane.");
23332334
switch (Opcode) {

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ static VPScalarIVStepsRecipe *
527527
createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
528528
Instruction::BinaryOps InductionOpcode,
529529
FPMathOperator *FPBinOp, Instruction *TruncI,
530-
VPValue *StartV, VPValue *Step, VPBuilder &Builder) {
530+
VPValue *StartV, VPValue *Step, DebugLoc DL,
531+
VPBuilder &Builder) {
531532
VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
532533
VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
533534
VPSingleDefRecipe *BaseIV = Builder.createDerivedIV(
@@ -542,7 +543,7 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
542543
assert(ResultTy->getScalarSizeInBits() > TruncTy->getScalarSizeInBits() &&
543544
"Not truncating.");
544545
assert(ResultTy->isIntegerTy() && "Truncation requires an integer type");
545-
BaseIV = Builder.createScalarCast(Instruction::Trunc, BaseIV, TruncTy);
546+
BaseIV = Builder.createScalarCast(Instruction::Trunc, BaseIV, TruncTy, DL);
546547
ResultTy = TruncTy;
547548
}
548549

@@ -556,7 +557,7 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
556557
cast<VPBasicBlock>(HeaderVPBB->getSingleHierarchicalPredecessor());
557558
VPBuilder::InsertPointGuard Guard(Builder);
558559
Builder.setInsertPoint(VecPreheader);
559-
Step = Builder.createScalarCast(Instruction::Trunc, Step, ResultTy);
560+
Step = Builder.createScalarCast(Instruction::Trunc, Step, ResultTy, DL);
560561
}
561562
return Builder.createScalarIVSteps(InductionOpcode, FPBinOp, BaseIV, Step);
562563
}
@@ -588,7 +589,7 @@ static void legalizeAndOptimizeInductions(VPlan &Plan) {
588589
VPValue *StepV = PtrIV->getOperand(1);
589590
VPScalarIVStepsRecipe *Steps = createScalarIVSteps(
590591
Plan, InductionDescriptor::IK_IntInduction, Instruction::Add, nullptr,
591-
nullptr, StartV, StepV, Builder);
592+
nullptr, StartV, StepV, PtrIV->getDebugLoc(), Builder);
592593

593594
VPValue *PtrAdd = Builder.createPtrAdd(PtrIV->getStartValue(), Steps,
594595
PtrIV->getDebugLoc(), "next.gep");
@@ -612,7 +613,7 @@ static void legalizeAndOptimizeInductions(VPlan &Plan) {
612613
Plan, ID.getKind(), ID.getInductionOpcode(),
613614
dyn_cast_or_null<FPMathOperator>(ID.getInductionBinOp()),
614615
WideIV->getTruncInst(), WideIV->getStartValue(), WideIV->getStepValue(),
615-
Builder);
616+
WideIV->getDebugLoc(), Builder);
616617

617618
// Update scalar users of IV to use Step instead.
618619
if (!HasOnlyVectorVFs)
@@ -1689,9 +1690,9 @@ bool VPlanTransforms::tryAddExplicitVectorLength(
16891690
VPSingleDefRecipe *OpVPEVL = VPEVL;
16901691
if (unsigned IVSize = CanonicalIVPHI->getScalarType()->getScalarSizeInBits();
16911692
IVSize != 32) {
1692-
OpVPEVL = new VPScalarCastRecipe(IVSize < 32 ? Instruction::Trunc
1693-
: Instruction::ZExt,
1694-
OpVPEVL, CanonicalIVPHI->getScalarType());
1693+
OpVPEVL = new VPScalarCastRecipe(
1694+
IVSize < 32 ? Instruction::Trunc : Instruction::ZExt, OpVPEVL,
1695+
CanonicalIVPHI->getScalarType(), CanonicalIVIncrement->getDebugLoc());
16951696
OpVPEVL->insertBefore(CanonicalIVIncrement);
16961697
}
16971698
auto *NextEVLIV =

llvm/test/Transforms/LoopVectorize/preserve-dbg-loc-and-loop-metadata.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ define void @scalar_cast_dbg(ptr nocapture %a, i32 %start, i64 %k) {
9191
; DEBUGLOC: = trunc i64 %index to i32, !dbg [[CASTLOC:![0-9]+]]
9292
;
9393
; DEBUGLOC: loop:
94-
; DEBUGLOC-NOT: %trunc.iv = trunc i64 %iv to i32, !dbg [[CASTLOC]]
94+
; DEBUGLOC: %trunc.iv = trunc i64 %iv to i32, !dbg [[CASTLOC]]
9595
;
9696
entry:
9797
br label %loop

0 commit comments

Comments
 (0)