xref: /llvm-project/llvm/test/Transforms/SimplifyCFG/X86/pr39187-g.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt < %s -S -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true | FileCheck %s
2; RUN: opt --try-experimental-debuginfo-iterators < %s -S -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true | FileCheck %s
3
4; SimplifyCFG can hoist any common code in the 'then' and 'else' blocks to
5; the 'if' basic block.
6;
7; For the special case, when hoisting the terminator instruction, its debug
8; location keep references to its basic block, causing the debug information
9; to become ambiguous. It causes the debugger to display unreached lines.
10
11; Check that hoisted instructions get unknown-location line numbers -- there
12; is no correct line number for code that has been common'd in this way.
13
14; IR generated with:
15; clang -S -g -gno-column-info -O2 -emit-llvm pr39187.cpp -o pr39187-g.ll -mllvm -opt-bisect-limit=10
16
17; // pr39187.cpp
18; int main() {
19;   volatile int foo = 0;
20;
21;   int beards = 0;
22;   bool cond = foo == 4;
23;   int bar = 0;
24;   if (cond)
25;     beards = 8;
26;   else
27;     beards = 4;
28;
29;   volatile bool face = cond;
30;
31;   return face ? beards : 0;
32; }
33
34; CHECK-LABEL: entry
35; CHECK:  %foo = alloca i32, align 4
36; CHECK:  %face = alloca i8, align 1
37; CHECK:  store volatile i32 0, ptr %foo, align 4
38; CHECK:  %foo.0. = load volatile i32, ptr %foo, align 4, !dbg !16
39; CHECK:  %cmp = icmp eq i32 %foo.0., 4, !dbg !16
40; CHECK:  %frombool = zext i1 %cmp to i8, !dbg !16
41; CHECK:  #dbg_value(i8 %frombool, !13, !DIExpression(), !16
42; CHECK:  #dbg_value(i32 0, !15, !DIExpression(), !17
43; CHECK:  %. = select i1 %cmp, i32 8, i32 4, !dbg ![[MERGEDLOC:[0-9]+]]
44; CHECK:  ![[MERGEDLOC]] = !DILocation(line: 0, scope: !7)
45
46; ModuleID = 'pr39187.cpp'
47source_filename = "pr39187.cpp"
48target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
49target triple = "x86_64-pc-linux-gnu"
50
51; Function Attrs: norecurse nounwind uwtable
52define dso_local i32 @main() local_unnamed_addr #0 !dbg !7 {
53entry:
54  %foo = alloca i32, align 4
55  %face = alloca i8, align 1
56  store volatile i32 0, ptr %foo, align 4
57  %foo.0. = load volatile i32, ptr %foo, align 4, !dbg !26
58  %cmp = icmp eq i32 %foo.0., 4, !dbg !26
59  %frombool = zext i1 %cmp to i8, !dbg !26
60  call void @llvm.dbg.value(metadata i8 %frombool, metadata !15, metadata !DIExpression()), !dbg !26
61  call void @llvm.dbg.value(metadata i32 0, metadata !17, metadata !DIExpression()), !dbg !27
62  br i1 %cmp, label %if.then, label %if.else
63
64if.then:                                          ; preds = %entry
65  call void @llvm.dbg.value(metadata i32 8, metadata !14, metadata !DIExpression()), !dbg !25
66  br label %if.end, !dbg !25
67
68if.else:                                          ; preds = %entry
69  call void @llvm.dbg.value(metadata i32 4, metadata !14, metadata !DIExpression()), !dbg !27
70  br label %if.end, !dbg !27
71
72if.end:                                           ; preds = %if.else, %if.then
73  %beards.0 = phi i32 [ 8, %if.then ], [ 4, %if.else ]
74  store volatile i8 %frombool, ptr %face, align 1
75  %face.0. = load volatile i8, ptr %face, align 1
76  %0 = and i8 %face.0., 1
77  %tobool3 = icmp eq i8 %0, 0
78  %cond4 = select i1 %tobool3, i32 0, i32 %beards.0
79  ret i32 %cond4
80}
81
82; Function Attrs: nounwind readnone speculatable
83declare void @llvm.dbg.value(metadata, metadata, metadata) #2
84
85!llvm.dbg.cu = !{!0}
86!llvm.module.flags = !{!3, !4, !5}
87!llvm.ident = !{!6}
88
89!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 8.0.0 (trunk 346301)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
90!1 = !DIFile(filename: "pr39187.cpp", directory: ".")
91!2 = !{}
92!3 = !{i32 2, !"Dwarf Version", i32 4}
93!4 = !{i32 2, !"Debug Info Version", i32 3}
94!5 = !{i32 1, !"wchar_size", i32 4}
95!6 = !{!"clang version 8.0.0 (trunk 346301)"}
96!7 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !11)
97!8 = !DISubroutineType(types: !9)
98!9 = !{!10}
99!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
100!11 = !{!14, !15, !17}
101!14 = !DILocalVariable(name: "beards", scope: !7, file: !1, line: 4, type: !10)
102!15 = !DILocalVariable(name: "cond", scope: !7, file: !1, line: 5, type: !16)
103!16 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
104!17 = !DILocalVariable(name: "bar", scope: !7, file: !1, line: 6, type: !10)
105!25 = !DILocation(line: 4, scope: !7)
106!26 = !DILocation(line: 5, scope: !7)
107!27 = !DILocation(line: 6, scope: !7)
108