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