1 ; RUN: opt -S -passes=instcombine %s | FileCheck %s -check-prefix=RUN-ONCE
2 ; RUN: opt -S -passes=instcombine %s --try-experimental-debuginfo-iterators | FileCheck %s -check-prefix=RUN-ONCE
4 ; This example was reduced from a test case in which InstCombine ran at least
6 ; - The first InstCombine run converted dbg.declares to dbg.values using the
7 ; LowerDbgDeclare utility. This produced a dbg.value(ptr %2, DW_OP_deref)
8 ; (this happens when the contents of an alloca are passed by-value), and a
9 ; dbg.value(i32 %0) (due to the store of %0 into the alloca).
10 ; - The second InstCombine run deleted the alloca (%2).
11 ; Check that the DW_OP_deref dbg.value is deleted, just like a dbg.declare would
14 ; RUN-ONCE-LABEL: @t1(
15 ; RUN-ONCE-NEXT: llvm.dbg.value(metadata i32 %0, metadata [[t1_arg0:![0-9]+]], metadata !DIExpression())
16 ; RUN-ONCE-NEXT: llvm.dbg.value(metadata ptr poison, metadata [[t1_fake_ptr:![0-9]+]], metadata !DIExpression())
17 ; RUN-ONCE-NEXT: ret void
18 define void @t1(i32) !dbg !9 {
19 %2 = alloca i32, align 4
20 store i32 %0, ptr %2, align 4
21 call void @llvm.dbg.value(metadata i32 %0, metadata !14, metadata !DIExpression()), !dbg !15
22 call void @llvm.dbg.value(metadata ptr %2, metadata !14, metadata !DIExpression(DW_OP_deref)), !dbg !15
23 call void @llvm.dbg.value(metadata ptr %2, metadata !20, metadata !DIExpression()), !dbg !15
27 ; This example is closer to an end-to-end test: the IR looks like it could have
28 ; been produced by a frontend compiling at -O0.
30 ; Here's what happens:
31 ; 1) We run InstCombine. This puts a dbg.value(ptr %x.addr, DW_OP_deref)
32 ; before the call to @use, and a dbg.value(i32 %x) after the store.
34 ; 3) We run InstCombine again. The alloca %x.addr is erased. We should just get
35 ; dbg.value(i32 %x). There should be no leftover dbg.value(metadata ptr
38 ;;; define void @use(ptr %addr) alwaysinline { ret void }
39 ;;; define void @t2(i32 %x) !dbg !17 {
40 ;;; %x.addr = alloca i32, align 4
41 ;;; store i32 %x, ptr %x.addr, align 4
42 ;;; call void @llvm.dbg.declare(metadata ptr %x.addr, metadata !18, metadata !DIExpression()), !dbg !19
43 ;;; call void @use(ptr %x.addr)
47 declare void @llvm.dbg.value(metadata, metadata, metadata)
48 declare void @llvm.dbg.declare(metadata, metadata, metadata)
50 !llvm.module.flags = !{!0, !1, !2, !3, !4}
54 ; RUN-ONCE: [[t1_arg0]] = !DILocalVariable(name: "a"
55 ; RUN-ONCE: [[t1_fake_ptr]] = !DILocalVariable(name: "fake_ptr"
57 !0 = !{i32 2, !"SDK Version", [2 x i32] [i32 10, i32 14]}
58 !1 = !{i32 2, !"Dwarf Version", i32 4}
59 !2 = !{i32 2, !"Debug Info Version", i32 3}
60 !3 = !{i32 1, !"wchar_size", i32 4}
61 !4 = !{i32 7, !"PIC Level", i32 2}
62 !5 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !7, nameTableKind: GNU)
63 !6 = !DIFile(filename: "-", directory: "/")
66 !9 = distinct !DISubprogram(name: "t1", scope: !10, file: !10, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !7)
67 !10 = !DIFile(filename: "<stdin>", directory: "/")
68 !11 = !DISubroutineType(types: !12)
70 !13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
71 !14 = !DILocalVariable(name: "a", arg: 1, scope: !9, file: !10, line: 1, type: !13)
72 !15 = !DILocation(line: 1, column: 13, scope: !9)
73 !16 = !DILocation(line: 1, column: 17, scope: !9)
74 !17 = distinct !DISubprogram(name: "t2", scope: !10, file: !10, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !7)
75 !18 = !DILocalVariable(name: "x", arg: 1, scope: !17, file: !10, line: 1, type: !13)
76 !19 = !DILocation(line: 1, column: 1, scope: !17)
77 !20 = !DILocalVariable(name: "fake_ptr", scope: !9, file: !10, line: 1, type: !13)