Skip to content

Commit 470d59d

Browse files
authored
[DebugInfo][Reassociate] Fix missing debug location drop (llvm#95355)
Fix llvm#95343 .
1 parent 527e732 commit 470d59d

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

llvm/lib/Transforms/Scalar/Reassociate.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,13 @@ static Value *NegateValue(Value *V, Instruction *BI,
844844
->getIterator();
845845
}
846846

847+
// Check that if TheNeg is moved out of its parent block, we drop its
848+
// debug location to avoid extra coverage.
849+
// See test dropping_debugloc_the_neg.ll for a detailed example.
850+
if (TheNeg->getParent() != InsertPt->getParent())
851+
TheNeg->dropLocation();
847852
TheNeg->moveBefore(*InsertPt->getParent(), InsertPt);
853+
848854
if (TheNeg->getOpcode() == Instruction::Sub) {
849855
TheNeg->setHasNoUnsignedWrap(false);
850856
TheNeg->setHasNoSignedWrap(false);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
; RUN: opt < %s -passes=reassociate -S | FileCheck %s
2+
3+
; Check that Reassociate's NegateValue() drops the debug location of `%sub2`
4+
; when moving it out of the loop's body (`%for.body`) to `%for.cond`.
5+
6+
define void @fn1(i32 %a, i1 %c, ptr %ptr) !dbg !5 {
7+
; CHECK-LABEL: define void @fn1(
8+
; CHECK: for.cond:
9+
; CHECK: [[SUB2:%.*]] = sub i32 0, %d.0{{$}}
10+
; CHECK: for.body:
11+
;
12+
entry:
13+
br label %for.cond, !dbg !8
14+
15+
for.cond: ; preds = %for.body, %entry
16+
%d.0 = phi i32 [ 1, %entry ], [ 2, %for.body ], !dbg !9
17+
br i1 %c, label %for.end, label %for.body, !dbg !10
18+
19+
for.body: ; preds = %for.cond
20+
%sub1 = sub i32 %a, %d.0, !dbg !11
21+
%dead1 = add i32 %sub1, 1, !dbg !12
22+
%dead2 = mul i32 %dead1, 3, !dbg !13
23+
%dead3 = mul i32 %dead2, %sub1, !dbg !14
24+
%sub2 = sub nsw i32 0, %d.0, !dbg !15
25+
store i32 %sub2, ptr %ptr, align 4, !dbg !16
26+
br label %for.cond, !dbg !17
27+
28+
for.end: ; preds = %for.cond
29+
ret void, !dbg !18
30+
}
31+
32+
!llvm.dbg.cu = !{!0}
33+
!llvm.debugify = !{!2, !3}
34+
!llvm.module.flags = !{!4}
35+
36+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
37+
!1 = !DIFile(filename: "debugloc.ll", directory: "/")
38+
!2 = !{i32 11}
39+
!3 = !{i32 0}
40+
!4 = !{i32 2, !"Debug Info Version", i32 3}
41+
!5 = distinct !DISubprogram(name: "fn1", linkageName: "fn1", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
42+
!6 = !DISubroutineType(types: !7)
43+
!7 = !{}
44+
!8 = !DILocation(line: 1, column: 1, scope: !5)
45+
!9 = !DILocation(line: 2, column: 1, scope: !5)
46+
!10 = !DILocation(line: 3, column: 1, scope: !5)
47+
!11 = !DILocation(line: 4, column: 1, scope: !5)
48+
!12 = !DILocation(line: 5, column: 1, scope: !5)
49+
!13 = !DILocation(line: 6, column: 1, scope: !5)
50+
!14 = !DILocation(line: 7, column: 1, scope: !5)
51+
!15 = !DILocation(line: 8, column: 1, scope: !5)
52+
!16 = !DILocation(line: 9, column: 1, scope: !5)
53+
!17 = !DILocation(line: 10, column: 1, scope: !5)
54+
!18 = !DILocation(line: 11, column: 1, scope: !5)

0 commit comments

Comments
 (0)