xref: /llvm-project/llvm/test/Transforms/JumpThreading/guard-split-debuginfo.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
2; RUN: opt -S -passes=jump-threading %s -o - -S | FileCheck %s
3; RUN: opt -S -passes=jump-threading %s -o - -S --try-experimental-debuginfo-iterators | FileCheck %s
4
5; Test that debug-info records in the Merge block, to be copied by
6; DuplicateInstructionsInSplitBetween, get duplicated into the relevant
7; parent blocks. And that ino jump-threading, the old dbg.value gets
8; deleted.
9
10; Test that JumpThreading's threadGuard() propagates the debug location
11; to the `phi` from the instruction it replaces (`%retval`)
12
13declare void @llvm.experimental.guard(i1, ...)
14
15declare i32 @f1()
16declare i32 @f2()
17
18declare void @llvm.dbg.value(metadata, metadata, metadata)
19
20define i32 @branch_implies_guard(i32 %a) !dbg !7 {
21; CHECK-LABEL: @branch_implies_guard(
22; CHECK-NEXT:    [[COND:%.*]] = icmp slt i32 [[A:%.*]], 10
23; CHECK-NEXT:    br i1 [[COND]], label [[T1_SPLIT:%.*]], label [[F1_SPLIT:%.*]], !dbg [[DBG12:![0-9]+]]
24; CHECK:       T1.split:
25; CHECK-NEXT:    [[V1:%.*]] = call i32 @f1(), !dbg [[DBG12]]
26; CHECK-NEXT:      #dbg_value(i32 0, [[META13:![0-9]+]], !DIExpression(), [[META14:![0-9]+]])
27; CHECK-NEXT:    [[RETVAL3:%.*]] = add i32 [[V1]], 10, !dbg [[DBG12]]
28; CHECK-NEXT:    [[CONDGUARD4:%.*]] = icmp slt i32 [[A]], 20, !dbg [[DBG12]]
29; CHECK-NEXT:    br label [[MERGE:%.*]]
30; CHECK:       F1.split:
31; CHECK-NEXT:    [[V2:%.*]] = call i32 @f2(), !dbg [[DBG12]]
32; CHECK-NEXT:      #dbg_value(i32 0, [[META13]], !DIExpression(), [[META14]])
33; CHECK-NEXT:    [[RETVAL1:%.*]] = add i32 [[V2]], 10, !dbg [[DBG12]]
34; CHECK-NEXT:    [[CONDGUARD2:%.*]] = icmp slt i32 [[A]], 20, !dbg [[DBG12]]
35; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 [[CONDGUARD2]]) [ "deopt"() ]
36; CHECK-NEXT:    br label [[MERGE]]
37; CHECK:       Merge:
38; CHECK-NEXT:    [[RETPHI:%.*]] = phi i32 [ [[V1]], [[T1_SPLIT]] ], [ [[V2]], [[F1_SPLIT]] ]
39; CHECK-NEXT:    [[TMP1:%.*]] = phi i32 [ [[RETVAL3]], [[T1_SPLIT]] ], [ [[RETVAL1]], [[F1_SPLIT]] ], !dbg [[DBG12]]
40; CHECK-NEXT:    ret i32 [[TMP1]], !dbg [[DBG12]]
41;
42  %cond = icmp slt i32 %a, 10
43  br i1 %cond, label %T1, label %F1, !dbg !26
44
45T1:
46  %v1 = call i32 @f1(), !dbg !26
47  br label %Merge
48
49F1:
50  %v2 = call i32 @f2(), !dbg !26
51  br label %Merge
52
53Merge:
54  %retPhi = phi i32 [ %v1, %T1 ], [ %v2, %F1 ]
55  call void @llvm.dbg.value(metadata i32 0, metadata !12, metadata !DIExpression()), !dbg !13
56  %retVal = add i32 %retPhi, 10, !dbg !26
57  %condGuard = icmp slt i32 %a, 20, !dbg !26
58  call void(i1, ...) @llvm.experimental.guard(i1 %condGuard) [ "deopt"() ]
59  ret i32 %retVal, !dbg !26
60}
61
62!llvm.dbg.cu = !{!0}
63!llvm.module.flags = !{!3, !4, !5}
64!llvm.ident = !{!6}
65
66!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
67!1 = !DIFile(filename: "test.c", directory: "/tmp/out.c")
68!2 = !{}
69!3 = !{i32 7, !"Dwarf Version", i32 4}
70!4 = !{i32 2, !"Debug Info Version", i32 3}
71!5 = !{i32 1, !"wchar_size", i32 4}
72!6 = !{!""}
73!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !8, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
74!8 = !DISubroutineType(types: !9)
75!9 = !{!10, !11, !11}
76!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
77!11 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)
78!12 = !DILocalVariable(name: "bar", arg: 1, scope: !7, file: !1, line: 3, type: !11)
79!13 = !DILocation(line: 0, scope: !7)
80!14 = !DILocalVariable(name: "baz", arg: 2, scope: !7, file: !1, line: 3, type: !11)
81!19 = distinct !DILexicalBlock(scope: !7, file: !1, line: 8, column: 7)
82!26 = !DILocation(line: 13, column: 3, scope: !7)
83
84;.
85; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C99, file: [[META1:![0-9]+]], isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: [[META2:![0-9]+]], splitDebugInlining: false, nameTableKind: None)
86; CHECK: [[META1]] = !DIFile(filename: "test.c", directory: {{.*}})
87; CHECK: [[META2]] = !{}
88; CHECK: [[META3:![0-9]+]] = !{i32 7, !"Dwarf Version", i32 4}
89; CHECK: [[META4:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3}
90; CHECK: [[META5:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
91; CHECK: [[META6:![0-9]+]] = !{!""}
92; CHECK: [[META7:![0-9]+]] = distinct !DISubprogram(name: "foo", scope: [[META1]], file: [[META1]], line: 3, type: [[META8:![0-9]+]], scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]], retainedNodes: [[META2]])
93; CHECK: [[META8]] = !DISubroutineType(types: [[META9:![0-9]+]])
94; CHECK: [[META9]] = !{[[META10:![0-9]+]], [[META11:![0-9]+]], [[META11]]}
95; CHECK: [[META10]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
96; CHECK: [[META11]] = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)
97; CHECK: [[DBG12]] = !DILocation(line: 13, column: 3, scope: [[META7]])
98; CHECK: [[META13]] = !DILocalVariable(name: "bar", arg: 1, scope: [[META7]], file: [[META1]], line: 3, type: [[META11]])
99; CHECK: [[META14]] = !DILocation(line: 0, scope: [[META7]])
100;.
101