Skip to content

Commit 86ceed7

Browse files
authored
[DebugInfo][LoopDistribute] Salvage debug values using dead instructions in the distributed loops (#137124)
Fix #136532 .
1 parent c9ddaa3 commit 86ceed7

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

llvm/lib/Transforms/Scalar/LoopDistribute.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "llvm/Support/raw_ostream.h"
5959
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
6060
#include "llvm/Transforms/Utils/Cloning.h"
61+
#include "llvm/Transforms/Utils/Local.h"
6162
#include "llvm/Transforms/Utils/LoopUtils.h"
6263
#include "llvm/Transforms/Utils/LoopVersioning.h"
6364
#include "llvm/Transforms/Utils/ValueMapper.h"
@@ -224,6 +225,7 @@ class InstPartition {
224225
// Delete the instructions backwards, as it has a reduced likelihood of
225226
// having to update as many def-use and use-def chains.
226227
for (auto *Inst : reverse(Unused)) {
228+
salvageDebugInfo(*Inst);
227229
if (!Inst->use_empty())
228230
Inst->replaceAllUsesWith(PoisonValue::get(Inst->getType()));
229231
Inst->eraseFromParent();
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
; RUN: opt -passes=loop-distribute -enable-loop-distribute -S < %s | FileCheck %s
2+
3+
; Check that removeUnusedInsts() salvages `dbg_value`s which use dead
4+
; instructions in the distributed loops.
5+
6+
define void @f(ptr noalias %a, ptr noalias %c, ptr noalias %d) !dbg !5 {
7+
; CHECK-LABEL: define void @f(
8+
; CHECK-SAME: ptr noalias [[A:%.*]], ptr noalias [[C:%.*]], ptr noalias [[D:%.*]])
9+
10+
entry:
11+
br label %for.body, !dbg !21
12+
13+
for.body: ; preds = %for.body, %entry
14+
%ind = phi i64 [ 0, %entry ], [ %add, %for.body ], !dbg !22
15+
%add = add nuw nsw i64 %ind, 1, !dbg !23
16+
17+
; CHECK-LABEL: for.body.ldist1:
18+
; CHECK: #dbg_value(!DIArgList(ptr [[D]], i64 [[IND_LDIST1:%.*]]), [[META16:![0-9]+]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 4, DW_OP_mul, DW_OP_plus, DW_OP_stack_value), [[META28:![0-9]+]])
19+
;
20+
%arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind, !dbg !24
21+
#dbg_value(ptr %arrayidxA, !12, !DIExpression(), !24)
22+
%loadA = load i32, ptr %arrayidxA, align 4, !dbg !25
23+
%arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add, !dbg !26
24+
store i32 %loadA, ptr %arrayidxA_plus_4, align 4, !dbg !27
25+
26+
; CHECK-LABEL: for.body:
27+
; CHECK: #dbg_value(!DIArgList(ptr [[A]], i64 [[IND:%.*]]), [[META12:![0-9]+]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 4, DW_OP_mul, DW_OP_plus, DW_OP_stack_value), [[DBG24:![0-9]+]])
28+
;
29+
%arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind, !dbg !28
30+
#dbg_value(ptr %arrayidxD, !16, !DIExpression(), !28)
31+
%loadD = load i32, ptr %arrayidxD, align 4, !dbg !29
32+
%arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind, !dbg !30
33+
store i32 %loadD, ptr %arrayidxC, align 4, !dbg !31
34+
35+
%exitcond = icmp eq i64 %add, 20, !dbg !32
36+
br i1 %exitcond, label %for.end, label %for.body, !dbg !33
37+
38+
for.end: ; preds = %for.body
39+
ret void, !dbg !34
40+
}
41+
42+
!llvm.dbg.cu = !{!0}
43+
!llvm.debugify = !{!2, !3}
44+
!llvm.module.flags = !{!4}
45+
46+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
47+
!1 = !DIFile(filename: "temp.ll", directory: "/")
48+
!2 = !{i32 14}
49+
!3 = !{i32 9}
50+
!4 = !{i32 2, !"Debug Info Version", i32 3}
51+
!5 = distinct !DISubprogram(name: "f", linkageName: "f", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
52+
!6 = !DISubroutineType(types: !7)
53+
!7 = !{}
54+
!8 = !{!12, !16}
55+
!10 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_unsigned)
56+
!12 = !DILocalVariable(name: "3", scope: !5, file: !1, line: 4, type: !10)
57+
!16 = !DILocalVariable(name: "6", scope: !5, file: !1, line: 8, type: !10)
58+
!21 = !DILocation(line: 1, column: 1, scope: !5)
59+
!22 = !DILocation(line: 2, column: 1, scope: !5)
60+
!23 = !DILocation(line: 3, column: 1, scope: !5)
61+
!24 = !DILocation(line: 4, column: 1, scope: !5)
62+
!25 = !DILocation(line: 5, column: 1, scope: !5)
63+
!26 = !DILocation(line: 6, column: 1, scope: !5)
64+
!27 = !DILocation(line: 7, column: 1, scope: !5)
65+
!28 = !DILocation(line: 8, column: 1, scope: !5)
66+
!29 = !DILocation(line: 9, column: 1, scope: !5)
67+
!30 = !DILocation(line: 10, column: 1, scope: !5)
68+
!31 = !DILocation(line: 11, column: 1, scope: !5)
69+
!32 = !DILocation(line: 12, column: 1, scope: !5)
70+
!33 = !DILocation(line: 13, column: 1, scope: !5)
71+
!34 = !DILocation(line: 14, column: 1, scope: !5)
72+
;.
73+
; CHECK: [[META12]] = !DILocalVariable(name: "3"
74+
; CHECK: [[META16]] = !DILocalVariable(name: "6"
75+
; CHECK: [[DBG24]] = !DILocation(line: 4, column: 1
76+
; CHECK: [[META28]] = !DILocation(line: 8, column: 1
77+
;.

0 commit comments

Comments
 (0)