Skip to content

Commit b452b34

Browse files
authored
[DebugInfo][IndVarSimplify] Fix missing debug location updates (#91443)
Adds debug location updates for the newly created `phi`, `add`, `icmp` and `sitofp` instructions in `IndVarSimplify`. Fixes #91436
1 parent b903bad commit b452b34

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,18 @@ bool IndVarSimplify::handleFloatingPointIV(Loop *L, PHINode *PN) {
359359
PHINode::Create(Int32Ty, 2, PN->getName() + ".int", PN->getIterator());
360360
NewPHI->addIncoming(ConstantInt::get(Int32Ty, InitValue),
361361
PN->getIncomingBlock(IncomingEdge));
362+
NewPHI->setDebugLoc(PN->getDebugLoc());
362363

363-
Value *NewAdd =
364+
Instruction *NewAdd =
364365
BinaryOperator::CreateAdd(NewPHI, ConstantInt::get(Int32Ty, IncValue),
365366
Incr->getName() + ".int", Incr->getIterator());
367+
NewAdd->setDebugLoc(Incr->getDebugLoc());
366368
NewPHI->addIncoming(NewAdd, PN->getIncomingBlock(BackEdge));
367369

368370
ICmpInst *NewCompare =
369371
new ICmpInst(TheBr->getIterator(), NewPred, NewAdd,
370372
ConstantInt::get(Int32Ty, ExitValue), Compare->getName());
373+
NewCompare->setDebugLoc(Compare->getDebugLoc());
371374

372375
// In the following deletions, PN may become dead and may be deleted.
373376
// Use a WeakTrackingVH to observe whether this happens.
@@ -391,8 +394,9 @@ bool IndVarSimplify::handleFloatingPointIV(Loop *L, PHINode *PN) {
391394
// We give preference to sitofp over uitofp because it is faster on most
392395
// platforms.
393396
if (WeakPH) {
394-
Value *Conv = new SIToFPInst(NewPHI, PN->getType(), "indvar.conv",
395-
PN->getParent()->getFirstInsertionPt());
397+
Instruction *Conv = new SIToFPInst(NewPHI, PN->getType(), "indvar.conv",
398+
PN->getParent()->getFirstInsertionPt());
399+
Conv->setDebugLoc(PN->getDebugLoc());
396400
PN->replaceAllUsesWith(Conv);
397401
RecursivelyDeleteTriviallyDeadInstructions(PN, TLI, MSSAU.get());
398402
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
; RUN: opt < %s -passes=indvars -S | FileCheck %s
2+
3+
; This testcase checks the preservation of debug locations of newly created
4+
; phi, sitofp, add and icmp instructions in IndVarSimplify Pass.
5+
6+
define void @test1() !dbg !5 {
7+
; CHECK-LABEL: @test1(
8+
; CHECK-NEXT: entry:
9+
; CHECK-NEXT: br label [[BB:%.*]], !dbg
10+
; CHECK: bb:
11+
; CHECK: [[IV_INT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[DOTINT:%.*]], [[BB]] ], !dbg ![[DBG1:[0-9]+]]
12+
; CHECK: [[INDVAR_CONV:%.*]] = sitofp i32 [[IV_INT]] to double, !dbg ![[DBG1]]
13+
; CHECK: [[DOTINT]] = add nuw nsw i32 [[IV_INT]], 1, !dbg ![[DBG2:[0-9]+]]
14+
; CHECK: [[TMP1:%.*]] = icmp ult i32 [[DOTINT]], 10000, !dbg ![[DBG3:[0-9]+]]
15+
; CHECK: ![[DBG1]] = !DILocation(line: 2
16+
; CHECK: ![[DBG2]] = !DILocation(line: 4
17+
; CHECK: ![[DBG3]] = !DILocation(line: 5
18+
;
19+
entry:
20+
br label %bb, !dbg !16
21+
22+
bb: ; preds = %bb, %entry
23+
%iv = phi double [ 0.000000e+00, %entry ], [ %1, %bb ], !dbg !17
24+
%0 = tail call i32 @foo(double %iv), !dbg !18
25+
%1 = fadd double %iv, 1.000000e+00, !dbg !19
26+
%2 = fcmp olt double %1, 1.000000e+04, !dbg !20
27+
br i1 %2, label %bb, label %return, !dbg !21
28+
29+
return: ; preds = %bb
30+
ret void, !dbg !22
31+
}
32+
33+
declare i32 @foo(double)
34+
35+
!llvm.dbg.cu = !{!0}
36+
!llvm.debugify = !{!2, !3}
37+
!llvm.module.flags = !{!4}
38+
39+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
40+
!1 = !DIFile(filename: "indvars-preserving.ll", directory: "/")
41+
!2 = !{i32 7}
42+
!3 = !{i32 4}
43+
!4 = !{i32 2, !"Debug Info Version", i32 3}
44+
!5 = distinct !DISubprogram(name: "test1", linkageName: "test1", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
45+
!6 = !DISubroutineType(types: !7)
46+
!7 = !{}
47+
!8 = !{!9, !11, !13, !14}
48+
!9 = !DILocalVariable(name: "1", scope: !5, file: !1, line: 2, type: !10)
49+
!10 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_unsigned)
50+
!11 = !DILocalVariable(name: "2", scope: !5, file: !1, line: 3, type: !12)
51+
!12 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned)
52+
!13 = !DILocalVariable(name: "3", scope: !5, file: !1, line: 4, type: !10)
53+
!14 = !DILocalVariable(name: "4", scope: !5, file: !1, line: 5, type: !15)
54+
!15 = !DIBasicType(name: "ty8", size: 8, encoding: DW_ATE_unsigned)
55+
!16 = !DILocation(line: 1, column: 1, scope: !5)
56+
!17 = !DILocation(line: 2, column: 1, scope: !5)
57+
!18 = !DILocation(line: 3, column: 1, scope: !5)
58+
!19 = !DILocation(line: 4, column: 1, scope: !5)
59+
!20 = !DILocation(line: 5, column: 1, scope: !5)
60+
!21 = !DILocation(line: 6, column: 1, scope: !5)
61+
!22 = !DILocation(line: 7, column: 1, scope: !5)

0 commit comments

Comments
 (0)