1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -S -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 | FileCheck %s
3 ; RUN: opt < %s -S -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 --try-experimental-debuginfo-iterators | FileCheck %s
5 ; This test case was generated from speculate-dbgvalue.c:
7 ; int test1(int getdirt, int dirt) {
15 ; clang speculate-dbgvalue.c -S -emit-llvm -g -O3 -mllvm -disable-llvm-optzns -o - | opt -passes=mem2reg -S
18 ; Function Attrs: nounwind uwtable
19 define i32 @test1(i32 %getdirt, i32 %dirt) #0 !dbg !7 {
20 ; CHECK-LABEL: @test1(
22 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 [[GETDIRT:%.*]], metadata !12, metadata !DIExpression()), !dbg !15
23 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 [[DIRT:%.*]], metadata !13, metadata !DIExpression()), !dbg !16
24 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 100, metadata !14, metadata !DIExpression()), !dbg !17
25 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[GETDIRT]], 0, !dbg !18
26 ; *** We used to get an incorrect "call void @llvm.dbg.value(metadata i32 [[DIRT]], metadata !14, metadata !DIExpression()), !dbg !17" here, before the select. ***
27 ; CHECK-NOT: call void @llvm.dbg.value(metadata i32 [[DIRT]], metadata !14
28 ; CHECK-NEXT: [[RESULT:%.*]] = select i1 [[CMP]], i32 [[DIRT]], i32 100, !dbg !20
29 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 [[RESULT]], metadata !14, metadata !DIExpression()), !dbg !17
30 ; CHECK-NEXT: ret i32 [[RESULT]], !dbg !21
31 ; CHECK: !12 = !DILocalVariable(name: "getdirt"
32 ; CHECK: !13 = !DILocalVariable(name: "dirt"
33 ; CHECK: !14 = !DILocalVariable(name: "result"
36 call void @llvm.dbg.value(metadata i32 %getdirt, metadata !12, metadata !DIExpression()), !dbg !15
37 call void @llvm.dbg.value(metadata i32 %dirt, metadata !13, metadata !DIExpression()), !dbg !16
38 call void @llvm.dbg.value(metadata i32 100, metadata !14, metadata !DIExpression()), !dbg !17
39 %cmp = icmp ne i32 %getdirt, 0, !dbg !18
40 br i1 %cmp, label %if.then, label %if.end, !dbg !20
42 if.then: ; preds = %entry
43 call void @llvm.dbg.value(metadata i32 %dirt, metadata !14, metadata !DIExpression()), !dbg !17
44 br label %if.end, !dbg !21
46 if.end: ; preds = %if.then, %entry
47 %result.0 = phi i32 [ %dirt, %if.then ], [ 100, %entry ]
48 call void @llvm.dbg.value(metadata i32 %result.0, metadata !14, metadata !DIExpression()), !dbg !17
49 ret i32 %result.0, !dbg !22
52 ; Function Attrs: nounwind readnone speculatable
53 declare void @llvm.dbg.value(metadata, metadata, metadata) #1
55 attributes #0 = { nounwind uwtable }
56 attributes #1 = { nounwind readnone speculatable }
59 !llvm.module.flags = !{!3, !4, !5}
62 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
63 !1 = !DIFile(filename: "speculate-dbgvalue.c", directory: "/foo")
65 !3 = !{i32 2, !"Dwarf Version", i32 4}
66 !4 = !{i32 2, !"Debug Info Version", i32 3}
67 !5 = !{i32 1, !"wchar_size", i32 4}
68 !6 = !{!"clang version 6.0.0"}
69 !7 = distinct !DISubprogram(name: "test1", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !11)
70 !8 = !DISubroutineType(types: !9)
72 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
73 !11 = !{!12, !13, !14}
74 !12 = !DILocalVariable(name: "getdirt", arg: 1, scope: !7, file: !1, line: 1, type: !10)
75 !13 = !DILocalVariable(name: "dirt", arg: 2, scope: !7, file: !1, line: 1, type: !10)
76 !14 = !DILocalVariable(name: "result", scope: !7, file: !1, line: 2, type: !10)
77 !15 = !DILocation(line: 1, column: 15, scope: !7)
78 !16 = !DILocation(line: 1, column: 28, scope: !7)
79 !17 = !DILocation(line: 2, column: 7, scope: !7)
80 !18 = !DILocation(line: 3, column: 15, scope: !19)
81 !19 = distinct !DILexicalBlock(scope: !7, file: !1, line: 3, column: 7)
82 !20 = !DILocation(line: 3, column: 7, scope: !7)
83 !21 = !DILocation(line: 4, column: 5, scope: !19)
84 !22 = !DILocation(line: 5, column: 3, scope: !7)