283 lines · plain
1# RUN: llc %s -o - -experimental-debug-variable-locations=true \2# RUN: -run-pass=livedebugvalues | \3# RUN: FileCheck %s --implicit-check-not=DBG_VALUE4#5## Check that LiveDebugValues can track and join DBG_INSTR_REFs that use6## registers, stack slots, and constants in a single instruction.7#8# CHECK: ![[VAR_D:[0-9]+]] = !DILocalVariable(name: "d"9 10# CHECK-LABEL: bb.0.entry11#12## Value at end of first block should use the registers given by DBG_PHI, and13## fold the offset+deref from stack slot [$rsp+12] into the expression.14# CHECK: DBG_VALUE_LIST ![[VAR_D]]15# CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 2, DW_OP_mul, DW_OP_LLVM_arg, 1, DW_OP_plus_uconst, 12, DW_OP_deref, DW_OP_plus, DW_OP_LLVM_arg, 3, DW_OP_minus, DW_OP_stack_value)16# CHECK-SAME: $ebp, $rsp, $ebx, 617 18# CHECK-LABEL: bb.1.while.body19#20## Prior DBG_VALUE_LIST should be live-in to this bb.1.21# CHECK: DBG_VALUE_LIST ![[VAR_D]]22# CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 2, DW_OP_mul, DW_OP_LLVM_arg, 1, DW_OP_plus_uconst, 12, DW_OP_deref, DW_OP_plus, DW_OP_LLVM_arg, 3, DW_OP_minus, DW_OP_stack_value)23# CHECK-SAME: $ebp, $rsp, $ebx, 624#25## When $ebp is spilled to a stack slot, a new debug value using the stack slot26## should be inserted.27# CHECK: MOV32mr $rsp, {{.+}} $ebp28# CHECK-NEXT: DBG_VALUE_LIST ![[VAR_D]]29# CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_plus_uconst, 16, DW_OP_deref, DW_OP_LLVM_arg, 2, DW_OP_mul, DW_OP_LLVM_arg, 1, DW_OP_plus_uconst, 12, DW_OP_deref, DW_OP_plus, DW_OP_LLVM_arg, 3, DW_OP_minus, DW_OP_stack_value)30# CHECK-SAME: $rsp, $rsp, $ebx, 631#32## Similarly produce a new debug value when $ebx is spilled.33# CHECK: MOV32mr $rsp, {{.+}} $ebx34# CHECK-NEXT: DBG_VALUE_LIST ![[VAR_D]]35# CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_plus_uconst, 16, DW_OP_deref, DW_OP_LLVM_arg, 2, DW_OP_plus_uconst, 20, DW_OP_deref, DW_OP_mul, DW_OP_LLVM_arg, 1, DW_OP_plus_uconst, 12, DW_OP_deref, DW_OP_plus, DW_OP_LLVM_arg, 3, DW_OP_minus, DW_OP_stack_value)36# CHECK-SAME: $rsp, $rsp, $rsp, 637#38## When the value in the stack slot is restored and then that slot is clobbered, the debug value should use the restored register.39# CHECK: MOV32mi $rsp40# CHECK-NEXT: DBG_VALUE_LIST ![[VAR_D]]41# CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_plus_uconst, 16, DW_OP_deref, DW_OP_LLVM_arg, 2, DW_OP_mul, DW_OP_LLVM_arg, 1, DW_OP_plus_uconst, 12, DW_OP_deref, DW_OP_plus, DW_OP_LLVM_arg, 3, DW_OP_minus, DW_OP_stack_value)42# CHECK-SAME: $rsp, $rsp, $ebx, 643#44## Repeat for the next stack slot that gets restored and then clobbered.45# CHECK: MOV32mi $rsp46# CHECK-NEXT: DBG_VALUE_LIST ![[VAR_D]]47# CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 2, DW_OP_mul, DW_OP_LLVM_arg, 1, DW_OP_plus_uconst, 12, DW_OP_deref, DW_OP_plus, DW_OP_LLVM_arg, 3, DW_OP_minus, DW_OP_stack_value)48# CHECK-SAME: $ebp, $rsp, $ebx, 649#50## TODO: The debug value range should be terminated when the value in $ebx is clobbered.51#52## At the end of the block a new DBG_INSTR_REF begins a new range.53# CHECK: DBG_VALUE_LIST ![[VAR_D]]54# CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 2, DW_OP_mul, DW_OP_LLVM_arg, 1, DW_OP_plus_uconst, 12, DW_OP_deref, DW_OP_plus, DW_OP_LLVM_arg, 3, DW_OP_minus, DW_OP_stack_value)55# CHECK-SAME: $ebp, $rsp, $ebx, 656 57# CHECK-LABEL: bb.2.while.end58#59## Finally, the two entry debug values should be joined, as they have identical60## expressions, their respective stack slots and constants are identical, and61## the remaining operands occupy the same registers out of each block.62# CHECK: DBG_VALUE_LIST ![[VAR_D]]63# CHECK-SAME: !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 2, DW_OP_mul, DW_OP_LLVM_arg, 1, DW_OP_plus_uconst, 12, DW_OP_deref, DW_OP_plus, DW_OP_LLVM_arg, 3, DW_OP_minus, DW_OP_stack_value)64# CHECK-SAME: $ebp, $rsp, $ebx, 665 66 67--- |68 69 ; ModuleID = 'test.ll'70 source_filename = "test.cpp"71 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"72 target triple = "x86_64-unknown-linux-gnu"73 74 ; Function Attrs: mustprogress uwtable75 define dso_local noundef i32 @_Z3fooii(i32 noundef %a, i32 noundef %b) local_unnamed_addr !dbg !9 {76 entry:77 %call = tail call noundef i32 @_Z3bazv(), !dbg !1878 call void @llvm.dbg.value(metadata !DIArgList(i32 %a, i32 %call, i32 %b), metadata !17, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 2, DW_OP_mul, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_constu, 6, DW_OP_minus, DW_OP_stack_value)), !dbg !1979 %cmp19 = icmp sgt i32 %b, %a, !dbg !2080 br i1 %cmp19, label %while.body.preheader, label %while.end, !dbg !2181 82 while.body.preheader: ; preds = %entry83 br label %while.body, !dbg !2184 85 while.body: ; preds = %while.body.preheader, %while.body86 %a.addr.021 = phi i32 [ %mul3, %while.body ], [ %a, %while.body.preheader ]87 %b.addr.020 = phi i32 [ %add2, %while.body ], [ %b, %while.body.preheader ]88 %call1 = tail call noundef i32 @_Z3bazv(), !dbg !2289 tail call void asm sideeffect "", "~{rax},~{rbx},~{rcx},~{rdx},~{rsi},~{rdi},~{rbp},~{r8},~{r9},~{r10},~{r11},~{r12},~{r13},~{r14},~{r15},~{dirflag},~{fpsr},~{flags}"() #3, !dbg !24, !srcloc !2590 %add2 = add i32 %b.addr.020, 2, !dbg !2691 %mul3 = shl nsw i32 %a.addr.021, 1, !dbg !2792 call void @llvm.dbg.value(metadata !DIArgList(i32 %mul3, i32 %call, i32 %add2), metadata !17, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 2, DW_OP_mul, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_constu, 6, DW_OP_minus, DW_OP_stack_value)), !dbg !1993 %cmp = icmp sgt i32 %add2, %mul3, !dbg !2094 br i1 %cmp, label %while.body, label %while.end, !dbg !21, !llvm.loop !2895 96 while.end: ; preds = %while.body, %entry97 %b.addr.0.lcssa = phi i32 [ %b, %entry ], [ %add2, %while.body ]98 %a.addr.0.lcssa = phi i32 [ %a, %entry ], [ %mul3, %while.body ]99 %add7 = sub i32 %b.addr.0.lcssa, %call, !dbg !31100 %sub8 = add i32 %add7, %a.addr.0.lcssa, !dbg !32101 ret i32 %sub8, !dbg !33102 }103 104 declare !dbg !34 noundef i32 @_Z3bazv() local_unnamed_addr105 106 ; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn107 declare void @llvm.dbg.value(metadata, metadata, metadata)108 109 !llvm.dbg.cu = !{!0}110 !llvm.module.flags = !{!2, !3, !4, !5, !6, !7}111 !llvm.ident = !{!8}112 113 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 16.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)114 !1 = !DIFile(filename: "test.cpp", directory: "/")115 !2 = !{i32 7, !"Dwarf Version", i32 5}116 !3 = !{i32 2, !"Debug Info Version", i32 3}117 !4 = !{i32 1, !"wchar_size", i32 4}118 !5 = !{i32 8, !"PIC Level", i32 2}119 !6 = !{i32 7, !"PIE Level", i32 2}120 !7 = !{i32 7, !"uwtable", i32 2}121 !8 = !{!"clang version 16.0.0"}122 !9 = distinct !DISubprogram(name: "foo", linkageName: "_Z3fooii", scope: !1, file: !1, line: 3, type: !10, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !13)123 !10 = !DISubroutineType(types: !11)124 !11 = !{!12, !12, !12}125 !12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)126 !13 = !{!14, !15, !16, !17}127 !14 = !DILocalVariable(name: "a", arg: 1, scope: !9, file: !1, line: 3, type: !12)128 !15 = !DILocalVariable(name: "b", arg: 2, scope: !9, file: !1, line: 3, type: !12)129 !16 = !DILocalVariable(name: "c", scope: !9, file: !1, line: 4, type: !12)130 !17 = !DILocalVariable(name: "d", scope: !9, file: !1, line: 5, type: !12)131 !18 = !DILocation(line: 4, column: 11, scope: !9)132 !19 = !DILocation(line: 0, scope: !9)133 !20 = !DILocation(line: 6, column: 12, scope: !9)134 !21 = !DILocation(line: 6, column: 3, scope: !9)135 !22 = !DILocation(line: 7, column: 5, scope: !23)136 !23 = distinct !DILexicalBlock(scope: !9, file: !1, line: 6, column: 17)137 !24 = !DILocation(line: 9, column: 5, scope: !23)138 !25 = !{i64 129}139 !26 = !DILocation(line: 8, column: 7, scope: !23)140 !27 = !DILocation(line: 10, column: 7, scope: !23)141 !28 = distinct !{!28, !21, !29, !30}142 !29 = !DILocation(line: 12, column: 3, scope: !9)143 !30 = !{!"llvm.loop.mustprogress"}144 !31 = !DILocation(line: 13, column: 12, scope: !9)145 !32 = !DILocation(line: 13, column: 16, scope: !9)146 !33 = !DILocation(line: 13, column: 3, scope: !9)147 !34 = !DISubprogram(name: "baz", linkageName: "_Z3bazv", scope: !1, file: !1, line: 1, type: !35, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !37)148 !35 = !DISubroutineType(types: !36)149 !36 = !{!12}150 !37 = !{}151 152...153---154name: _Z3fooii155alignment: 16156tracksRegLiveness: true157tracksDebugUserValues: true158debugInstrRef: true159registers: []160liveins:161 - { reg: '$edi', virtual-reg: '' }162 - { reg: '$esi', virtual-reg: '' }163frameInfo:164 stackSize: 72165 offsetAdjustment: -72166 maxAlignment: 4167 adjustsStack: true168 hasCalls: true169 stackProtector: ''170 functionContext: ''171 cvBytesOfCalleeSavedRegisters: 48172 savePoint: []173 restorePoint: []174fixedStack:175 - { id: 0, type: spill-slot, offset: -56, size: 8, alignment: 8, stack-id: default, 176 callee-saved-register: '$rbx', callee-saved-restored: true, debug-info-variable: '', 177 debug-info-expression: '', debug-info-location: '' }178 - { id: 1, type: spill-slot, offset: -48, size: 8, alignment: 16, stack-id: default, 179 callee-saved-register: '$r12', callee-saved-restored: true, debug-info-variable: '', 180 debug-info-expression: '', debug-info-location: '' }181 - { id: 2, type: spill-slot, offset: -40, size: 8, alignment: 8, stack-id: default, 182 callee-saved-register: '$r13', callee-saved-restored: true, debug-info-variable: '', 183 debug-info-expression: '', debug-info-location: '' }184 - { id: 3, type: spill-slot, offset: -32, size: 8, alignment: 16, stack-id: default, 185 callee-saved-register: '$r14', callee-saved-restored: true, debug-info-variable: '', 186 debug-info-expression: '', debug-info-location: '' }187 - { id: 4, type: spill-slot, offset: -24, size: 8, alignment: 8, stack-id: default, 188 callee-saved-register: '$r15', callee-saved-restored: true, debug-info-variable: '', 189 debug-info-expression: '', debug-info-location: '' }190 - { id: 5, type: spill-slot, offset: -16, size: 8, alignment: 16, stack-id: default, 191 callee-saved-register: '$rbp', callee-saved-restored: true, debug-info-variable: '', 192 debug-info-expression: '', debug-info-location: '' }193stack:194 - { id: 0, name: '', type: spill-slot, offset: -60, size: 4, alignment: 4, 195 stack-id: default, callee-saved-register: '', callee-saved-restored: true, 196 debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }197 - { id: 1, name: '', type: spill-slot, offset: -64, size: 4, alignment: 4, 198 stack-id: default, callee-saved-register: '', callee-saved-restored: true, 199 debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }200 - { id: 2, name: '', type: spill-slot, offset: -68, size: 4, alignment: 4, 201 stack-id: default, callee-saved-register: '', callee-saved-restored: true, 202 debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }203callSites: []204debugValueSubstitutions: []205constants: []206machineFunctionInfo: {}207body: |208 bb.0.entry:209 successors: %bb.1(0x78e38e39), %bb.3(0x071c71c7)210 liveins: $edi, $esi, $rbp, $r15, $r14, $r13, $r12, $rbx211 212 frame-setup PUSH64r killed $rbp, implicit-def $rsp, implicit $rsp213 frame-setup CFI_INSTRUCTION def_cfa_offset 16214 frame-setup PUSH64r killed $r15, implicit-def $rsp, implicit $rsp215 frame-setup CFI_INSTRUCTION def_cfa_offset 24216 frame-setup PUSH64r killed $r14, implicit-def $rsp, implicit $rsp217 frame-setup CFI_INSTRUCTION def_cfa_offset 32218 frame-setup PUSH64r killed $r13, implicit-def $rsp, implicit $rsp219 frame-setup CFI_INSTRUCTION def_cfa_offset 40220 frame-setup PUSH64r killed $r12, implicit-def $rsp, implicit $rsp221 frame-setup CFI_INSTRUCTION def_cfa_offset 48222 frame-setup PUSH64r killed $rbx, implicit-def $rsp, implicit $rsp223 frame-setup CFI_INSTRUCTION def_cfa_offset 56224 $rsp = frame-setup SUB64ri8 $rsp, 24, implicit-def dead $eflags225 frame-setup CFI_INSTRUCTION def_cfa_offset 80226 CFI_INSTRUCTION offset $rbx, -56227 CFI_INSTRUCTION offset $r12, -48228 CFI_INSTRUCTION offset $r13, -40229 CFI_INSTRUCTION offset $r14, -32230 CFI_INSTRUCTION offset $r15, -24231 CFI_INSTRUCTION offset $rbp, -16232 DBG_PHI $esi, 5233 DBG_PHI $edi, 3234 $ebx = MOV32rr $esi235 $ebp = MOV32rr $edi236 CALL64pcrel32 target-flags(x86-plt) @_Z3bazv, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-instr-number 4, debug-location !18237 MOV32mr $rsp, 1, $noreg, 12, $noreg, $eax :: (store (s32) into %stack.2)238 DBG_INSTR_REF !17, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 2, DW_OP_mul, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_LLVM_arg, 3, DW_OP_minus, DW_OP_stack_value), dbg-instr-ref(3, 0), dbg-instr-ref(4, 6), dbg-instr-ref(5, 0), 6, debug-location !19239 CMP32rr renamable $ebx, renamable $ebp, implicit-def $eflags, debug-location !20240 JCC_1 %bb.3, 14, implicit $eflags, debug-location !21241 242 bb.1.while.body (align 16):243 successors: %bb.1(0x78e38e39), %bb.3(0x071c71c7)244 liveins: $ebp, $ebx245 246 MOV32mr $rsp, 1, $noreg, 16, $noreg, killed renamable $ebp :: (store (s32) into %stack.1)247 MOV32mr $rsp, 1, $noreg, 20, $noreg, killed renamable $ebx :: (store (s32) into %stack.0)248 CALL64pcrel32 target-flags(x86-plt) @_Z3bazv, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, implicit-def dead $eax, debug-location !22249 INLINEASM &"", 1 /* sideeffect attdialect */, 12 /* clobber */, implicit-def dead early-clobber $rax, 12 /* clobber */, implicit-def dead early-clobber $rbx, 12 /* clobber */, implicit-def dead early-clobber $rcx, 12 /* clobber */, implicit-def dead early-clobber $rdx, 12 /* clobber */, implicit-def dead early-clobber $rsi, 12 /* clobber */, implicit-def dead early-clobber $rdi, 12 /* clobber */, implicit-def dead early-clobber $rbp, 12 /* clobber */, implicit-def dead early-clobber $r8, 12 /* clobber */, implicit-def dead early-clobber $r9, 12 /* clobber */, implicit-def dead early-clobber $r10, 12 /* clobber */, implicit-def dead early-clobber $r11, 12 /* clobber */, implicit-def dead early-clobber $r12, 12 /* clobber */, implicit-def dead early-clobber $r13, 12 /* clobber */, implicit-def dead early-clobber $r14, 12 /* clobber */, implicit-def dead early-clobber $r15, 12 /* clobber */, implicit-def dead early-clobber $df, 12 /* clobber */, implicit-def early-clobber $fpsw, 12 /* clobber */, implicit-def dead early-clobber $eflags, !25, debug-location !24250 renamable $ebp = MOV32rm $rsp, 1, $noreg, 16, $noreg :: (load (s32) from %stack.1)251 renamable $ebx = MOV32rm $rsp, 1, $noreg, 20, $noreg :: (load (s32) from %stack.0)252 MOV32mi $rsp, 1, $noreg, 20, $noreg, 0 :: (store (s32) into %stack.0)253 MOV32mi $rsp, 1, $noreg, 16, $noreg, 0 :: (store (s32) into %stack.1)254 renamable $ebx = ADD32ri8 killed renamable $ebx, 2, implicit-def dead $eflags, debug-instr-number 2, debug-location !26255 renamable $ebp = nsw ADD32rr killed renamable $ebp, renamable $ebp, implicit-def dead $eflags, debug-instr-number 1, debug-location !27256 DBG_INSTR_REF !17, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 2, DW_OP_mul, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_LLVM_arg, 3, DW_OP_minus, DW_OP_stack_value), dbg-instr-ref(1, 0), dbg-instr-ref(4, 6), dbg-instr-ref(2, 0), 6, debug-location !19257 CMP32rr renamable $ebx, renamable $ebp, implicit-def $eflags, debug-location !20258 JCC_1 %bb.1, 15, implicit $eflags, debug-location !21259 260 bb.3.while.end:261 liveins: $ebp, $ebx262 263 renamable $ebx = SUB32rm killed renamable $ebx, $rsp, 1, $noreg, 12, $noreg, implicit-def dead $eflags, debug-location !31 :: (load (s32) from %stack.2)264 renamable $ebx = ADD32rr killed renamable $ebx, killed renamable $ebp, implicit-def dead $eflags, debug-location !32265 $eax = MOV32rr killed $ebx, debug-location !33266 $rsp = frame-destroy ADD64ri8 $rsp, 24, implicit-def dead $eflags, debug-location !33267 frame-destroy CFI_INSTRUCTION def_cfa_offset 56, debug-location !33268 $rbx = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !33269 frame-destroy CFI_INSTRUCTION def_cfa_offset 48, debug-location !33270 $r12 = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !33271 frame-destroy CFI_INSTRUCTION def_cfa_offset 40, debug-location !33272 $r13 = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !33273 frame-destroy CFI_INSTRUCTION def_cfa_offset 32, debug-location !33274 $r14 = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !33275 frame-destroy CFI_INSTRUCTION def_cfa_offset 24, debug-location !33276 $r15 = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !33277 frame-destroy CFI_INSTRUCTION def_cfa_offset 16, debug-location !33278 $rbp = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !33279 frame-destroy CFI_INSTRUCTION def_cfa_offset 8, debug-location !33280 RET64 $eax, debug-location !33281 282...283