xref: /llvm-project/llvm/test/DebugInfo/Generic/mldst-motion-dbg.ll (revision 5a288fa32e0c91b211e39f3e370255916902f898)
1; RUN: opt -passes=mldst-motion -S %s -o - | FileCheck %s
2
3;; $ cat test.cpp -n
4;;      1	void fun(int *a, int cond) {
5;;      2	  if (cond)
6;;      3	    a[1] = 1;
7;;      4	  else
8;;      5	    a[1] = 2;
9;;      6	}
10;;
11;; mldst-motion will merge and sink the stores in if.then and if.else into
12;; if.end. The resultant PHI, gep and store should be attributed line zero
13;; with the innermost common scope rather than picking a debug location from
14;; one of the original stores.
15
16; CHECK: if.end:
17; CHECK-NEXT: %.sink = phi i32 [ 2, %if.else ], [ 1, %if.then ], !dbg ![[dbg:[0-9]+]]
18; CHECK-NEXT: %0 = getelementptr inbounds i32, ptr %a, i64 1, !dbg ![[dbg:[0-9]+]]
19; CHECK-NEXT: store i32 %.sink, ptr %0, align 4, !dbg ![[dbg:[0-9]+]]
20
21; CHECK-DAG: ![[dbg]] = !DILocation(line: 0, scope: ![[scp:[0-9]+]]
22; CHECK-DAG: ![[scp]] = distinct !DILexicalBlock(scope: ![[fun:[0-9]+]]
23; CHECK-DAG: ![[fun]] = distinct !DISubprogram(name: "fun",
24
25define void @_Z3funPii(ptr nocapture noundef writeonly %a, i32 noundef %cond) !dbg !7 {
26entry:
27  call void @llvm.dbg.value(metadata ptr %a, metadata !13, metadata !DIExpression()), !dbg !15
28  call void @llvm.dbg.value(metadata i32 %cond, metadata !14, metadata !DIExpression()), !dbg !15
29  %tobool.not = icmp eq i32 %cond, 0, !dbg !16
30  br i1 %tobool.not, label %if.else, label %if.then, !dbg !18
31
32if.then:                                          ; preds = %entry
33  %arrayidx = getelementptr inbounds i32, ptr %a, i64 1, !dbg !19
34  store i32 1, ptr %arrayidx, align 4, !dbg !20
35  br label %if.end, !dbg !19
36
37if.else:                                          ; preds = %entry
38  %arrayidx1 = getelementptr inbounds i32, ptr %a, i64 1, !dbg !25
39  store i32 2, ptr %arrayidx1, align 4, !dbg !26
40  br label %if.end
41
42if.end:                                           ; preds = %if.else, %if.then
43  ret void, !dbg !27
44}
45
46declare void @llvm.dbg.value(metadata, metadata, metadata)
47
48!llvm.dbg.cu = !{!0}
49!llvm.module.flags = !{!2, !3, !4, !5}
50!llvm.ident = !{!6}
51
52!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 14.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
53!1 = !DIFile(filename: "test.cpp", directory: "/")
54!2 = !{i32 7, !"Dwarf Version", i32 5}
55!3 = !{i32 2, !"Debug Info Version", i32 3}
56!4 = !{i32 1, !"wchar_size", i32 4}
57!5 = !{i32 7, !"uwtable", i32 1}
58!6 = !{!"clang version 14.0.0"}
59!7 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funPii", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12)
60!8 = !DISubroutineType(types: !9)
61!9 = !{null, !10, !11}
62!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
63!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
64!12 = !{!13, !14}
65!13 = !DILocalVariable(name: "a", arg: 1, scope: !7, file: !1, line: 1, type: !10)
66!14 = !DILocalVariable(name: "cond", arg: 2, scope: !7, file: !1, line: 1, type: !11)
67!15 = !DILocation(line: 0, scope: !7)
68!16 = !DILocation(line: 2, column: 7, scope: !17)
69!17 = distinct !DILexicalBlock(scope: !7, file: !1, line: 2, column: 7)
70!18 = !DILocation(line: 2, column: 7, scope: !7)
71!19 = !DILocation(line: 3, column: 5, scope: !17)
72!20 = !DILocation(line: 3, column: 10, scope: !17)
73!25 = !DILocation(line: 5, column: 5, scope: !17)
74!26 = !DILocation(line: 5, column: 10, scope: !17)
75!27 = !DILocation(line: 6, column: 1, scope: !7)
76