1 ; RUN: opt -instcombine %s -S -o - | FileCheck %s
2 ; Verify that the eliminated instructions (bitcast, gep, load) are salvaged into
5 ; Originally created from the following C source and then heavily isolated/reduced.
10 ; void scan(struct entry *queue, struct entry *end)
12 ; struct entry *entry;
13 ; for (entry = (struct entry *)((char *)(queue->next) - 8);
14 ; &entry->next == end;
15 ; entry = (struct entry *)((char *)(entry->next) - 8)) {
19 ; ModuleID = '<stdin>'
20 source_filename = "test.c"
21 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
22 target triple = "x86_64-apple-macosx10.12.0"
24 %struct.entry = type { %struct.entry* }
26 ; This salvage can't currently occur safely (PR40628), however if/when that's
27 ; ever fixed, then this is definitely a piece of test coverage that should
29 define void @salvage_load(%struct.entry** %queue) local_unnamed_addr #0 !dbg !14 {
31 %im_not_dead = alloca %struct.entry*
32 %0 = load %struct.entry*, %struct.entry** %queue, align 8, !dbg !19
33 %1 = load %struct.entry*, %struct.entry** %queue, align 8, !dbg !19
34 call void @llvm.dbg.value(metadata %struct.entry* %1, metadata !18, metadata !20), !dbg !19
35 ; CHECK: define void @salvage_load
37 ; CHECK-NOT: dbg.value
38 store %struct.entry* %1, %struct.entry** %im_not_dead, align 8
42 define void @salvage_bitcast(%struct.entry* %queue) local_unnamed_addr #0 !dbg !22 {
44 %im_not_dead = alloca i8*
45 %0 = bitcast %struct.entry* %queue to i8*, !dbg !23
46 %1 = bitcast %struct.entry* %queue to i8*, !dbg !23
47 call void @llvm.dbg.value(metadata i8* %1, metadata !24, metadata !20), !dbg !23
48 ; CHECK: define void @salvage_bitcast
50 ; CHECK-NEXT: call void @llvm.dbg.value(metadata %struct.entry* %queue,
51 ; CHECK-SAME: metadata !DIExpression(DW_OP_plus_uconst, 0))
52 store i8* %1, i8** %im_not_dead, align 8
56 define void @salvage_gep0(%struct.entry* %queue, %struct.entry* %end) local_unnamed_addr #0 !dbg !25 {
58 %im_not_dead = alloca %struct.entry**
59 %0 = getelementptr inbounds %struct.entry, %struct.entry* %queue, i32 -1, i32 0, !dbg !26
60 %1 = getelementptr inbounds %struct.entry, %struct.entry* %queue, i32 -1, i32 0, !dbg !26
61 call void @llvm.dbg.value(metadata %struct.entry** %1, metadata !27, metadata !20), !dbg !26
62 ; CHECK: define void @salvage_gep0
64 ; CHECK-NEXT: call void @llvm.dbg.value(metadata %struct.entry* %queue,
65 ; CHECK-SAME: metadata !DIExpression(DW_OP_constu, 8, DW_OP_minus, DW_OP_plus_uconst, 0, DW_OP_stack_value))
66 store %struct.entry** %1, %struct.entry*** %im_not_dead, align 8
70 define void @salvage_gep1(%struct.entry* %queue, %struct.entry* %end) local_unnamed_addr #0 !dbg !28 {
72 %im_not_dead = alloca %struct.entry**
73 %0 = getelementptr inbounds %struct.entry, %struct.entry* %queue, i32 -1, i32 0, !dbg !29
74 %1 = getelementptr inbounds %struct.entry, %struct.entry* %queue, i32 -1, i32 0, !dbg !29
75 call void @llvm.dbg.value(metadata %struct.entry** %1, metadata !30, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 32)), !dbg !29
76 ; CHECK: define void @salvage_gep1
78 ; CHECK-NEXT: call void @llvm.dbg.value(metadata %struct.entry* %queue,
79 ; CHECK-SAME: metadata !DIExpression(DW_OP_constu, 8, DW_OP_minus, DW_OP_stack_value, DW_OP_LLVM_fragment, 0, 32))
80 store %struct.entry** %1, %struct.entry*** %im_not_dead, align 8
84 define void @salvage_gep2(%struct.entry* %queue, %struct.entry* %end) local_unnamed_addr #0 !dbg !31 {
86 %im_not_dead = alloca %struct.entry**
87 %0 = getelementptr inbounds %struct.entry, %struct.entry* %queue, i32 -1, i32 0, !dbg !32
88 %1 = getelementptr inbounds %struct.entry, %struct.entry* %queue, i32 -1, i32 0, !dbg !32
89 call void @llvm.dbg.value(metadata %struct.entry** %1, metadata !33, metadata !DIExpression(DW_OP_stack_value)), !dbg !32
90 ; CHECK: define void @salvage_gep2
92 ; CHECK-NEXT: call void @llvm.dbg.value(metadata %struct.entry* %queue,
93 ; CHECK-SAME: metadata !DIExpression(DW_OP_constu, 8, DW_OP_minus, DW_OP_stack_value))
94 store %struct.entry** %1, %struct.entry*** %im_not_dead, align 8
98 ; Function Attrs: nounwind readnone
99 declare void @llvm.dbg.value(metadata, metadata, metadata) #1
101 attributes #0 = { nounwind ssp uwtable }
102 attributes #1 = { nounwind readnone }
105 !llvm.module.flags = !{!10, !11, !12}
108 !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)
109 !1 = !DIFile(filename: "test.c", directory: "/")
112 !4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64)
113 !5 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "entry", file: !1, line: 1, size: 64, elements: !6)
115 !7 = !DIDerivedType(tag: DW_TAG_member, name: "next", scope: !5, file: !1, line: 2, baseType: !4, size: 64)
116 !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64)
117 !9 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
118 !10 = !{i32 2, !"Dwarf Version", i32 4}
119 !11 = !{i32 2, !"Debug Info Version", i32 3}
120 !12 = !{i32 1, !"PIC Level", i32 2}
121 !13 = !{!"clang version 5.0.0 (trunk 297628) (llvm/trunk 297643)"}
122 !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)
123 !15 = !DISubroutineType(types: !16)
124 !16 = !{null, !4, !4}
126 !18 = !DILocalVariable(name: "entry", scope: !14, file: !1, line: 6, type: !4)
127 !19 = !DILocation(line: 6, column: 17, scope: !14)
128 !20 = !DIExpression(DW_OP_plus_uconst, 0)
129 !21 = !DILocation(line: 11, column: 1, scope: !14)
130 !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)
131 !23 = !DILocation(line: 6, column: 17, scope: !22)
132 !24 = !DILocalVariable(name: "entry", scope: !22, file: !1, line: 6, type: !4)
133 !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)
134 !26 = !DILocation(line: 6, column: 17, scope: !25)
135 !27 = !DILocalVariable(name: "entry", scope: !25, file: !1, line: 6, type: !4)
136 !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)
137 !29 = !DILocation(line: 6, column: 17, scope: !28)
138 !30 = !DILocalVariable(name: "entry", scope: !28, file: !1, line: 6, type: !4)
139 !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)
140 !32 = !DILocation(line: 6, column: 17, scope: !31)
141 !33 = !DILocalVariable(name: "entry", scope: !31, file: !1, line: 6, type: !4)