blob: e23aef7334d591dcc0535bf9fbd6cd679d662e49 [file] [log] [blame]
Adrian Prantl47ea6472017-03-16 21:14:09 +00001; RUN: opt -instcombine %s -S -o - | FileCheck %s
2; Verify that the eliminated instructions (bitcast, gep, load) are salvaged into
3; a DIExpression.
4;
5; Originally created from the following C source and then heavily isolated/reduced.
6;
7; struct entry {
8; struct entry *next;
9; };
10; void scan(struct entry *queue, struct entry *end)
11; {
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)) {
16; }
17; }
18
19; ModuleID = '<stdin>'
20source_filename = "test.c"
21target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
22target triple = "x86_64-apple-macosx10.12.0"
23
24%struct.entry = type { %struct.entry* }
25
26; Function Attrs: nounwind ssp uwtable
27define void @salvage_load(%struct.entry** %queue) local_unnamed_addr #0 !dbg !14 {
28entry:
29 %im_not_dead = alloca %struct.entry*
30 %0 = load %struct.entry*, %struct.entry** %queue, align 8, !dbg !19
31 %1 = load %struct.entry*, %struct.entry** %queue, align 8, !dbg !19
32 call void @llvm.dbg.value(metadata %struct.entry* %1, i64 0, metadata !18, metadata !20), !dbg !19
33; CHECK: define void @salvage_load
34; CHECK-NEXT: entry:
35; CHECK-NEXT: call void @llvm.dbg.value(metadata %struct.entry** %queue, i64 0,
36; CHECK-SAME: metadata ![[LOAD_EXPR:[0-9]+]])
37 store %struct.entry* %1, %struct.entry** %im_not_dead, align 8
38 ret void, !dbg !21
39}
40
41; Function Attrs: nounwind ssp uwtable
42define void @salvage_bitcast(%struct.entry* %queue) local_unnamed_addr #0 !dbg !14 {
43entry:
44 %im_not_dead = alloca i8*
45 %0 = bitcast %struct.entry* %queue to i8*, !dbg !19
46 %1 = bitcast %struct.entry* %queue to i8*, !dbg !19
47 call void @llvm.dbg.value(metadata i8* %1, i64 0, metadata !18, metadata !20), !dbg !19
48; CHECK: define void @salvage_bitcast
49; CHECK-NEXT: entry:
50; CHECK-NEXT: call void @llvm.dbg.value(metadata %struct.entry* %queue, i64 0,
51; CHECK-SAME: metadata ![[BITCAST_EXPR:[0-9]+]])
52 store i8* %1, i8** %im_not_dead, align 8
53 ret void, !dbg !21
54}
55
56; Function Attrs: nounwind ssp uwtable
57define void @salvage_gep(%struct.entry* %queue, %struct.entry* %end) local_unnamed_addr #0 !dbg !14 {
58entry:
59 %im_not_dead = alloca %struct.entry**
60 %0 = getelementptr inbounds %struct.entry, %struct.entry* %queue, i32 -1, i32 0, !dbg !19
61 %1 = getelementptr inbounds %struct.entry, %struct.entry* %queue, i32 -1, i32 0, !dbg !19
62 call void @llvm.dbg.value(metadata %struct.entry** %1, i64 0, metadata !18, metadata !20), !dbg !19
63; CHECK: define void @salvage_gep
64; CHECK-NEXT: entry:
65; CHECK-NEXT: call void @llvm.dbg.value(metadata %struct.entry* %queue, i64 0,
66; CHECK-SAME: metadata ![[GEP_EXPR:[0-9]+]])
67 store %struct.entry** %1, %struct.entry*** %im_not_dead, align 8
68 ret void, !dbg !21
69}
70
71; CHECK: ![[LOAD_EXPR]] = !DIExpression(DW_OP_deref, DW_OP_plus, 0)
72; CHECK: ![[BITCAST_EXPR]] = !DIExpression(DW_OP_plus, 0)
73; CHECK: ![[GEP_EXPR]] = !DIExpression(DW_OP_minus, 8, DW_OP_plus, 0)
74
75; Function Attrs: nounwind readnone
76declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1
77
78attributes #0 = { nounwind ssp uwtable }
79attributes #1 = { nounwind readnone }
80
81!llvm.dbg.cu = !{!0}
82!llvm.module.flags = !{!10, !11, !12}
83!llvm.ident = !{!13}
84
85!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)
86!1 = !DIFile(filename: "test.c", directory: "/")
87!2 = !{}
88!3 = !{!4, !8}
89!4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64)
90!5 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "entry", file: !1, line: 1, size: 64, elements: !6)
91!6 = !{!7}
92!7 = !DIDerivedType(tag: DW_TAG_member, name: "next", scope: !5, file: !1, line: 2, baseType: !4, size: 64)
93!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64)
94!9 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
95!10 = !{i32 2, !"Dwarf Version", i32 4}
96!11 = !{i32 2, !"Debug Info Version", i32 3}
97!12 = !{i32 1, !"PIC Level", i32 2}
98!13 = !{!"clang version 5.0.0 (trunk 297628) (llvm/trunk 297643)"}
99!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, variables: !17)
100!15 = !DISubroutineType(types: !16)
101!16 = !{null, !4, !4}
102!17 = !{!18}
103!18 = !DILocalVariable(name: "entry", scope: !14, file: !1, line: 6, type: !4)
104!19 = !DILocation(line: 6, column: 17, scope: !14)
105!20 = !DIExpression(DW_OP_plus, 0)
106!21 = !DILocation(line: 11, column: 1, scope: !14)