Reid Kleckner | 29a5c03 | 2017-11-14 21:49:06 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -S -instcombine -instcombine-lower-dbg-declare=0 | FileCheck %s |
| 2 | |
| 3 | ; In this example, instcombine wants to turn "local" into an i64, since that's |
| 4 | ; how it is stored. It should keep the debug info referring to the alloca when |
| 5 | ; it does the replacement. |
| 6 | |
| 7 | ; C source: |
| 8 | ; struct Foo { |
| 9 | ; int x, y; |
| 10 | ; }; |
| 11 | ; void escape(const void*); |
| 12 | ; void f(struct Foo *p) { |
| 13 | ; struct Foo local; |
| 14 | ; *(__int64 *)&local = *(__int64 *)p; |
| 15 | ; escape(&local); |
| 16 | ; } |
| 17 | |
| 18 | ; ModuleID = '<stdin>' |
| 19 | source_filename = "t.c" |
| 20 | target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" |
| 21 | target triple = "x86_64-pc-windows-msvc19.11.25508" |
| 22 | |
| 23 | %struct.Foo = type { i32, i32 } |
| 24 | |
| 25 | define void @f(%struct.Foo* %p) !dbg !11 { |
| 26 | entry: |
| 27 | %local = alloca %struct.Foo, align 4 |
| 28 | %0 = bitcast %struct.Foo* %local to i8*, !dbg !24 |
| 29 | call void @llvm.dbg.declare(metadata %struct.Foo* %local, metadata !22, metadata !DIExpression()), !dbg !25 |
| 30 | %1 = bitcast %struct.Foo* %p to i64*, !dbg !26 |
| 31 | %2 = load i64, i64* %1, align 8, !dbg !26, !tbaa !27 |
| 32 | %3 = bitcast %struct.Foo* %local to i64*, !dbg !31 |
| 33 | store i64 %2, i64* %3, align 4, !dbg !32, !tbaa !27 |
| 34 | %4 = bitcast %struct.Foo* %local to i8*, !dbg !33 |
| 35 | call void @escape(i8* %4), !dbg !34 |
| 36 | %5 = bitcast %struct.Foo* %local to i8*, !dbg !35 |
| 37 | ret void, !dbg !35 |
| 38 | } |
| 39 | |
| 40 | ; CHECK-LABEL: define void @f(%struct.Foo* %p) |
| 41 | ; CHECK: %local = alloca i64, align 8 |
| 42 | ; CHECK: call void @llvm.dbg.declare(metadata i64* %local, metadata !22, metadata !DIExpression()) |
Vedant Kumar | e48597a | 2018-01-26 22:02:52 +0000 | [diff] [blame] | 43 | ; CHECK: [[simplified:%.*]] = bitcast i64* %local to i8* |
Vedant Kumar | 6379a62 | 2018-07-06 17:32:39 +0000 | [diff] [blame] | 44 | ; |
| 45 | ; Another dbg.value for "local" would be redundant here. |
| 46 | ; CHECK-NOT: call void @llvm.dbg.value(metadata i8* [[simplified]], metadata !22, metadata !DIExpression()) |
| 47 | ; |
Johannes Doerfert | 00102c7 | 2019-01-26 23:40:35 +0000 | [diff] [blame] | 48 | ; CHECK: call void @escape(i8* nonnull [[simplified]]) |
Vedant Kumar | e48597a | 2018-01-26 22:02:52 +0000 | [diff] [blame] | 49 | ; CHECK: ret void |
Reid Kleckner | 29a5c03 | 2017-11-14 21:49:06 +0000 | [diff] [blame] | 50 | |
| 51 | declare void @llvm.dbg.declare(metadata, metadata, metadata) |
| 52 | |
| 53 | declare void @escape(i8*) |
| 54 | |
| 55 | !llvm.dbg.cu = !{!0} |
| 56 | !llvm.module.flags = !{!6, !7, !8, !9} |
| 57 | !llvm.ident = !{!10} |
| 58 | |
| 59 | !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3) |
| 60 | !1 = !DIFile(filename: "t.c", directory: "C:\5Csrc\5Cllvm-project\5Cbuild", checksumkind: CSK_MD5, checksum: "d7473625866433067a75fd7d03d2abf7") |
| 61 | !2 = !{} |
| 62 | !3 = !{!4} |
| 63 | !4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64) |
| 64 | !5 = !DIBasicType(name: "long long int", size: 64, encoding: DW_ATE_signed) |
| 65 | !6 = !{i32 2, !"CodeView", i32 1} |
| 66 | !7 = !{i32 2, !"Debug Info Version", i32 3} |
| 67 | !8 = !{i32 1, !"wchar_size", i32 2} |
| 68 | !9 = !{i32 7, !"PIC Level", i32 2} |
| 69 | !10 = !{!"clang version 6.0.0 "} |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 70 | !11 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 5, type: !12, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !20) |
Reid Kleckner | 29a5c03 | 2017-11-14 21:49:06 +0000 | [diff] [blame] | 71 | !12 = !DISubroutineType(types: !13) |
| 72 | !13 = !{null, !14} |
| 73 | !14 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !15, size: 64) |
| 74 | !15 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", file: !1, line: 1, size: 64, elements: !16) |
| 75 | !16 = !{!17, !19} |
| 76 | !17 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !15, file: !1, line: 2, baseType: !18, size: 32) |
| 77 | !18 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) |
| 78 | !19 = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: !15, file: !1, line: 2, baseType: !18, size: 32, offset: 32) |
| 79 | !20 = !{!21, !22} |
| 80 | !21 = !DILocalVariable(name: "p", arg: 1, scope: !11, file: !1, line: 5, type: !14) |
| 81 | !22 = !DILocalVariable(name: "local", scope: !11, file: !1, line: 6, type: !15) |
| 82 | !23 = !DILocation(line: 5, column: 20, scope: !11) |
| 83 | !24 = !DILocation(line: 6, column: 3, scope: !11) |
| 84 | !25 = !DILocation(line: 6, column: 14, scope: !11) |
| 85 | !26 = !DILocation(line: 7, column: 24, scope: !11) |
| 86 | !27 = !{!28, !28, i64 0} |
| 87 | !28 = !{!"long long", !29, i64 0} |
| 88 | !29 = !{!"omnipotent char", !30, i64 0} |
| 89 | !30 = !{!"Simple C/C++ TBAA"} |
| 90 | !31 = !DILocation(line: 7, column: 3, scope: !11) |
| 91 | !32 = !DILocation(line: 7, column: 22, scope: !11) |
| 92 | !33 = !DILocation(line: 8, column: 10, scope: !11) |
| 93 | !34 = !DILocation(line: 8, column: 3, scope: !11) |
| 94 | !35 = !DILocation(line: 9, column: 1, scope: !11) |