Skip to content

Commit d83d09f

Browse files
authored
[DebugInfo][LoopStrengthReduce] Fix missing debug location updates (#97519)
Fix #97510 . Note that, for the new phi instruction `NewPH`, which replaces the old phi `PH` and the cast `ShadowUse`, I choose to propagate the debug location of `PH` to it, because the cast is eliminated according to the optimization semantics.
1 parent 6441df3 commit d83d09f

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,13 +2404,15 @@ void LSRInstance::OptimizeShadowIV() {
24042404

24052405
/* Add new PHINode. */
24062406
PHINode *NewPH = PHINode::Create(DestTy, 2, "IV.S.", PH->getIterator());
2407+
NewPH->setDebugLoc(PH->getDebugLoc());
24072408

24082409
/* create new increment. '++d' in above example. */
24092410
Constant *CFP = ConstantFP::get(DestTy, C->getZExtValue());
24102411
BinaryOperator *NewIncr = BinaryOperator::Create(
24112412
Incr->getOpcode() == Instruction::Add ? Instruction::FAdd
24122413
: Instruction::FSub,
24132414
NewPH, CFP, "IV.S.next.", Incr->getIterator());
2415+
NewIncr->setDebugLoc(Incr->getDebugLoc());
24142416

24152417
NewPH->addIncoming(NewInit, PH->getIncomingBlock(Entry));
24162418
NewPH->addIncoming(NewIncr, PH->getIncomingBlock(Latch));
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
; RUN: opt -S -passes=loop-reduce -mtriple=x86_64-unknown-unknown < %s | FileCheck %s
2+
3+
; Check that LoopStrengthReduce's OptimizeShadowIV() propagates the debug
4+
; locations of the old phi (`%accum`) and binop (`%accum.next`) instruction
5+
; to the new phi and binop instruction, respectively.
6+
7+
target datalayout = "n8:16:32:64"
8+
9+
define i32 @foobar6() !dbg !5 {
10+
; CHECK-LABEL: define i32 @foobar6(
11+
; CHECK: loop:
12+
; CHECK: [[IV_S_:%.*]] = phi double [ -3.220000e+03, %[[ENTRY:.*]] ], [ [[IV_S_NEXT_:%.*]], %loop ], !dbg [[DBG9:![0-9]+]]
13+
; CHECK: [[IV_S_NEXT_]] = fadd double [[IV_S_]], 0x41624E65A0000000, !dbg [[DBG11:![0-9]+]]
14+
; CHECK: exit:
15+
;
16+
entry:
17+
br label %loop, !dbg !8
18+
19+
loop: ; preds = %loop, %entry
20+
%accum = phi i32 [ -3220, %entry ], [ %accum.next, %loop ], !dbg !9
21+
%iv = phi i32 [ 12, %entry ], [ %iv.next, %loop ], !dbg !10
22+
%tmp1 = sitofp i32 %accum to double, !dbg !11
23+
tail call void @foo(double %tmp1), !dbg !12
24+
%accum.next = add nsw i32 %accum, 9597741, !dbg !13
25+
%iv.next = add nuw nsw i32 %iv, 1, !dbg !14
26+
%exitcond = icmp ugt i32 %iv, 235, !dbg !15
27+
br i1 %exitcond, label %exit, label %loop, !dbg !16
28+
29+
exit: ; preds = %loop
30+
ret i32 %accum.next, !dbg !17
31+
}
32+
33+
declare void @foo(double)
34+
35+
!llvm.dbg.cu = !{!0}
36+
!llvm.debugify = !{!2, !3}
37+
!llvm.module.flags = !{!4}
38+
39+
; CHECK: [[DBG9]] = !DILocation(line: 2,
40+
; CHECK: [[DBG11]] = !DILocation(line: 6,
41+
42+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
43+
!1 = !DIFile(filename: "main.ll", directory: "/")
44+
!2 = !{i32 10}
45+
!3 = !{i32 0}
46+
!4 = !{i32 2, !"Debug Info Version", i32 3}
47+
!5 = distinct !DISubprogram(name: "foobar6", linkageName: "foobar6", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
48+
!6 = !DISubroutineType(types: !7)
49+
!7 = !{}
50+
!8 = !DILocation(line: 1, column: 1, scope: !5)
51+
!9 = !DILocation(line: 2, column: 1, scope: !5)
52+
!10 = !DILocation(line: 3, column: 1, scope: !5)
53+
!11 = !DILocation(line: 4, column: 1, scope: !5)
54+
!12 = !DILocation(line: 5, column: 1, scope: !5)
55+
!13 = !DILocation(line: 6, column: 1, scope: !5)
56+
!14 = !DILocation(line: 7, column: 1, scope: !5)
57+
!15 = !DILocation(line: 8, column: 1, scope: !5)
58+
!16 = !DILocation(line: 9, column: 1, scope: !5)
59+
!17 = !DILocation(line: 10, column: 1, scope: !5)

0 commit comments

Comments
 (0)