xref: /llvm-project/llvm/test/DebugInfo/X86/sdag-dbgvalue-phi-use-3.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 was generated from the following phi-split.c program,
13; using: clang phi-split.c -g -O1 -S -o - --target=i386 -emit-llvm
14; --------------------------------------
15; long long end = 10;
16;
17; int main() {
18;   long long x = 9;
19;   long long y = 13;
20;   for (long long u = 0; u < end; ++u) {
21;     x += y;
22;     y = y * 3;
23;   }
24;
25;   volatile long long arr[80];
26;   for (long long q = 0; q < 64; ++q) {
27;     arr[q] = q + 3;
28;   }
29;
30;   return x;
31; }
32; --------------------------------------
33;
34
35; ModuleID = 'phi-split.c'
36source_filename = "phi-split.c"
37target datalayout = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
38target triple = "i386"
39
40@end = dso_local local_unnamed_addr global i64 10, align 8, !dbg !0
41
42; Function Attrs: nounwind
43define dso_local i32 @main() local_unnamed_addr #0 !dbg !12 {
44; CHECK-LABEL: name:            main
45entry:
46  %arr = alloca [80 x i64], align 8
47  call void @llvm.dbg.value(metadata i64 9, metadata !17, metadata !DIExpression()), !dbg !28
48  call void @llvm.dbg.value(metadata i64 13, metadata !18, metadata !DIExpression()), !dbg !29
49  call void @llvm.dbg.value(metadata i64 0, metadata !19, metadata !DIExpression()), !dbg !30
50  %0 = load i64, ptr @end, align 8, !dbg !31
51  %cmp20 = icmp sgt i64 %0, 0, !dbg !37
52  br i1 %cmp20, label %for.body.lr.ph, label %for.cond.cleanup, !dbg !38
53
54for.body.lr.ph:                                   ; preds = %entry
55  %1 = load i64, ptr @end, align 8
56  br label %for.body, !dbg !38
57
58for.cond.cleanup.loopexit:                        ; preds = %for.body
59  %extract.t = trunc i64 %add to i32, !dbg !38
60  br label %for.cond.cleanup, !dbg !39
61
62for.cond.cleanup:                                 ; preds = %for.cond.cleanup.loopexit, %entry
63  %x.0.lcssa.off0 = phi i32 [ 9, %entry ], [ %extract.t, %for.cond.cleanup.loopexit ]
64  call void @llvm.dbg.value(metadata i64 undef, metadata !17, metadata !DIExpression()), !dbg !28
65  call void @llvm.dbg.value(metadata i64 0, metadata !26, metadata !DIExpression()), !dbg !41
66  br label %for.body4, !dbg !42
67
68for.body:                                         ; preds = %for.body.lr.ph, %for.body
69; CHECK-LABEL: bb.{{.*}}.for.body:
70; CHECK:         [[REG2:%[0-9]+]]:gr32 = PHI
71; INSTRREF-SAME:    debug-instr-number 5
72; CHECK-NEXT:    [[REG3:%[0-9]+]]:gr32 = PHI
73; INSTRREF-SAME:    debug-instr-number 6
74; CHECK-NEXT:    [[REG4:%[0-9]+]]:gr32 = PHI
75; INSTRREF-SAME:    debug-instr-number 7
76; CHECK-NEXT:    [[REG5:%[0-9]+]]:gr32_nosp = PHI
77; INSTRREF-SAME:    debug-instr-number 8
78; CHECK-NEXT:    [[REG6:%[0-9]+]]:gr32 = PHI
79; INSTRREF-SAME:    debug-instr-number 9
80; CHECK-NEXT:    [[REG7:%[0-9]+]]:gr32 = PHI
81; INSTRREF-SAME:    debug-instr-number 10
82; INSTRREF-NEXT: DBG_INSTR_REF !19, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_fragment, 0, 32), dbg-instr-ref(5, 0)
83; INSTRREF-NEXT: DBG_INSTR_REF !19, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_fragment, 32, 32), dbg-instr-ref(6, 0)
84; INSTRREF-NEXT: DBG_INSTR_REF !18, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_fragment, 0, 32), dbg-instr-ref(7, 0)
85; INSTRREF-NEXT: DBG_INSTR_REF !18, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_fragment, 32, 32), dbg-instr-ref(8, 0)
86; INSTRREF-NEXT: DBG_INSTR_REF !17, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_fragment, 0, 32), dbg-instr-ref(9, 0)
87; INSTRREF-NEXT: DBG_INSTR_REF !17, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_fragment, 32, 32), dbg-instr-ref(10, 0)
88; DBGVALUE-NEXT: DBG_VALUE [[REG2]], $noreg, !19, !DIExpression(DW_OP_LLVM_fragment, 0, 32)
89; DBGVALUE-NEXT: DBG_VALUE [[REG3]], $noreg, !19, !DIExpression(DW_OP_LLVM_fragment, 32, 32)
90; DBGVALUE-NEXT: DBG_VALUE [[REG4]], $noreg, !18, !DIExpression(DW_OP_LLVM_fragment, 0, 32)
91; DBGVALUE-NEXT: DBG_VALUE [[REG5]], $noreg, !18, !DIExpression(DW_OP_LLVM_fragment, 32, 32)
92; DBGVALUE-NEXT: DBG_VALUE [[REG6]], $noreg, !17, !DIExpression(DW_OP_LLVM_fragment, 0, 32)
93; DBGVALUE-NEXT: DBG_VALUE [[REG7]], $noreg, !17, !DIExpression(DW_OP_LLVM_fragment, 32, 32)
94  %u.023 = phi i64 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
95  %y.022 = phi i64 [ 13, %for.body.lr.ph ], [ %mul, %for.body ]
96  %x.021 = phi i64 [ 9, %for.body.lr.ph ], [ %add, %for.body ]
97  call void @llvm.dbg.value(metadata i64 %u.023, metadata !19, metadata !DIExpression()), !dbg !30
98  call void @llvm.dbg.value(metadata i64 %y.022, metadata !18, metadata !DIExpression()), !dbg !29
99  call void @llvm.dbg.value(metadata i64 %x.021, metadata !17, metadata !DIExpression()), !dbg !28
100  %add = add nuw nsw i64 %y.022, %x.021, !dbg !43
101  %mul = mul nsw i64 %y.022, 3, !dbg !45
102  %inc = add nuw nsw i64 %u.023, 1, !dbg !46
103  call void @llvm.dbg.value(metadata i64 %inc, metadata !19, metadata !DIExpression()), !dbg !30
104  call void @llvm.dbg.value(metadata i64 %mul, metadata !18, metadata !DIExpression()), !dbg !29
105  call void @llvm.dbg.value(metadata i64 %add, metadata !17, metadata !DIExpression()), !dbg !28
106  %cmp = icmp slt i64 %inc, %1, !dbg !37
107  br i1 %cmp, label %for.body, label %for.cond.cleanup.loopexit, !dbg !38, !llvm.loop !47
108
109for.cond.cleanup3:                                ; preds = %for.body4
110  ret i32 %x.0.lcssa.off0, !dbg !50
111
112for.body4:                                        ; preds = %for.cond.cleanup, %for.body4
113  %q.019 = phi i64 [ 0, %for.cond.cleanup ], [ %inc7, %for.body4 ]
114  call void @llvm.dbg.value(metadata i64 %q.019, metadata !26, metadata !DIExpression()), !dbg !41
115  %add5 = add nuw nsw i64 %q.019, 3, !dbg !51
116  %idxprom = trunc i64 %q.019 to i32, !dbg !54
117  %arrayidx = getelementptr inbounds [80 x i64], ptr %arr, i32 0, i32 %idxprom, !dbg !54
118  store volatile i64 %add5, ptr %arrayidx, align 8, !dbg !55
119  %inc7 = add nuw nsw i64 %q.019, 1, !dbg !56
120  call void @llvm.dbg.value(metadata i64 %inc7, metadata !26, metadata !DIExpression()), !dbg !41
121  %cmp2 = icmp ult i64 %inc7, 64, !dbg !57
122  br i1 %cmp2, label %for.body4, label %for.cond.cleanup3, !dbg !42, !llvm.loop !58
123}
124
125; Function Attrs: nounwind readnone speculatable
126declare void @llvm.dbg.value(metadata, metadata, metadata) #1
127
128attributes #0 = { nounwind }
129attributes #1 = { nounwind readnone speculatable }
130
131!llvm.dbg.cu = !{!2}
132!llvm.module.flags = !{!7, !8, !9, !10}
133!llvm.ident = !{!11}
134
135!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
136!1 = distinct !DIGlobalVariable(name: "end", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
137!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)
138!3 = !DIFile(filename: "phi-split.c", directory: "")
139!4 = !{}
140!5 = !{!0}
141!6 = !DIBasicType(name: "long long int", size: 64, encoding: DW_ATE_signed)
142!7 = !{i32 1, !"NumRegisterParameters", i32 0}
143!8 = !{i32 2, !"Dwarf Version", i32 4}
144!9 = !{i32 2, !"Debug Info Version", i32 3}
145!10 = !{i32 1, !"wchar_size", i32 4}
146!11 = !{!"clang version 7.0.0  (x)"}
147!12 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 3, type: !13, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: true, unit: !2, retainedNodes: !16)
148!13 = !DISubroutineType(types: !14)
149!14 = !{!15}
150!15 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
151!16 = !{!17, !18, !19, !21, !26}
152!17 = !DILocalVariable(name: "x", scope: !12, file: !3, line: 4, type: !6)
153!18 = !DILocalVariable(name: "y", scope: !12, file: !3, line: 5, type: !6)
154!19 = !DILocalVariable(name: "u", scope: !20, file: !3, line: 6, type: !6)
155!20 = distinct !DILexicalBlock(scope: !12, file: !3, line: 6, column: 3)
156!21 = !DILocalVariable(name: "arr", scope: !12, file: !3, line: 11, type: !22)
157!22 = !DICompositeType(tag: DW_TAG_array_type, baseType: !23, size: 5120, elements: !24)
158!23 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !6)
159!24 = !{!25}
160!25 = !DISubrange(count: 80)
161!26 = !DILocalVariable(name: "q", scope: !27, file: !3, line: 12, type: !6)
162!27 = distinct !DILexicalBlock(scope: !12, file: !3, line: 12, column: 3)
163!28 = !DILocation(line: 4, column: 13, scope: !12)
164!29 = !DILocation(line: 5, column: 13, scope: !12)
165!30 = !DILocation(line: 6, column: 18, scope: !20)
166!31 = !DILocation(line: 6, column: 29, scope: !32)
167!32 = distinct !DILexicalBlock(scope: !20, file: !3, line: 6, column: 3)
168!37 = !DILocation(line: 6, column: 27, scope: !32)
169!38 = !DILocation(line: 6, column: 3, scope: !20)
170!39 = !DILocation(line: 11, column: 3, scope: !12)
171!40 = !DILocation(line: 11, column: 22, scope: !12)
172!41 = !DILocation(line: 12, column: 18, scope: !27)
173!42 = !DILocation(line: 12, column: 3, scope: !27)
174!43 = !DILocation(line: 7, column: 7, scope: !44)
175!44 = distinct !DILexicalBlock(scope: !32, file: !3, line: 6, column: 39)
176!45 = !DILocation(line: 8, column: 11, scope: !44)
177!46 = !DILocation(line: 6, column: 34, scope: !32)
178!47 = distinct !{!47, !38, !48}
179!48 = !DILocation(line: 9, column: 3, scope: !20)
180!50 = !DILocation(line: 16, column: 3, scope: !12)
181!51 = !DILocation(line: 13, column: 16, scope: !52)
182!52 = distinct !DILexicalBlock(scope: !53, file: !3, line: 12, column: 38)
183!53 = distinct !DILexicalBlock(scope: !27, file: !3, line: 12, column: 3)
184!54 = !DILocation(line: 13, column: 5, scope: !52)
185!55 = !DILocation(line: 13, column: 12, scope: !52)
186!56 = !DILocation(line: 12, column: 33, scope: !53)
187!57 = !DILocation(line: 12, column: 27, scope: !53)
188!58 = distinct !{!58, !42, !59}
189!59 = !DILocation(line: 14, column: 3, scope: !27)
190