Skip to content

Commit cdd7821

Browse files
authored
[DebugInfo][LICM] Fix missing debug location updates (#91729)
1 parent 3773191 commit cdd7821

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,12 +933,14 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI,
933933
ReciprocalDivisor->setFastMathFlags(I.getFastMathFlags());
934934
SafetyInfo->insertInstructionTo(ReciprocalDivisor, I.getParent());
935935
ReciprocalDivisor->insertBefore(&I);
936+
ReciprocalDivisor->setDebugLoc(I.getDebugLoc());
936937

937938
auto Product =
938939
BinaryOperator::CreateFMul(I.getOperand(0), ReciprocalDivisor);
939940
Product->setFastMathFlags(I.getFastMathFlags());
940941
SafetyInfo->insertInstructionTo(Product, I.getParent());
941942
Product->insertAfter(&I);
943+
Product->setDebugLoc(I.getDebugLoc());
942944
I.replaceAllUsesWith(Product);
943945
eraseInstruction(I, *SafetyInfo, MSSAU);
944946

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
; RUN: opt -passes=licm -verify-memoryssa -S < %s | FileCheck %s
2+
3+
; JumpThreading's hoistRegion() replaces the `fdiv` (%v6), of which the second
4+
; operand (%v) is a loop invariant, with a loop invariant `fdiv` and a `fmul`.
5+
; This test checks that the debug location propagates to the new `fmul` from
6+
; the old `fdiv` it replaces in block `loop` and the debug location drop of new
7+
; `fdiv`, which is hoisted to block `entry` after being created.
8+
9+
define zeroext i1 @invariant_denom(double %v) !dbg !5 {
10+
; CHECK: entry:
11+
; CHECK-NEXT: [[TMP0:%.*]] = fdiv fast double 1.000000e+00, [[V:%.*]]{{$}}
12+
; CHECK: loop:
13+
; CHECK: [[TMP1:%.*]] = fmul fast double {{.*}}, !dbg [[DBG12:![0-9]+]]
14+
; CHECK: [[DBG12]] = !DILocation(line: 5,
15+
;
16+
entry:
17+
br label %loop, !dbg !8
18+
19+
loop: ; preds = %loop, %entry
20+
%v3 = phi i32 [ 0, %entry ], [ %v11, %loop ], !dbg !9
21+
%v4 = phi i32 [ 0, %entry ], [ %v12, %loop ], !dbg !10
22+
%v5 = uitofp i32 %v4 to double, !dbg !11
23+
%v6 = fdiv fast double %v5, %v, !dbg !12
24+
%v7 = fptoui double %v6 to i64, !dbg !13
25+
%v8 = and i64 %v7, 1, !dbg !14
26+
%v9 = xor i64 %v8, 1, !dbg !15
27+
%v10 = trunc i64 %v9 to i32, !dbg !16
28+
%v11 = add i32 %v10, %v3, !dbg !17
29+
%v12 = add nuw i32 %v4, 1, !dbg !18
30+
%v13 = icmp eq i32 %v12, -1, !dbg !19
31+
br i1 %v13, label %end, label %loop, !dbg !20
32+
33+
end: ; preds = %loop
34+
%v15 = phi i32 [ %v11, %loop ], !dbg !21
35+
%v16 = icmp ne i32 %v15, 0, !dbg !22
36+
ret i1 %v16, !dbg !23
37+
}
38+
39+
!llvm.dbg.cu = !{!0}
40+
!llvm.debugify = !{!2, !3}
41+
!llvm.module.flags = !{!4}
42+
43+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
44+
!1 = !DIFile(filename: "test.ll", directory: "/")
45+
!2 = !{i32 16}
46+
!3 = !{i32 0}
47+
!4 = !{i32 2, !"Debug Info Version", i32 3}
48+
!5 = distinct !DISubprogram(name: "invariant_denom", linkageName: "invariant_denom", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
49+
!6 = !DISubroutineType(types: !7)
50+
!7 = !{}
51+
!8 = !DILocation(line: 1, column: 1, scope: !5)
52+
!9 = !DILocation(line: 2, column: 1, scope: !5)
53+
!10 = !DILocation(line: 3, column: 1, scope: !5)
54+
!11 = !DILocation(line: 4, column: 1, scope: !5)
55+
!12 = !DILocation(line: 5, column: 1, scope: !5)
56+
!13 = !DILocation(line: 6, column: 1, scope: !5)
57+
!14 = !DILocation(line: 7, column: 1, scope: !5)
58+
!15 = !DILocation(line: 8, column: 1, scope: !5)
59+
!16 = !DILocation(line: 9, column: 1, scope: !5)
60+
!17 = !DILocation(line: 10, column: 1, scope: !5)
61+
!18 = !DILocation(line: 11, column: 1, scope: !5)
62+
!19 = !DILocation(line: 12, column: 1, scope: !5)
63+
!20 = !DILocation(line: 13, column: 1, scope: !5)
64+
!21 = !DILocation(line: 14, column: 1, scope: !5)
65+
!22 = !DILocation(line: 15, column: 1, scope: !5)
66+
!23 = !DILocation(line: 16, column: 1, scope: !5)

0 commit comments

Comments
 (0)