Reid Kleckner | 0fe506b | 2017-09-21 19:52:03 +0000 | [diff] [blame] | 1 | ; RUN: opt -mem2reg -S < %s | FileCheck %s -implicit-check-not="call void @llvm.dbg.addr" |
| 2 | |
| 3 | ; This example is intended to simulate this pass pipeline, which may not exist |
| 4 | ; in practice: |
| 5 | ; 1. DSE f from the original C source |
| 6 | ; 2. Inline escape |
| 7 | ; 3. mem2reg |
| 8 | ; This exercises the corner case of multiple llvm.dbg.addr intrinsics. |
| 9 | |
| 10 | ; C source: |
| 11 | ; |
| 12 | ; void escape(int *px) { ++*px; } |
| 13 | ; extern int global; |
| 14 | ; void f(int x) { |
| 15 | ; escape(&x); |
| 16 | ; x = 1; // DSE should delete and insert dbg.value(i32 1) |
| 17 | ; global = x; |
| 18 | ; x = 2; // DSE should insert dbg.addr |
| 19 | ; escape(&x); |
| 20 | ; } |
| 21 | |
| 22 | ; ModuleID = 'dse.c' |
| 23 | source_filename = "dse.c" |
| 24 | target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" |
| 25 | target triple = "x86_64-pc-windows-msvc19.0.24215" |
| 26 | |
| 27 | declare void @llvm.dbg.addr(metadata, metadata, metadata) #2 |
| 28 | declare void @llvm.dbg.value(metadata, metadata, metadata) #2 |
| 29 | |
| 30 | @global = external global i32, align 4 |
| 31 | |
| 32 | ; Function Attrs: nounwind uwtable |
| 33 | define void @f(i32 %x) #0 !dbg !8 { |
| 34 | entry: |
| 35 | %x.addr = alloca i32, align 4 |
| 36 | store i32 %x, i32* %x.addr, align 4 |
| 37 | call void @llvm.dbg.addr(metadata i32* %x.addr, metadata !13, metadata !DIExpression()), !dbg !18 |
| 38 | %ld.1 = load i32, i32* %x.addr, align 4, !dbg !19 |
| 39 | %inc.1 = add nsw i32 %ld.1, 1, !dbg !19 |
| 40 | store i32 %inc.1, i32* %x.addr, align 4, !dbg !19 |
| 41 | call void @llvm.dbg.value(metadata i32 1, metadata !13, metadata !DIExpression()), !dbg !20 |
| 42 | store i32 1, i32* @global, align 4, !dbg !22 |
| 43 | call void @llvm.dbg.addr(metadata i32* %x.addr, metadata !13, metadata !DIExpression()), !dbg !23 |
| 44 | store i32 2, i32* %x.addr, align 4, !dbg !23 |
| 45 | %ld.2 = load i32, i32* %x.addr, align 4, !dbg !19 |
| 46 | %inc.2 = add nsw i32 %ld.2, 1, !dbg !19 |
| 47 | store i32 %inc.2, i32* %x.addr, align 4, !dbg !19 |
| 48 | ret void, !dbg !25 |
| 49 | } |
| 50 | |
| 51 | ; CHECK-LABEL: define void @f(i32 %x) |
| 52 | ; CHECK: call void @llvm.dbg.value(metadata i32 %x, metadata !13, metadata !DIExpression()) |
| 53 | ; CHECK: %inc.1 = add nsw i32 %x, 1 |
| 54 | ; CHECK: call void @llvm.dbg.value(metadata i32 %inc.1, metadata !13, metadata !DIExpression()) |
| 55 | ; CHECK: call void @llvm.dbg.value(metadata i32 1, metadata !13, metadata !DIExpression()) |
| 56 | ; CHECK: store i32 1, i32* @global, align 4 |
| 57 | ; CHECK: call void @llvm.dbg.value(metadata i32 2, metadata !13, metadata !DIExpression()) |
| 58 | ; CHECK: %inc.2 = add nsw i32 2, 1 |
| 59 | ; CHECK: call void @llvm.dbg.value(metadata i32 %inc.2, metadata !13, metadata !DIExpression()) |
| 60 | ; CHECK: ret void |
| 61 | |
| 62 | attributes #0 = { nounwind uwtable } |
| 63 | attributes #2 = { nounwind readnone speculatable } |
| 64 | |
| 65 | !llvm.dbg.cu = !{!0} |
| 66 | !llvm.module.flags = !{!3, !4, !5, !6} |
| 67 | !llvm.ident = !{!7} |
| 68 | |
| 69 | !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) |
| 70 | !1 = !DIFile(filename: "dse.c", directory: "C:\5Csrc\5Cllvm-project\5Cbuild") |
| 71 | !2 = !{} |
| 72 | !3 = !{i32 2, !"Dwarf Version", i32 4} |
| 73 | !4 = !{i32 2, !"Debug Info Version", i32 3} |
| 74 | !5 = !{i32 1, !"wchar_size", i32 2} |
| 75 | !6 = !{i32 7, !"PIC Level", i32 2} |
| 76 | !7 = !{!"clang version 6.0.0 "} |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 77 | !8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 3, type: !9, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12) |
Reid Kleckner | 0fe506b | 2017-09-21 19:52:03 +0000 | [diff] [blame] | 78 | !9 = !DISubroutineType(types: !10) |
| 79 | !10 = !{null, !11} |
| 80 | !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) |
| 81 | !12 = !{!13} |
| 82 | !13 = !DILocalVariable(name: "x", arg: 1, scope: !8, file: !1, line: 3, type: !11) |
| 83 | !14 = !{!15, !15, i64 0} |
| 84 | !15 = !{!"int", !16, i64 0} |
| 85 | !16 = !{!"omnipotent char", !17, i64 0} |
| 86 | !17 = !{!"Simple C/C++ TBAA"} |
| 87 | !18 = !DILocation(line: 3, column: 12, scope: !8) |
| 88 | !19 = !DILocation(line: 4, column: 3, scope: !8) |
| 89 | !20 = !DILocation(line: 5, column: 5, scope: !8) |
| 90 | !21 = !DILocation(line: 6, column: 12, scope: !8) |
| 91 | !22 = !DILocation(line: 6, column: 10, scope: !8) |
| 92 | !23 = !DILocation(line: 7, column: 5, scope: !8) |
| 93 | !24 = !DILocation(line: 8, column: 3, scope: !8) |
| 94 | !25 = !DILocation(line: 9, column: 1, scope: !8) |