llvm.org GIT mirror llvm / 9f32fd2
[EarlyCSE] Salvage debug info during DCE EarlyCSE did not try to salvage debug info during erasing of instructions. This change fixes it. Patch by Djordje Todorovic. Differential Revision: https://reviews.llvm.org/D41496 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322083 91177308-0d34-0410-b5e6-96231b3b80d8 Petar Jovanovic 1 year, 8 months ago
2 changed file(s) with 65 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
716716 // Dead instructions should just be removed.
717717 if (isInstructionTriviallyDead(Inst, &TLI)) {
718718 DEBUG(dbgs() << "EarlyCSE DCE: " << *Inst << '\n');
719 salvageDebugInfo(*Inst);
719720 removeMSSA(Inst);
720721 Inst->eraseFromParent();
721722 Changed = true;
0 ; RUN: opt -early-cse -S %s -o - | FileCheck %s
1 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
2
3 ; Function Attrs: nounwind uwtable
4 define i32 @foo() !dbg !6 {
5 entry:
6 %0 = call i64 @llvm.ctpop.i64(i64 0), !dbg !14
7 %1 = inttoptr i64 %0 to i32*, !dbg !14
8 call void @llvm.dbg.value(metadata i32* %1, i64 0, metadata !11, metadata !13), !dbg !14
9 ; CHECK: call void @llvm.dbg.value(metadata i64 0, metadata !11, metadata !DIExpression()), !dbg !13
10 %call = call i32* (...) @baa(), !dbg !15
11 %2 = ptrtoint i32* %call to i64, !dbg !16
12 %3 = inttoptr i64 %2 to i32*, !dbg !16
13 call void @llvm.dbg.value(metadata i32* %3, i64 0, metadata !11, metadata !13), !dbg !14
14 %tobool = icmp ne i32* %3, null, !dbg !17
15 br i1 %tobool, label %if.end, label %if.then, !dbg !19
16
17 if.then: ; preds = %entry
18 br label %cleanup, !dbg !20
19
20 if.end: ; preds = %entry
21 %4 = ptrtoint i32* %3 to i32, !dbg !21
22 br label %cleanup, !dbg !22
23
24 cleanup: ; preds = %if.end, %if.then
25 %retval.0 = phi i32 [ %4, %if.end ], [ 0, %if.then ]
26 ret i32 %retval.0, !dbg !22
27 }
28
29 declare i32* @baa(...)
30
31 ; Function Attrs: nounwind readnone
32 declare i64 @llvm.ctpop.i64(i64)
33
34 ; Function Attrs: nounwind readnone
35 declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
36
37 !llvm.dbg.cu = !{!0}
38 !llvm.module.flags = !{!3, !4}
39 !llvm.ident = !{!5}
40
41 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
42 !1 = !DIFile(filename: "test.c", directory: "/dir")
43 !2 = !{}
44 !3 = !{i32 2, !"Dwarf Version", i32 4}
45 !4 = !{i32 2, !"Debug Info Version", i32 3}
46 !5 = !{!"clang version 6.0.0"}
47 !6 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !7, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: true, unit: !0, variables: !10)
48 !7 = !DISubroutineType(types: !8)
49 !8 = !{!9}
50 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
51 !10 = !{!11}
52 !11 = !DILocalVariable(name: "ptr", scope: !6, file: !1, line: 4, type: !12)
53 !12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64)
54 !13 = !DIExpression()
55 !14 = !DILocation(line: 4, column: 8, scope: !6)
56 !15 = !DILocation(line: 5, column: 9, scope: !6)
57 !16 = !DILocation(line: 5, column: 7, scope: !6)
58 !17 = !DILocation(line: 7, column: 7, scope: !18)
59 !18 = distinct !DILexicalBlock(scope: !6, file: !1, line: 7, column: 6)
60 !19 = !DILocation(line: 7, column: 6, scope: !6)
61 !20 = !DILocation(line: 8, column: 5, scope: !18)
62 !21 = !DILocation(line: 10, column: 10, scope: !6)
63 !22 = !DILocation(line: 11, column: 1, scope: !6)