1# RUN: llc -mtriple=x86_64-unknown-unknown %s -o - -run-pass=livedebugvalues | FileCheck %s 2# 3# Fix some of PR42772. Consider the code below: the arguments are forced onto 4# the stack by the FORCE_SPILL macro, and go out of liveness if the 5# "bees == 2" conditional is not taken. A spill slot is then re-used to 6# preserve quux over the second FORCE_SPILL, over-writing the value of either 7# "a" or "b". LiveDebugValues should detect when this happens, and terminate 8# stack-spill locations when they get overwritten by a new value. 9# 10# --------8<-------- 11# #define FORCE_SPILL() \ 12# __asm volatile("" : : : \ 13# "rax", "rbx", "rcx", "rdx", "rsi", "rdi", "rbp", "r8", \ 14# "r9", "r10", "r11", "r12", "r13", "r14", "r15") 15# 16# volatile int bees = 0; 17# 18# long int f(long int a, long int b) { 19# if (bees == 12) 20# return 3; 21# 22# FORCE_SPILL(); 23# if (bees == 2) 24# return a - b; 25# 26# int quux = sum(1, 2); 27# FORCE_SPILL(); 28# bees++; 29# return quux; 30# } 31# -------->8-------- 32# 33# CHECK: ![[ANUM:[0-9]+]] = !DILocalVariable(name: "a" 34# CHECK: ![[BNUM:[0-9]+]] = !DILocalVariable(name: "b" 35# CHECK: ![[CNUM:[0-9]+]] = !DILocalVariable(name: "c" 36# 37# These variables should be spilt, 38# CHECK-LABEL: bb.1.if.end: 39# CHECK: MOV64mr $rsp, 1, $noreg, 16, $noreg, killed renamable $rsi 40# CHECK-NEXT: DBG_VALUE_LIST ![[CNUM]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_plus_uconst, 16, DW_OP_deref 41# CHECK-SAME: $rsp, $rdi 42# CHECK-NEXT: DBG_VALUE $rsp, 0, ![[BNUM]], !DIExpression( 43# CHECK-NEXT: MOV64mr $rsp, 1, $noreg, 8, $noreg, killed renamable $rdi 44# CHECK-NEXT: DBG_VALUE_LIST ![[CNUM]], !DIExpression({{[^)]+}}DW_OP_LLVM_arg, 1, DW_OP_plus_uconst, 8, DW_OP_deref 45# CHECK-SAME: $rsp, $rsp 46# CHECK-NEXT: DBG_VALUE $rsp, 0, ![[ANUM]], !DIExpression( 47# CHECK-NEXT: INLINEASM 48# 49# Then the location of "a" should be terminated when overwritten 50# CHECK-LABEL: bb.3.if.end3: 51# CHECK: CALL64pcrel32 @sum 52# CHECK-NEXT: MOV64mr $rsp, 1, $noreg, 8, $noreg, $rax 53# CHECK-NEXT: DBG_VALUE_LIST ![[CNUM]], !DIExpression({{[^)]*}}), $noreg, $noreg 54# CHECK-NEXT: DBG_VALUE $noreg, $noreg, ![[ANUM]], !DIExpression() 55# CHECK-NEXT: INLINEASM 56 57--- | 58 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 59 target triple = "x86_64-unknown-linux-gnu" 60 61 @bees = external global i32, !dbg !0 62 63 ; Function Attrs: noinline norecurse nounwind readnone uwtable 64 declare i64 @sum(i64, i64) 65 66 ; Function Attrs: noinline nounwind uwtable 67 define i64 @f(i64 %a, i64 %b) !dbg !12 { 68 entry: 69 br label %if.end 70 if.end: 71 br label %if.then2 72 if.then2: 73 br label %if.end3 74 if.end3: 75 br label %return 76 return: 77 ret i64 0 78 } 79 80 !llvm.dbg.cu = !{!2} 81 !llvm.module.flags = !{!8, !9, !10} 82 83 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 84 !1 = distinct !DIGlobalVariable(name: "bees", scope: !2, file: !3, line: 6, type: !6, isLocal: false, isDefinition: true) 85 !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None) 86 !3 = !DIFile(filename: "pr42772.c", directory: ".") 87 !4 = !{} 88 !5 = !{!0} 89 !6 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !7) 90 !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 91 !8 = !{i32 2, !"Dwarf Version", i32 4} 92 !9 = !{i32 2, !"Debug Info Version", i32 3} 93 !10 = !{i32 1, !"wchar_size", i32 4} 94 !12 = distinct !DISubprogram(name: "f", scope: !3, file: !3, line: 15, type: !13, scopeLine: 15, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !16) 95 !13 = !DISubroutineType(types: !14) 96 !14 = !{!15, !15, !15} 97 !15 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed) 98 !16 = !{!17, !18, !19} 99 !17 = !DILocalVariable(name: "a", arg: 1, scope: !12, file: !3, line: 15, type: !15) 100 !18 = !DILocalVariable(name: "b", arg: 2, scope: !12, file: !3, line: 15, type: !15) 101 !19 = !DILocalVariable(name: "c", scope: !12, file: !3, line: 23, type: !7) 102 !28 = !DILocation(line: 1, column: 1, scope: !12) 103 104... 105--- 106name: f 107tracksRegLiveness: true 108debugInstrRef: true 109liveins: 110 - { reg: '$rdi', virtual-reg: '' } 111 - { reg: '$rsi', virtual-reg: '' } 112frameInfo: 113 stackSize: 72 114 offsetAdjustment: -72 115 maxAlignment: 8 116 adjustsStack: true 117 hasCalls: true 118 cvBytesOfCalleeSavedRegisters: 48 119fixedStack: 120 - { id: 0, type: spill-slot, offset: -56, size: 8, alignment: 8, stack-id: default, 121 callee-saved-register: '$rbx', callee-saved-restored: true, debug-info-variable: '', 122 debug-info-expression: '', debug-info-location: '' } 123 - { id: 1, type: spill-slot, offset: -48, size: 8, alignment: 16, stack-id: default, 124 callee-saved-register: '$r12', callee-saved-restored: true, debug-info-variable: '', 125 debug-info-expression: '', debug-info-location: '' } 126 - { id: 2, type: spill-slot, offset: -40, size: 8, alignment: 8, stack-id: default, 127 callee-saved-register: '$r13', callee-saved-restored: true, debug-info-variable: '', 128 debug-info-expression: '', debug-info-location: '' } 129 - { id: 3, type: spill-slot, offset: -32, size: 8, alignment: 16, stack-id: default, 130 callee-saved-register: '$r14', callee-saved-restored: true, debug-info-variable: '', 131 debug-info-expression: '', debug-info-location: '' } 132 - { id: 4, type: spill-slot, offset: -24, size: 8, alignment: 8, stack-id: default, 133 callee-saved-register: '$r15', callee-saved-restored: true, debug-info-variable: '', 134 debug-info-expression: '', debug-info-location: '' } 135 - { id: 5, type: spill-slot, offset: -16, size: 8, alignment: 16, stack-id: default, 136 callee-saved-register: '$rbp', callee-saved-restored: true, debug-info-variable: '', 137 debug-info-expression: '', debug-info-location: '' } 138stack: 139 - { id: 0, name: '', type: spill-slot, offset: -72, size: 8, alignment: 8, 140 stack-id: default, callee-saved-register: '', callee-saved-restored: true, 141 debug-info-variable: '', debug-info-expression: '', debug-info-location: '' } 142 - { id: 1, name: '', type: spill-slot, offset: -64, size: 8, alignment: 8, 143 stack-id: default, callee-saved-register: '', callee-saved-restored: true, 144 debug-info-variable: '', debug-info-expression: '', debug-info-location: '' } 145body: | 146 bb.0.entry: 147 successors: %bb.4, %bb.1 148 liveins: $rdi, $rsi, $rbp, $r15, $r14, $r13, $r12, $rbx 149 150 DBG_VALUE $rdi, $noreg, !17, !DIExpression(), debug-location !28 151 DBG_VALUE $rdi, $noreg, !17, !DIExpression(), debug-location !28 152 DBG_VALUE $rsi, $noreg, !18, !DIExpression(), debug-location !28 153 DBG_VALUE $rsi, $noreg, !18, !DIExpression(), debug-location !28 154 DBG_VALUE_LIST !19, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus), $rsi, $rdi, debug-location !28 155 frame-setup PUSH64r killed $rbp, implicit-def $rsp, implicit $rsp, debug-location !28 156 frame-setup PUSH64r killed $r15, implicit-def $rsp, implicit $rsp, debug-location !28 157 frame-setup PUSH64r killed $r14, implicit-def $rsp, implicit $rsp, debug-location !28 158 frame-setup PUSH64r killed $r13, implicit-def $rsp, implicit $rsp, debug-location !28 159 frame-setup PUSH64r killed $r12, implicit-def $rsp, implicit $rsp, debug-location !28 160 frame-setup PUSH64r killed $rbx, implicit-def $rsp, implicit $rsp, debug-location !28 161 $rsp = frame-setup SUB64ri8 $rsp, 24, implicit-def dead $eflags 162 renamable $ecx = MOV32rm $rip, 1, $noreg, @bees, $noreg, debug-location !28 :: (volatile dereferenceable load (s32) from @bees) 163 $eax = MOV32ri 3, implicit-def $rax 164 CMP32ri killed renamable $ecx, 12, implicit-def $eflags, debug-location !28 165 JCC_1 %bb.4, 4, implicit $eflags, debug-location !28 166 167 bb.1.if.end: 168 successors: %bb.2, %bb.3 169 liveins: $rdi, $rsi 170 171 MOV64mr $rsp, 1, $noreg, 16, $noreg, killed renamable $rsi :: (store (s64) into %stack.1) 172 MOV64mr $rsp, 1, $noreg, 8, $noreg, killed renamable $rdi :: (store (s64) into %stack.0) 173 INLINEASM &"", 1, 12, implicit-def dead early-clobber $rax, 12, implicit-def dead early-clobber $rbx, 12, implicit-def dead early-clobber $rcx, 12, implicit-def dead early-clobber $rdx, 12, implicit-def dead early-clobber $rsi, 12, implicit-def dead early-clobber $rdi, 12, implicit-def dead early-clobber $rbp, 12, implicit-def dead early-clobber $r8, 12, implicit-def dead early-clobber $r9, 12, implicit-def dead early-clobber $r10, 12, implicit-def dead early-clobber $r11, 12, implicit-def dead early-clobber $r12, 12, implicit-def dead early-clobber $r13, 12, implicit-def dead early-clobber $r14, 12, implicit-def dead early-clobber $r15, 12, implicit-def dead early-clobber $df, 12, implicit-def dead early-clobber $fpsw, 12, implicit-def dead early-clobber $eflags, debug-location !28 174 renamable $eax = MOV32rm $rip, 1, $noreg, @bees, $noreg, debug-location !28 :: (volatile dereferenceable load (s32) from @bees) 175 CMP32ri killed renamable $eax, 2, implicit-def $eflags, debug-location !28 176 JCC_1 %bb.3, 5, implicit killed $eflags, debug-location !28 177 178 bb.2.if.then2: 179 successors: %bb.4 180 181 renamable $rax = MOV64rm $rsp, 1, $noreg, 8, $noreg :: (load (s64) from %stack.0) 182 renamable $rax = SUB64rm killed renamable $rax, $rsp, 1, $noreg, 16, $noreg, implicit-def dead $eflags, debug-location !28 :: (load (s64) from %stack.1) 183 JMP_1 %bb.4 184 185 bb.3.if.end3: 186 successors: %bb.4 187 188 $edi = MOV32ri 1, implicit-def $rdi, debug-location !28 189 $esi = MOV32ri 2, implicit-def $rsi, debug-location !28 190 CALL64pcrel32 @sum, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit $rsi, implicit-def $rsp, implicit-def $ssp, implicit-def $rax, debug-location !28 191 MOV64mr $rsp, 1, $noreg, 8, $noreg, $rax :: (store (s64) into %stack.0) 192 INLINEASM &"", 1, 12, implicit-def dead early-clobber $rax, 12, implicit-def dead early-clobber $rbx, 12, implicit-def dead early-clobber $rcx, 12, implicit-def dead early-clobber $rdx, 12, implicit-def dead early-clobber $rsi, 12, implicit-def dead early-clobber $rdi, 12, implicit-def dead early-clobber $rbp, 12, implicit-def dead early-clobber $r8, 12, implicit-def dead early-clobber $r9, 12, implicit-def dead early-clobber $r10, 12, implicit-def dead early-clobber $r11, 12, implicit-def dead early-clobber $r12, 12, implicit-def dead early-clobber $r13, 12, implicit-def dead early-clobber $r14, 12, implicit-def dead early-clobber $r15, 12, implicit-def dead early-clobber $df, 12, implicit-def dead early-clobber $fpsw, 12, implicit-def dead early-clobber $eflags, debug-location !28 193 ADD32mi $rip, 1, $noreg, @bees, $noreg, 1, implicit-def dead $eflags, debug-location !28 :: (volatile store (s32) into @bees), (volatile dereferenceable load (s32) from @bees) 194 renamable $rax = MOVSX64rm32 $rsp, 1, $noreg, 8, $noreg, debug-location !28 :: (load (s32) from %stack.0, align 8) 195 196 bb.4.return: 197 liveins: $rax 198 199 $rsp = frame-destroy ADD64ri8 $rsp, 24, implicit-def dead $eflags, debug-location !28 200 $rbx = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !28 201 $r12 = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !28 202 $r13 = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !28 203 $r14 = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !28 204 $r15 = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !28 205 $rbp = frame-destroy POP64r implicit-def $rsp, implicit $rsp, debug-location !28 206 RET64 $rax, debug-location !28 207 208... 209