llvm.org GIT mirror llvm / e049fdb
[DebugInfo] Fix pr41175 Dead Store Elimination missing debug loc Bug: https://bugs.llvm.org/show_bug.cgi?id=41175 In the bug test case the DSE pass is shortening the range of memory that a memset is working on. A getelementptr is generated so that the new starting address can be passed to memset. This instruction was not given a DebugLoc. To fix the bug, copy the DebugLoc from the memset instruction. Patch by Orlando Cazalet-Hyams! Differential Revision: https://reviews.llvm.org/D60556 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358270 91177308-0d34-0410-b5e6-96231b3b80d8 Jeremy Morse 5 months ago
2 changed file(s) with 90 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
947947 GetElementPtrInst *NewDestGEP = GetElementPtrInst::CreateInBounds(
948948 EarlierIntrinsic->getRawDest()->getType()->getPointerElementType(),
949949 EarlierIntrinsic->getRawDest(), Indices, "", EarlierWrite);
950 NewDestGEP->setDebugLoc(EarlierIntrinsic->getDebugLoc());
950951 EarlierIntrinsic->setDest(NewDestGEP);
951952 EarlierOffset = EarlierOffset + OffsetMoved;
952953 }
0 ; Test that the getelementptr generated when the dse pass determines that
1 ; a memset can be shortened has the debugloc carried over from the memset.
2
3 ; RUN: opt -S -march=native -dse < %s| FileCheck %s
4 ; CHECK: bitcast [5 x i64]* %{{[a-zA-Z_][a-zA-Z0-9_]*}} to i8*, !dbg
5 ; CHECK-NEXT: %{{[0-9]+}} = getelementptr inbounds i8, i8* %0, i64 32, !dbg ![[DBG:[0-9]+]]
6 ; CHECK: ![[DBG]] = !DILocation(line: 2,
7
8 ; The test IR is generated by running:
9 ;
10 ; clang Debugify_Dead_Store_Elimination.cpp -Wno-c++11-narrowing -S \
11 ; -emit-llvm -O0 -w -Xclang -disable-O0-optnone -march=native -fdeclspec \
12 ; --target=x86_64-gnu-linux-unknown -Werror=unreachable-code -o -
13 ;
14 ; Where Debugify_Dead_Store_Elimination.cpp contains:
15 ;
16 ; int a() {
17 ; long b[]{2, 2, 2, 2, 0};
18 ; if (a())
19 ; ;
20 ; }
21
22
23 define dso_local i32 @_Z1av() !dbg !7 {
24 entry:
25 %retval = alloca i32, align 4
26 %b = alloca [5 x i64], align 16
27 call void @llvm.dbg.declare(metadata [5 x i64]* %b, metadata !11, metadata !DIExpression()), !dbg !16
28 %0 = bitcast [5 x i64]* %b to i8*, !dbg !16
29 call void @llvm.memset.p0i8.i64(i8* align 16 %0, i8 0, i64 40, i1 false), !dbg !16
30 %1 = bitcast i8* %0 to [5 x i64]*, !dbg !16
31 %2 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i32 0, i32 0, !dbg !16
32 store i64 2, i64* %2, align 16, !dbg !16
33 %3 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i32 0, i32 1, !dbg !16
34 store i64 2, i64* %3, align 8, !dbg !16
35 %4 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i32 0, i32 2, !dbg !16
36 store i64 2, i64* %4, align 16, !dbg !16
37 %5 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i32 0, i32 3, !dbg !16
38 store i64 2, i64* %5, align 8, !dbg !16
39 %call = call i32 @_Z1av(), !dbg !17
40 %tobool = icmp ne i32 %call, 0, !dbg !17
41 br i1 %tobool, label %if.then, label %if.end, !dbg !19
42
43 if.then: ; preds = %entry
44 br label %if.end, !dbg !19
45
46 if.end: ; preds = %if.then, %entry
47 call void @llvm.trap(), !dbg !20
48 unreachable, !dbg !20
49
50 return: ; No predecessors!
51 %6 = load i32, i32* %retval, align 4, !dbg !21
52 ret i32 %6, !dbg !21
53 }
54
55 ; Function Attrs: nounwind readnone speculatable
56 declare void @llvm.dbg.declare(metadata, metadata, metadata)
57
58 ; Function Attrs: argmemonly nounwind
59 declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg)
60
61 ; Function Attrs: cold noreturn nounwind
62 declare void @llvm.trap()
63
64 !llvm.module.flags = !{!3, !4, !5}
65 !llvm.ident = !{!6}
66
67 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git eb1a156d7f7ba56ea8f9a26da36e6a93d1e98bda)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
68 !1 = !DIFile(filename: "Debugify_Dead_Store_Elimination.cpp", directory: "")
69 !2 = !{}
70 !3 = !{i32 2, !"Dwarf Version", i32 4}
71 !4 = !{i32 2, !"Debug Info Version", i32 3}
72 !5 = !{i32 1, !"wchar_size", i32 4}
73 !6 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git eb1a156d7f7ba56ea8f9a26da36e6a93d1e98bda)"}
74 !7 = distinct !DISubprogram(name: "a", linkageName: "_Z1av", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
75 !8 = !DISubroutineType(types: !9)
76 !9 = !{!10}
77 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
78 !11 = !DILocalVariable(name: "b", scope: !7, file: !1, line: 2, type: !12)
79 !12 = !DICompositeType(tag: DW_TAG_array_type, baseType: !13, size: 320, elements: !14)
80 !13 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)
81 !14 = !{!15}
82 !15 = !DISubrange(count: 5)
83 !16 = !DILocation(line: 2, column: 8, scope: !7)
84 !17 = !DILocation(line: 3, column: 7, scope: !18)
85 !18 = distinct !DILexicalBlock(scope: !7, file: !1, line: 3, column: 7)
86 !19 = !DILocation(line: 3, column: 7, scope: !7)
87 !20 = !DILocation(line: 3, column: 9, scope: !18)
88 !21 = !DILocation(line: 5, column: 1, scope: !7)