1 ; RUN: opt -passes=instcombine %s -S -o - | FileCheck %s
2 ; RUN: opt -passes=instcombine %s -S -o - --try-experimental-debuginfo-iterators | FileCheck %s
3 ; Verify that the eliminated instructions (bitcast, gep, load) are salvaged into
6 ; Originally created from the following C source and then heavily isolated/reduced.
11 ; void scan(struct entry *queue, struct entry *end)
13 ; struct entry *entry;
14 ; for (entry = (struct entry *)((char *)(queue->next) - 8);
15 ; &entry->next == end;
16 ; entry = (struct entry *)((char *)(entry->next) - 8)) {
20 ; ModuleID = '<stdin>'
21 source_filename = "test.c"
22 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
23 target triple = "x86_64-apple-macosx10.12.0"
25 %struct.entry = type { ptr }
27 ; This salvage can't currently occur safely (PR40628), however if/when that's
28 ; ever fixed, then this is definitely a piece of test coverage that should
30 define void @salvage_load(ptr %queue) local_unnamed_addr #0 !dbg !14 {
32 %im_not_dead = alloca ptr
33 %0 = load ptr, ptr %queue, align 8, !dbg !19
34 %1 = load ptr, ptr %queue, align 8, !dbg !19
35 call void @llvm.dbg.value(metadata ptr %1, metadata !18, metadata !20), !dbg !19
36 ; CHECK: define void @salvage_load
38 ; CHECK-NEXT: #dbg_value(ptr poison
39 store ptr %1, ptr %im_not_dead, align 8
43 define void @salvage_bitcast(ptr %queue) local_unnamed_addr #0 !dbg !22 {
45 %im_not_dead = alloca ptr
46 call void @llvm.dbg.value(metadata ptr %queue, metadata !24, metadata !20), !dbg !23
47 ; CHECK: define void @salvage_bitcast
49 ; CHECK-NEXT: #dbg_value(ptr %queue,
50 ; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, 0),
51 store ptr %queue, ptr %im_not_dead, align 8
55 define void @salvage_gep0(ptr %queue, ptr %end) local_unnamed_addr #0 !dbg !25 {
57 %im_not_dead = alloca ptr
58 %0 = getelementptr inbounds %struct.entry, ptr %queue, i32 -1, i32 0, !dbg !26
59 %1 = getelementptr inbounds %struct.entry, ptr %queue, i32 -1, i32 0, !dbg !26
60 call void @llvm.dbg.value(metadata ptr %1, metadata !27, metadata !20), !dbg !26
61 ; CHECK: define void @salvage_gep0
63 ; CHECK-NEXT: #dbg_value(ptr %queue,
64 ; CHECK-SAME: !DIExpression(DW_OP_constu, 8, DW_OP_minus, DW_OP_stack_value),
65 store ptr %1, ptr %im_not_dead, align 8
69 define void @salvage_gep1(ptr %queue, ptr %end) local_unnamed_addr #0 !dbg !28 {
71 %im_not_dead = alloca ptr
72 %0 = getelementptr inbounds %struct.entry, ptr %queue, i32 -1, i32 0, !dbg !29
73 %1 = getelementptr inbounds %struct.entry, ptr %queue, i32 -1, i32 0, !dbg !29
74 call void @llvm.dbg.value(metadata ptr %1, metadata !30, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 32)), !dbg !29
75 ; CHECK: define void @salvage_gep1
77 ; CHECK-NEXT: #dbg_value(ptr %queue,
78 ; CHECK-SAME: !DIExpression(DW_OP_constu, 8, DW_OP_minus, DW_OP_stack_value, DW_OP_LLVM_fragment, 0, 32),
79 store ptr %1, ptr %im_not_dead, align 8
83 define void @salvage_gep2(ptr %queue, ptr %end) local_unnamed_addr #0 !dbg !31 {
85 %im_not_dead = alloca ptr
86 %0 = getelementptr inbounds %struct.entry, ptr %queue, i32 -1, i32 0, !dbg !32
87 %1 = getelementptr inbounds %struct.entry, ptr %queue, i32 -1, i32 0, !dbg !32
88 call void @llvm.dbg.value(metadata ptr %1, metadata !33, metadata !DIExpression(DW_OP_stack_value)), !dbg !32
89 ; CHECK: define void @salvage_gep2
91 ; CHECK-NEXT: #dbg_value(ptr %queue,
92 ; CHECK-SAME: !DIExpression(DW_OP_constu, 8, DW_OP_minus, DW_OP_stack_value),
93 store ptr %1, ptr %im_not_dead, align 8
97 ; Function Attrs: nounwind readnone
98 declare void @llvm.dbg.value(metadata, metadata, metadata) #1
100 attributes #0 = { nounwind ssp uwtable }
101 attributes #1 = { nounwind readnone }
104 !llvm.module.flags = !{!10, !11, !12}
107 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 5.0.0 (trunk 297628) (llvm/trunk 297643)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3)
108 !1 = !DIFile(filename: "test.c", directory: "/")
111 !4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64)
112 !5 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "entry", file: !1, line: 1, size: 64, elements: !6)
114 !7 = !DIDerivedType(tag: DW_TAG_member, name: "next", scope: !5, file: !1, line: 2, baseType: !4, size: 64)
115 !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64)
116 !9 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
117 !10 = !{i32 2, !"Dwarf Version", i32 4}
118 !11 = !{i32 2, !"Debug Info Version", i32 3}
119 !12 = !{i32 1, !"PIC Level", i32 2}
120 !13 = !{!"clang version 5.0.0 (trunk 297628) (llvm/trunk 297643)"}
121 !14 = distinct !DISubprogram(name: "scan", scope: !1, file: !1, line: 4, type: !15, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !17)
122 !15 = !DISubroutineType(types: !16)
123 !16 = !{null, !4, !4}
125 !18 = !DILocalVariable(name: "entry", scope: !14, file: !1, line: 6, type: !4)
126 !19 = !DILocation(line: 6, column: 17, scope: !14)
127 !20 = !DIExpression(DW_OP_plus_uconst, 0)
128 !21 = !DILocation(line: 11, column: 1, scope: !14)
129 !22 = distinct !DISubprogram(name: "scan", scope: !1, file: !1, line: 4, type: !15, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !17)
130 !23 = !DILocation(line: 6, column: 17, scope: !22)
131 !24 = !DILocalVariable(name: "entry", scope: !22, file: !1, line: 6, type: !4)
132 !25 = distinct !DISubprogram(name: "scan", scope: !1, file: !1, line: 4, type: !15, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !17)
133 !26 = !DILocation(line: 6, column: 17, scope: !25)
134 !27 = !DILocalVariable(name: "entry", scope: !25, file: !1, line: 6, type: !4)
135 !28 = distinct !DISubprogram(name: "scan", scope: !1, file: !1, line: 4, type: !15, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !17)
136 !29 = !DILocation(line: 6, column: 17, scope: !28)
137 !30 = !DILocalVariable(name: "entry", scope: !28, file: !1, line: 6, type: !4)
138 !31 = distinct !DISubprogram(name: "scan", scope: !1, file: !1, line: 4, type: !15, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !17)
139 !32 = !DILocation(line: 6, column: 17, scope: !31)
140 !33 = !DILocalVariable(name: "entry", scope: !31, file: !1, line: 6, type: !4)