• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -S -simplifycfg | FileCheck %s
2
3; Note: This patch is a complement to pr38763.
4;
5; When SimplifyCFG changes the PHI node into a select instruction, the debug
6; information becomes ambiguous. It causes the debugger to display unreached
7; lines and invalid variable values.
8;
9; When in the debugger, on the line "if (read1 > 3)", and we step from the
10; 'if' condition, onto the addition, then back to the 'if' again, which is
11; misleading because that addition doesn't really "happen" (it's speculated).
12
13; IR generated with:
14; clang -S -g -gno-column-info -O2 -emit-llvm pr38762.cpp -o pr38762.ll -mllvm -opt-bisect-limit=10
15
16; // pr38762.cpp
17; int main() {
18;   volatile int foo = 0;
19;   int read1 = foo;
20;   int brains = foo;
21;
22;   if (read1 > 3) {
23;     brains *= 2;
24;     brains += 1;
25;   }
26;
27;   return brains;
28; }
29
30; Change the debug locations associated with the PHI nodes being promoted, to
31; the debug locations from the insertion point in the dominant block.
32
33; CHECK-LABEL: entry
34; CHECK:  %cmp = icmp sgt i32 %foo.0., 3, !dbg !14
35; CHECK:  %mul = shl nsw i32 %foo.0.5, 1, !dbg !16
36; CHECK-NOT:  call void @llvm.dbg.value(metadata i32 %mul, metadata !15, metadata !DIExpression()), !dbg !25
37; CHECK:  %add = or i32 %mul, 1, !dbg !16
38; CHECK-NOT:  call void @llvm.dbg.value(metadata i32 %add, metadata !15, metadata !DIExpression()), !dbg !25
39; CHECK:  %brains.0 = select i1 %cmp, i32 %add, i32 %foo.0.5, !dbg !16
40
41; ModuleID = 'pr38762.cpp'
42source_filename = "pr38762.cpp"
43target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
44target triple = "x86_64-pc-linux-gnu"
45
46; Function Attrs: norecurse nounwind uwtable
47define dso_local i32 @main() local_unnamed_addr #0 !dbg !7 {
48entry:
49  %foo = alloca i32, align 4
50  %foo.0..sroa_cast = bitcast i32* %foo to i8*
51  store volatile i32 0, i32* %foo, align 4
52  %foo.0. = load volatile i32, i32* %foo, align 4
53  %foo.0.5 = load volatile i32, i32* %foo, align 4
54  call void @llvm.dbg.value(metadata i32 %foo.0.5, metadata !15, metadata !DIExpression()), !dbg !25
55  %cmp = icmp sgt i32 %foo.0., 3, !dbg !26
56  br i1 %cmp, label %if.then, label %if.end, !dbg !28
57
58if.then:                                          ; preds = %entry
59  %mul = shl nsw i32 %foo.0.5, 1, !dbg !29
60  call void @llvm.dbg.value(metadata i32 %mul, metadata !15, metadata !DIExpression()), !dbg !25
61  %add = or i32 %mul, 1, !dbg !31
62  call void @llvm.dbg.value(metadata i32 %add, metadata !15, metadata !DIExpression()), !dbg !25
63  br label %if.end, !dbg !32
64
65if.end:                                           ; preds = %if.then, %entry
66  %brains.0 = phi i32 [ %add, %if.then ], [ %foo.0.5, %entry ], !dbg !33
67  call void @llvm.dbg.value(metadata i32 %brains.0, metadata !15, metadata !DIExpression()), !dbg !25
68  ret i32 %brains.0, !dbg !35
69}
70
71declare void @llvm.dbg.value(metadata, metadata, metadata) #2
72
73!llvm.dbg.cu = !{!0}
74!llvm.module.flags = !{!3, !4, !5}
75!llvm.ident = !{!6}
76
77!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 8.0.0 (trunk 343753)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
78!1 = !DIFile(filename: "pr38762.cpp", directory: ".")
79!2 = !{}
80!3 = !{i32 2, !"Dwarf Version", i32 4}
81!4 = !{i32 2, !"Debug Info Version", i32 3}
82!5 = !{i32 1, !"wchar_size", i32 4}
83!6 = !{!"clang version 8.0.0 (trunk 343753)"}
84!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)
85!8 = !DISubroutineType(types: !9)
86!9 = !{!10}
87!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
88!11 = !{!15}
89!13 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !10)
90!15 = !DILocalVariable(name: "brains", scope: !7, file: !1, line: 4, type: !10)
91!25 = !DILocation(line: 4, scope: !7)
92!26 = !DILocation(line: 6, scope: !27)
93!27 = distinct !DILexicalBlock(scope: !7, file: !1, line: 6)
94!28 = !DILocation(line: 6, scope: !7)
95!29 = !DILocation(line: 7, scope: !30)
96!30 = distinct !DILexicalBlock(scope: !27, file: !1, line: 6)
97!31 = !DILocation(line: 8, scope: !30)
98!32 = !DILocation(line: 9, scope: !30)
99!33 = !DILocation(line: 0, scope: !7)
100!34 = !DILocation(line: 12, scope: !7)
101!35 = !DILocation(line: 11, scope: !7)
102