Skip to content

Commit 82e4b83

Browse files
committed
[VPlan] Use terminator debug loc for latch BranchOnCond.
Update VPlan to consistently use the latch branch debug location for the latch branch in the vector loop, if there is one.
1 parent b60aed6 commit 82e4b83

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,12 @@ static void addCanonicalIVRecipes(VPlan &Plan, VPBasicBlock *HeaderVPBB,
437437

438438
// We are about to replace the branch to exit the region. Remove the original
439439
// BranchOnCond, if there is any.
440+
DebugLoc LatchDL = DL;
440441
if (!LatchVPBB->empty() &&
441-
match(&LatchVPBB->back(), m_BranchOnCond(m_VPValue())))
442+
match(&LatchVPBB->back(), m_BranchOnCond(m_VPValue()))) {
443+
LatchDL = LatchVPBB->getTerminator()->getDebugLoc();
442444
LatchVPBB->getTerminator()->eraseFromParent();
445+
}
443446

444447
VPBuilder Builder(LatchVPBB);
445448
// Add a VPInstruction to increment the scalar canonical IV by VF * UF.
@@ -452,7 +455,8 @@ static void addCanonicalIVRecipes(VPlan &Plan, VPBasicBlock *HeaderVPBB,
452455

453456
// Add the BranchOnCount VPInstruction to the latch.
454457
Builder.createNaryOp(VPInstruction::BranchOnCount,
455-
{CanonicalIVIncrement, &Plan.getVectorTripCount()}, DL);
458+
{CanonicalIVIncrement, &Plan.getVectorTripCount()},
459+
LatchDL);
456460
}
457461

458462
void VPlanTransforms::prepareForVectorization(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ define void @foo(ptr %h) !dbg !4 {
3030
; CHECK-NEXT: br i1 [[TMP6]], label [[FOR_COND_CLEANUP32]], label [[FOR_COND5_PREHEADER1]], !dbg [[DBG28]]
3131
; CHECK: vector.latch:
3232
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4, !dbg [[DBG222]]
33-
; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], 20, !dbg [[DBG222]]
34-
; CHECK-NEXT: br i1 [[TMP9]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !dbg [[DBG222]], !llvm.loop [[LOOP29:![0-9]+]]
33+
; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], 20, !dbg [[DBG21]]
34+
; CHECK-NEXT: br i1 [[TMP9]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !dbg [[DBG21]], !llvm.loop [[LOOP29:![0-9]+]]
3535
; CHECK: middle.block:
3636
; CHECK-NEXT: br i1 false, label [[EXIT:%.*]], label [[SCALAR_PH]], !dbg [[DBG21]]
3737
; CHECK: scalar.ph:

llvm/test/Transforms/LoopVectorize/debugloc.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3
1414
; CHECK: load <2 x i32>, ptr {{.*}}, !dbg ![[LOC1]]
1515
; CHECK: add <2 x i32> {{.*}}, !dbg ![[LOC1]]
1616
; CHECK: add nuw i64 %index, 2, !dbg ![[LOC1]]
17-
; CHECK: icmp eq i64 %index.next, %n.vec, !dbg ![[LOC1]]
17+
; CHECK: icmp eq i64 %index.next, %n.vec, !dbg ![[BR_LOC:[0-9]+]]
1818
; CHECK: middle.block
19-
; CHECK: call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> %{{.*}}), !dbg ![[BR_LOC:[0-9]+]]
19+
; CHECK: call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> %{{.*}}), !dbg ![[BR_LOC]]
2020
; CHECK: for.body
2121
; CHECK: br i1{{.*}}, label %for.body,{{.*}}, !dbg ![[BR_LOC]],
2222

0 commit comments

Comments
 (0)