Skip to content

Commit aff1242

Browse files
authored
[LV] Align debug location of the widen-phi to the original phi. (#120338)
This patch align the debug location of the widen-phi to the debug location of original phi. Split from: #120054
1 parent 7746596 commit aff1242

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,9 +2304,10 @@ class VPWidenPHIRecipe : public VPSingleDefRecipe {
23042304
SmallVector<VPBasicBlock *, 2> IncomingBlocks;
23052305

23062306
public:
2307-
/// Create a new VPWidenPHIRecipe for \p Phi with start value \p Start.
2308-
VPWidenPHIRecipe(PHINode *Phi, VPValue *Start = nullptr)
2309-
: VPSingleDefRecipe(VPDef::VPWidenPHISC, ArrayRef<VPValue *>(), Phi) {
2307+
/// Create a new VPWidenPHIRecipe for \p Phi with start value \p Start and
2308+
/// debug location \p DL.
2309+
VPWidenPHIRecipe(PHINode *Phi, VPValue *Start = nullptr, DebugLoc DL = {})
2310+
: VPSingleDefRecipe(VPDef::VPWidenPHISC, ArrayRef<VPValue *>(), Phi, DL) {
23102311
if (Start)
23112312
addOperand(Start);
23122313
}

llvm/lib/Transforms/Vectorize/VPlanHCFGBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ void PlainCFGBuilder::createVPInstructionsForVPBB(VPBasicBlock *VPBB,
308308
// Phi node's operands may have not been visited at this point. We create
309309
// an empty VPInstruction that we will fix once the whole plain CFG has
310310
// been built.
311-
NewVPV = new VPWidenPHIRecipe(Phi);
311+
NewVPV = new VPWidenPHIRecipe(Phi, nullptr, Phi->getDebugLoc());
312312
VPBB->appendRecipe(cast<VPWidenPHIRecipe>(NewVPV));
313313
PhisToFix.push_back(Phi);
314314
} else {

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3514,6 +3514,7 @@ void VPWidenPHIRecipe::execute(VPTransformState &State) {
35143514
assert(EnableVPlanNativePath &&
35153515
"Non-native vplans are not expected to have VPWidenPHIRecipes.");
35163516

3517+
State.setDebugLocFrom(getDebugLoc());
35173518
Value *Op0 = State.get(getOperand(0));
35183519
Type *VecTy = Op0->getType();
35193520
Value *VecPhi = State.Builder.CreatePHI(VecTy, 2, "vec.phi");

llvm/test/Transforms/LoopVectorize/dbg-outer-loop-vect.ll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ define void @foo(ptr %h) !dbg !4 {
1515
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[FOR_COND_CLEANUP32:%.*]] ]
1616
; CHECK-NEXT: br label [[FOR_COND5_PREHEADER1:%.*]], !dbg [[DBG21]]
1717
; CHECK: for.cond5.preheader1:
18-
; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x i64> [ zeroinitializer, [[VECTOR_BODY]] ], [ [[TMP4:%.*]], [[FOR_COND5_PREHEADER1]] ], !dbg [[DBG21]]
19-
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr i32, ptr [[H]], <4 x i64> [[VEC_PHI]], !dbg [[DBG21]]
18+
; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x i64> [ zeroinitializer, [[VECTOR_BODY]] ], [ [[TMP4:%.*]], [[FOR_COND5_PREHEADER1]] ], !dbg [[DBG34:![0-9]+]]
19+
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr i32, ptr [[H]], <4 x i64> [[VEC_PHI]]
2020
; CHECK-NEXT: call void @llvm.masked.scatter.v4i32.v4p0(<4 x i32> zeroinitializer, <4 x ptr> [[TMP0]], i32 4, <4 x i1> splat (i1 true)), !dbg [[DBG22:![0-9]+]]
2121
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr i32, <4 x ptr> [[TMP0]], i64 1, !dbg [[DBG22]]
2222
; CHECK-NEXT: call void @llvm.masked.scatter.v4i32.v4p0(<4 x i32> splat (i32 1), <4 x ptr> [[TMP1]], i32 4, <4 x i1> splat (i1 true)), !dbg [[DBG22]]
@@ -42,7 +42,7 @@ define void @foo(ptr %h) !dbg !4 {
4242
; CHECK-NEXT: #dbg_value(i64 [[I_023]], [[META11]], !DIExpression(), [[META20]])
4343
; CHECK-NEXT: br label [[FOR_COND5_PREHEADER:%.*]], !dbg [[DBG26]]
4444
; CHECK: for.cond5.preheader:
45-
; CHECK-NEXT: [[L_022:%.*]] = phi i64 [ 0, [[FOR_COND1_PREHEADER]] ], [ [[INC10:%.*]], [[FOR_COND5_PREHEADER]] ]
45+
; CHECK-NEXT: [[L_022:%.*]] = phi i64 [ 0, [[FOR_COND1_PREHEADER]] ], [ [[INC10:%.*]], [[FOR_COND5_PREHEADER]] ], !dbg [[DBG34]]
4646
; CHECK-NEXT: [[TMP10:%.*]] = getelementptr i32, ptr [[H]], i64 [[L_022]]
4747
; CHECK-NEXT: store i32 0, ptr [[TMP10]], align 4, !dbg [[DBG22]]
4848
; CHECK-NEXT: [[ARRAYIDX_1:%.*]] = getelementptr i32, ptr [[TMP10]], i64 1, !dbg [[DBG31:![0-9]+]]
@@ -72,7 +72,7 @@ for.cond1.preheader: ; preds = %entry, %for.cond.cl
7272
br label %for.cond5.preheader, !dbg !22
7373

7474
for.cond5.preheader: ; preds = %for.cond1.preheader, %for.cond5.preheader
75-
%l.022 = phi i64 [ 0, %for.cond1.preheader ], [ %inc10, %for.cond5.preheader ]
75+
%l.022 = phi i64 [ 0, %for.cond1.preheader ], [ %inc10, %for.cond5.preheader ], !dbg !34
7676
%0 = getelementptr i32, ptr %h, i64 %l.022
7777
store i32 0, ptr %0, align 4, !dbg !24
7878
%arrayidx.1 = getelementptr i32, ptr %0, i64 1, !dbg !26
@@ -134,6 +134,7 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
134134
!31 = distinct !{!31, !21, !32, !33}
135135
!32 = !DILocation(line: 13, column: 13, scope: !12)
136136
!33 = !{!"llvm.loop.vectorize.enable", i1 true}
137+
!34 = !DILocation(line: 10, column: 5, scope: !12)
137138
;.
138139
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
139140
; CHECK: [[META1]] = !DIFile(filename: "outer-loop-vect.c", directory: {{.*}})

0 commit comments

Comments
 (0)