xref: /llvm-project/llvm/test/DebugInfo/Generic/assignment-tracking/simplifycfg/speculated-store.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt -passes=simplifycfg %s -S  \
2; RUN: | FileCheck %s
3; RUN: opt --try-experimental-debuginfo-iterators -passes=simplifycfg %s -S  \
4; RUN: | FileCheck %s
5
6;; Ensure that we correctly update the value component of dbg.assign intrinsics
7;; after merging a conditional block with a store its the predecessor. The
8;; value stored is still conditional, but the store itself is now
9;; unconditionally run, so we must be sure that any linked dbg.assign intrinsics
10;; are tracking the new stored value (the result of the select). If we don't,
11;; and the store were to be removed by another pass (e.g. DSE), then we'd
12;; eventually end up emitting a location describing the conditional value,
13;; unconditionally.
14
15;; Created from the following source and command, with dbg.assign and DIAssignID
16;; metadata added and some other metadata removed by hand:
17;; $ cat test.c
18;; int a;
19;; void b() {
20;;   int c = 0;
21;;   if (a)
22;;      c = 1;
23;; }
24;; $ clang -O2 -g -emit-llvm -S test.c -Xclang -fexperimental-assignment-tracking
25
26; CHECK: %[[SELECT:.*]] = select i1 %tobool
27; CHECK-NEXT: store i32 %[[SELECT]], ptr %c{{.*}}, !DIAssignID ![[ID:[0-9]+]]
28; CHECK-NEXT: #dbg_assign(i32 %[[SELECT]], ![[VAR_C:[0-9]+]], !DIExpression(), ![[ID]], ptr %c, !DIExpression(),
29; CHECK: ![[VAR_C]] = !DILocalVariable(name: "c",
30
31@a = dso_local global i32 0, align 4, !dbg !0
32
33define dso_local void @b() !dbg !11 {
34entry:
35  %c = alloca i32, align 4
36  %0 = bitcast ptr %c to ptr, !dbg !16
37  call void @llvm.lifetime.start.p0(i64 4, ptr %0), !dbg !16
38  store i32 0, ptr %c, align 4, !dbg !17, !DIAssignID !36
39  call void @llvm.dbg.assign(metadata i32 0, metadata !15, metadata !DIExpression(), metadata !36, metadata ptr %c, metadata !DIExpression()), !dbg !17
40  %1 = load i32, ptr @a, align 4, !dbg !22
41  %tobool = icmp ne i32 %1, 0, !dbg !22
42  br i1 %tobool, label %if.then, label %if.end, !dbg !24
43
44if.then:                                          ; preds = %entry
45  store i32 1, ptr %c, align 4, !dbg !25, !DIAssignID !37
46  call void @llvm.dbg.assign(metadata i32 1, metadata !15, metadata !DIExpression(), metadata !37, metadata ptr %c, metadata !DIExpression()), !dbg !17
47  br label %if.end, !dbg !26
48
49if.end:                                           ; preds = %if.then, %entry
50  %2 = bitcast ptr %c to ptr, !dbg !27
51  call void @llvm.lifetime.end.p0(i64 4, ptr %2), !dbg !27
52  ret void, !dbg !27
53}
54
55declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)
56declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
57declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)
58
59!llvm.dbg.cu = !{!2}
60!llvm.module.flags = !{!7, !8, !9, !1000}
61!llvm.ident = !{!10}
62
63!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
64!1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
65!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 14.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
66!3 = !DIFile(filename: "test.c", directory: "/")
67!4 = !{}
68!5 = !{!0}
69!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
70!7 = !{i32 7, !"Dwarf Version", i32 4}
71!8 = !{i32 2, !"Debug Info Version", i32 3}
72!9 = !{i32 1, !"wchar_size", i32 4}
73!10 = !{!"clang version 12.0.0"}
74!11 = distinct !DISubprogram(name: "b", scope: !3, file: !3, line: 2, type: !12, scopeLine: 2, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !14)
75!12 = !DISubroutineType(types: !13)
76!13 = !{null}
77!14 = !{!15}
78!15 = !DILocalVariable(name: "c", scope: !11, file: !3, line: 3, type: !6)
79!16 = !DILocation(line: 3, column: 3, scope: !11)
80!17 = !DILocation(line: 3, column: 7, scope: !11)
81!22 = !DILocation(line: 4, column: 7, scope: !23)
82!23 = distinct !DILexicalBlock(scope: !11, file: !3, line: 4, column: 7)
83!24 = !DILocation(line: 4, column: 7, scope: !11)
84!25 = !DILocation(line: 5, column: 7, scope: !23)
85!26 = !DILocation(line: 5, column: 5, scope: !23)
86!27 = !DILocation(line: 6, column: 1, scope: !11)
87!36 = distinct !DIAssignID()
88!37 = distinct !DIAssignID()
89!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
90