Skip to content

Commit 7e71466

Browse files
committed
[VPlan] Preserve dbg location on canonical IVs in native path.
Pass the debug location of the primary IV to addCanonicalIVRecipes in the native path, matching the behavior of inner loop vectorization.
1 parent 9ebaa9d commit 7e71466

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9760,8 +9760,9 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) {
97609760
// Tail folding is not supported for outer loops, so the induction increment
97619761
// is guaranteed to not wrap.
97629762
bool HasNUW = true;
9763-
addCanonicalIVRecipes(*Plan, Legal->getWidestInductionType(), HasNUW,
9764-
DebugLoc());
9763+
addCanonicalIVRecipes(
9764+
*Plan, Legal->getWidestInductionType(), HasNUW,
9765+
getDebugLocFromInstOrOperands(Legal->getPrimaryInduction()));
97659766

97669767
if (!VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(
97679768
Plan,

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ define void @foo(ptr %h) !dbg !4 {
1212
; CHECK: vector.ph:
1313
; CHECK-NEXT: br label [[VECTOR_BODY:%.*]], !dbg [[DBG21]]
1414
; CHECK: vector.body:
15-
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[FOR_COND_CLEANUP32:%.*]] ]
15+
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[FOR_COND_CLEANUP32:%.*]] ], !dbg [[DBG222:![0-9]+]]
1616
; CHECK-NEXT: br label [[FOR_COND5_PREHEADER1:%.*]], !dbg [[DBG21]]
1717
; CHECK: for.cond5.preheader1:
1818
; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x i64> [ zeroinitializer, [[VECTOR_BODY]] ], [ [[TMP4:%.*]], [[FOR_COND5_PREHEADER1]] ], !dbg [[DBG22:![0-9]+]]
@@ -29,9 +29,9 @@ define void @foo(ptr %h) !dbg !4 {
2929
; CHECK-NEXT: [[TMP6:%.*]] = extractelement <4 x i1> [[TMP5]], i32 0, !dbg [[DBG28:![0-9]+]]
3030
; CHECK-NEXT: br i1 [[TMP6]], label [[FOR_COND_CLEANUP32]], label [[FOR_COND5_PREHEADER1]], !dbg [[DBG28]]
3131
; CHECK: vector.latch:
32-
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
33-
; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], 20
34-
; CHECK-NEXT: br i1 [[TMP9]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP29:![0-9]+]]
32+
; 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]+]]
3535
; CHECK: middle.block:
3636
; CHECK-NEXT: br i1 false, label [[EXIT:%.*]], label [[SCALAR_PH]], !dbg [[DBG21]]
3737
; CHECK: scalar.ph:
@@ -156,6 +156,7 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
156156
; CHECK: [[META19]] = distinct !DILexicalBlock(scope: [[META15]], file: [[META1]], line: 11, column: 5)
157157
; CHECK: [[META20]] = !DILocation(line: 0, scope: [[META12]])
158158
; CHECK: [[DBG21]] = !DILocation(line: 10, column: 3, scope: [[META12]])
159+
; CHECK: [[DBG222]] = !DILocation(line: 10, column: 30, scope: [[META16]])
159160
; CHECK: [[DBG22]] = !DILocation(line: 10, column: 5, scope: [[META12]])
160161
; CHECK: [[DBG23]] = !DILocation(line: 13, column: 11, scope: [[META24:![0-9]+]])
161162
; CHECK: [[META24]] = distinct !DILexicalBlock(scope: [[META18]], file: [[META1]], line: 12, column: 7)
@@ -167,7 +168,6 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
167168
; CHECK: [[META30]] = !DILocation(line: 13, column: 13, scope: [[META12]])
168169
; CHECK: [[META31]] = !{!"llvm.loop.isvectorized", i32 1}
169170
; CHECK: [[META32]] = !{!"llvm.loop.unroll.runtime.disable"}
170-
; CHECK: [[DBG33]] = !DILocation(line: 10, column: 30, scope: [[META16]])
171171
; CHECK: [[DBG34]] = !DILocation(line: 10, column: 24, scope: [[META16]])
172172
; CHECK: [[LOOP35]] = distinct !{[[LOOP35]], [[DBG21]], [[META30]], [[META31]]}
173173
; CHECK: [[DBG36]] = !DILocation(line: 14, column: 1, scope: [[DBG4]])

0 commit comments

Comments
 (0)