xref: /llvm-project/llvm/test/DebugInfo/X86/sdag-dbgvalue-phi-use-2.ll (revision d53425e2a33a0ff7336c86d3f668b1855c47a6de)
1; RUN: llc -start-after=codegenprepare -stop-before finalize-isel -o - %s \
2; RUN:     -experimental-debug-variable-locations=false \
3; RUN: | FileCheck %s --check-prefixes=CHECK,DBGVALUE
4; RUN: llc -start-after=codegenprepare -stop-before finalize-isel -o - %s \
5; RUN:     -experimental-debug-variable-locations=true \
6; RUN: | FileCheck %s --check-prefixes=CHECK,INSTRREF
7
8; RUN: llc -start-after=codegenprepare -stop-before finalize-isel -o - %s \
9; RUN:     -experimental-debug-variable-locations=false --try-experimental-debuginfo-iterators \
10; RUN: | FileCheck %s --check-prefixes=CHECK,DBGVALUE
11
12; This test case is a modified version of dbg_value_phi_isel1.ll
13; where the llvm.dbg.value nodes in for.body has been moved.
14
15; ModuleID = 'debug.c'
16source_filename = "debug.c"
17target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
18target triple = "x86_64-unknown-linux-gnu"
19
20@end = dso_local local_unnamed_addr global i32 10, align 4, !dbg !0
21
22; Function Attrs: nounwind uwtable
23define dso_local i32 @main() local_unnamed_addr #0 !dbg !11 {
24entry:
25  %arr = alloca [80 x i32], align 16
26  call void @llvm.dbg.value(metadata i32 9, metadata !15, metadata !DIExpression()), !dbg !26
27  call void @llvm.dbg.value(metadata i32 13, metadata !16, metadata !DIExpression()), !dbg !27
28  call void @llvm.dbg.value(metadata i32 0, metadata !17, metadata !DIExpression()), !dbg !28
29  %0 = load i32, ptr @end, align 4, !dbg !29, !tbaa !31
30  %cmp20 = icmp sgt i32 %0, 0, !dbg !35
31  br i1 %cmp20, label %for.body.lr.ph, label %for.cond.cleanup, !dbg !36
32
33for.body.lr.ph:                                   ; preds = %entry
34  %1 = load i32, ptr @end, align 4, !tbaa !31
35  br label %for.body, !dbg !36
36
37for.cond.cleanup:                                 ; preds = %for.body, %entry
38; CHECK-LABEL: bb.{{.*}}.for.cond.cleanup:
39; CHECK:         [[REG1:%[0-9]+]]:gr32 = PHI
40; INSTRREF-SAME:      debug-instr-number 7
41; INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(7, 0)
42; DBGVALUE-NEXT: DBG_VALUE [[REG1]]
43  %x.0.lcssa = phi i32 [ 9, %entry ], [ %add, %for.body ]
44  call void @llvm.dbg.value(metadata i32 %x.0.lcssa, metadata !15, metadata !DIExpression()), !dbg !26
45  call void @llvm.lifetime.start.p0(i64 320, ptr nonnull %arr) #3, !dbg !37
46  call void @llvm.dbg.declare(metadata ptr %arr, metadata !19, metadata !DIExpression()), !dbg !38
47  call void @llvm.dbg.value(metadata i32 0, metadata !24, metadata !DIExpression()), !dbg !39
48  br label %for.body4, !dbg !40
49
50for.body:                                         ; preds = %for.body.lr.ph, %for.body
51; CHECK-LABEL: bb.{{.*}}.for.body:
52; CHECK:         [[REG2:%[0-9]+]]:gr32 = PHI
53; INSTRREF-SAME:    debug-instr-number 4
54; CHECK-NEXT:    [[REG3:%[0-9]+]]:gr32 = PHI
55; INSTRREF-SAME:    debug-instr-number 3
56; CHECK-NEXT:    [[REG4:%[0-9]+]]:gr32 = PHI
57; INSTRREF-SAME:    debug-instr-number 6
58; INSTRREF-NEXT: DBG_INSTR_REF !16, {{.+}}, dbg-instr-ref(3, 0)
59; DBGVALUE-NEXT: DBG_VALUE [[REG3]], $noreg, !16
60; CHECK-NEXT:    DBG_VALUE 555, $noreg, !17
61; CHECK-NEXT:    [[ADDREG:%[0-9]+]]:gr32 = nuw nsw ADD32rr
62; INSTRREF-SAME:    debug-instr-number 5
63; INSTRREF-NEXT: DBG_INSTR_REF !17, {{.+}}, dbg-instr-ref(4, 0)
64; DBGVALUE-NEXT: DBG_VALUE [[REG2]], $noreg, !17
65; CHECK:         [[MULREG:%[0-9]+]]:gr32 = LEA64_32r
66; INSTRREF-SAME:    debug-instr-number 1
67; CHECK-NEXT:    DBG_VALUE 777, $noreg, !17
68;;; XXX: The following DBG_INSTR_REF should have stayed below the INC32r
69; INSTRREF-NEXT: DBG_INSTR_REF !16, {{.+}}, dbg-instr-ref(1, 0)
70; DBGVALUE-NEXT: DBG_VALUE [[MULREG]], $noreg, !16
71; CHECK-NEXT:    [[INCREG:%[0-9]+]]:gr32 = nuw nsw INC32r
72; INSTRREF-SAME:    debug-instr-number 2
73; INSTRREF-NEXT: DBG_INSTR_REF !17, {{.+}}, dbg-instr-ref(2, 0)
74; INSTRREF-NEXT: DBG_INSTR_REF !15, {{.+}}, dbg-instr-ref(5, 0)
75; DBGVALUE-NEXT: DBG_VALUE [[INCREG]], $noreg, !17
76; DBGVALUE-NEXT: DBG_VALUE [[ADDREG]], $noreg, !15
77; CHECK-NEXT:    implicit-def $eflags,
78; INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(6, 0)
79; DBGVALUE-NEXT: DBG_VALUE [[REG4]]
80  %u.023 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
81  %y.022 = phi i32 [ 13, %for.body.lr.ph ], [ %mul, %for.body ]
82  %x.021 = phi i32 [ 9, %for.body.lr.ph ], [ %add, %for.body ]
83  call void @llvm.dbg.value(metadata i32 %y.022, metadata !16, metadata !DIExpression()), !dbg !27
84  ; This dbg.value has been manually added compared to dbg_value_phi_isel1.ll
85  call void @llvm.dbg.value(metadata i32 555, metadata !17, metadata !DIExpression()), !dbg !28
86  %add = add nuw nsw i32 %y.022, %x.021, !dbg !41
87  ; This dbg.value has been manually moved compared to dbg_value_phi_isel1.ll
88  call void @llvm.dbg.value(metadata i32 %u.023, metadata !17, metadata !DIExpression()), !dbg !28
89  %mul = mul nsw i32 %y.022, 3, !dbg !43
90  ; This dbg.value has been manually added compared to dbg_value_phi_isel1.ll
91  call void @llvm.dbg.value(metadata i32 777, metadata !17, metadata !DIExpression()), !dbg !28
92  %inc = add nuw nsw i32 %u.023, 1, !dbg !44
93  call void @llvm.dbg.value(metadata i32 %inc, metadata !17, metadata !DIExpression()), !dbg !28
94  call void @llvm.dbg.value(metadata i32 %mul, metadata !16, metadata !DIExpression()), !dbg !27
95  call void @llvm.dbg.value(metadata i32 %add, metadata !15, metadata !DIExpression()), !dbg !26
96  %cmp = icmp slt i32 %inc, %1, !dbg !35
97  ; This dbg.value has been manually moved compared to dbg_value_phi_isel1.ll
98  call void @llvm.dbg.value(metadata i32 %x.021, metadata !15, metadata !DIExpression()), !dbg !26
99  br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !36, !llvm.loop !45
100
101for.cond.cleanup3:                                ; preds = %for.body4
102  call void @llvm.lifetime.end.p0(i64 320, ptr nonnull %arr) #3, !dbg !47
103  ret i32 %x.0.lcssa, !dbg !48
104
105for.body4:                                        ; preds = %for.body4, %for.cond.cleanup
106  %indvars.iv = phi i64 [ 0, %for.cond.cleanup ], [ %indvars.iv.next, %for.body4 ]
107  call void @llvm.dbg.value(metadata i64 %indvars.iv, metadata !24, metadata !DIExpression()), !dbg !39
108  %arrayidx = getelementptr inbounds [80 x i32], ptr %arr, i64 0, i64 %indvars.iv, !dbg !49
109  %2 = trunc i64 %indvars.iv to i32, !dbg !52
110  %3 = add i32 %2, 3, !dbg !52
111  store volatile i32 %3, ptr %arrayidx, align 4, !dbg !52, !tbaa !31
112  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !53
113  call void @llvm.dbg.value(metadata i32 undef, metadata !24, metadata !DIExpression(DW_OP_plus_uconst, 1, DW_OP_stack_value)), !dbg !39
114  %exitcond = icmp eq i64 %indvars.iv.next, 64, !dbg !54
115  br i1 %exitcond, label %for.cond.cleanup3, label %for.body4, !dbg !40, !llvm.loop !55
116}
117
118; Function Attrs: argmemonly nounwind
119declare void @llvm.lifetime.start.p0(i64, ptr nocapture) #1
120
121; Function Attrs: nounwind readnone speculatable
122declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
123
124; Function Attrs: argmemonly nounwind
125declare void @llvm.lifetime.end.p0(i64, ptr nocapture) #1
126
127; Function Attrs: nounwind readnone speculatable
128declare void @llvm.dbg.value(metadata, metadata, metadata) #2
129
130attributes #0 = { nounwind uwtable }
131attributes #1 = { argmemonly nounwind }
132attributes #2 = { nounwind readnone speculatable }
133attributes #3 = { nounwind }
134
135!llvm.dbg.cu = !{!2}
136!llvm.module.flags = !{!7, !8, !9}
137!llvm.ident = !{!10}
138
139!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
140!1 = distinct !DIGlobalVariable(name: "end", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
141!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 7.0.0 (x)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
142!3 = !DIFile(filename: "debug.c", directory: "")
143!4 = !{}
144!5 = !{!0}
145!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
146!7 = !{i32 2, !"Dwarf Version", i32 4}
147!8 = !{i32 2, !"Debug Info Version", i32 3}
148!9 = !{i32 1, !"wchar_size", i32 4}
149!10 = !{!"clang version 7.0.0 (x)"}
150!11 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 3, type: !12, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: true, unit: !2, retainedNodes: !14)
151!12 = !DISubroutineType(types: !13)
152!13 = !{!6}
153!14 = !{!15, !16, !17, !19, !24}
154!15 = !DILocalVariable(name: "x", scope: !11, file: !3, line: 4, type: !6)
155!16 = !DILocalVariable(name: "y", scope: !11, file: !3, line: 5, type: !6)
156!17 = !DILocalVariable(name: "u", scope: !18, file: !3, line: 6, type: !6)
157!18 = distinct !DILexicalBlock(scope: !11, file: !3, line: 6, column: 3)
158!19 = !DILocalVariable(name: "arr", scope: !11, file: !3, line: 11, type: !20)
159!20 = !DICompositeType(tag: DW_TAG_array_type, baseType: !21, size: 2560, elements: !22)
160!21 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !6)
161!22 = !{!23}
162!23 = !DISubrange(count: 80)
163!24 = !DILocalVariable(name: "q", scope: !25, file: !3, line: 12, type: !6)
164!25 = distinct !DILexicalBlock(scope: !11, file: !3, line: 12, column: 3)
165!26 = !DILocation(line: 4, column: 7, scope: !11)
166!27 = !DILocation(line: 5, column: 7, scope: !11)
167!28 = !DILocation(line: 6, column: 12, scope: !18)
168!29 = !DILocation(line: 6, column: 23, scope: !30)
169!30 = distinct !DILexicalBlock(scope: !18, file: !3, line: 6, column: 3)
170!31 = !{!32, !32, i64 0}
171!32 = !{!"int", !33, i64 0}
172!33 = !{!"omnipotent char", !34, i64 0}
173!34 = !{!"Simple C/C++ TBAA"}
174!35 = !DILocation(line: 6, column: 21, scope: !30)
175!36 = !DILocation(line: 6, column: 3, scope: !18)
176!37 = !DILocation(line: 11, column: 3, scope: !11)
177!38 = !DILocation(line: 11, column: 16, scope: !11)
178!39 = !DILocation(line: 12, column: 12, scope: !25)
179!40 = !DILocation(line: 12, column: 3, scope: !25)
180!41 = !DILocation(line: 7, column: 7, scope: !42)
181!42 = distinct !DILexicalBlock(scope: !30, file: !3, line: 6, column: 33)
182!43 = !DILocation(line: 8, column: 11, scope: !42)
183!44 = !DILocation(line: 6, column: 28, scope: !30)
184!45 = distinct !{!45, !36, !46}
185!46 = !DILocation(line: 9, column: 3, scope: !18)
186!47 = !DILocation(line: 17, column: 1, scope: !11)
187!48 = !DILocation(line: 16, column: 3, scope: !11)
188!49 = !DILocation(line: 13, column: 5, scope: !50)
189!50 = distinct !DILexicalBlock(scope: !51, file: !3, line: 12, column: 32)
190!51 = distinct !DILexicalBlock(scope: !25, file: !3, line: 12, column: 3)
191!52 = !DILocation(line: 13, column: 12, scope: !50)
192!53 = !DILocation(line: 12, column: 27, scope: !51)
193!54 = !DILocation(line: 12, column: 21, scope: !51)
194!55 = distinct !{!55, !40, !56}
195!56 = !DILocation(line: 14, column: 3, scope: !25)
196