1# RUN: llc %s -o - -mtriple=x86_64-unknown-unknown \
2# RUN:    -experimental-debug-variable-locations \
3# RUN:    -run-pass=phi-node-elimination,livedebugvars,greedy,virtregrewriter \
4# RUN:    | FileCheck %s
5#
6# Like phi-through-regalloc.mir, pass a PHI node into register allocation, and
7# test that it correctly comes out, in a stack slot. Fifteen spurious PHIs have
8# been added to force the register allocator to spill one.
9
10--- |
11  ; ModuleID = 'promoted.ll'
12  source_filename = "test.c"
13  target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
14  target triple = "x86_64-unknown-linux-gnu"
15
16  define dso_local i32 @foo(i32 %bar, i32 %baz) !dbg !7 {
17  entry:
18    ret i32 0, !dbg !19
19  }
20
21  declare dso_local i32 @ext(i32)
22
23  ; Function Attrs: nounwind readnone speculatable willreturn
24  declare void @llvm.dbg.value(metadata, metadata, metadata)
25
26  !llvm.dbg.cu = !{!0}
27  !llvm.module.flags = !{!3, !4, !5}
28  !llvm.ident = !{!6}
29
30  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
31  !1 = !DIFile(filename: "test.c", directory: ".")
32  !2 = !{}
33  !3 = !{i32 7, !"Dwarf Version", i32 4}
34  !4 = !{i32 2, !"Debug Info Version", i32 3}
35  !5 = !{i32 1, !"wchar_size", i32 4}
36  !6 = !{!"."}
37  !7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
38  !8 = !DISubroutineType(types: !9)
39  !9 = !{!10, !10, !10}
40  !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
41  !11 = !DILocalVariable(name: "bar", arg: 1, scope: !7, file: !1, line: 2, type: !10)
42  !12 = !DILocation(line: 0, scope: !7)
43  !13 = !DILocalVariable(name: "baz", arg: 2, scope: !7, file: !1, line: 2, type: !10)
44  !14 = !DILocalVariable(name: "either", scope: !7, file: !1, line: 3, type: !10)
45  !15 = !DILocation(line: 4, column: 7, scope: !16)
46  !16 = distinct !DILexicalBlock(scope: !7, file: !1, line: 4, column: 7)
47  !17 = !DILocation(line: 4, column: 7, scope: !7)
48  !18 = !DILocation(line: 0, scope: !16)
49  !19 = !DILocation(line: 9, column: 3, scope: !7)
50
51...
52---
53name:            foo
54alignment:       16
55tracksRegLiveness: true
56registers:
57  - { id: 0, class: gr32 }
58  - { id: 1, class: gr32 }
59  - { id: 2, class: gr32 }
60  - { id: 3, class: gr32 }
61  - { id: 4, class: gr32 }
62liveins:
63  - { reg: '$edi', virtual-reg: '%1' }
64  - { reg: '$esi', virtual-reg: '%2' }
65frameInfo:
66  maxAlignment:    1
67  hasCalls:        true
68machineFunctionInfo: {}
69body:             |
70  ; CHECK-LABEL: bb.0:
71  ; CHECK:       renamable $ebp = COPY $edi
72  ; CHECK:       MOV32mr %stack.1, 1, $noreg, 0, $noreg, killed renamable $ebp
73  bb.0:
74    successors: %bb.2(0x50000000), %bb.1(0x30000000)
75    liveins: $edi, $esi
76
77    DBG_VALUE $edi, $noreg, !11, !DIExpression(), debug-location !12
78    DBG_VALUE $esi, $noreg, !13, !DIExpression(), debug-location !12
79    %2:gr32 = COPY killed $esi
80    %1:gr32 = COPY killed $edi
81    ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !15
82    %3:gr32 = MOV32r0 implicit-def dead $eflags
83    $edi = COPY killed %3, debug-location !15
84    CALL64pcrel32 @ext, csr_64, implicit $rsp, implicit $ssp, implicit killed $edi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-location !15
85    ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !15
86    %4:gr32 = COPY killed $eax, debug-location !15
87    %10:gr32 = MOV32ri 0
88    %11:gr32 = MOV32ri 1
89    %12:gr32 = MOV32ri 2
90    %13:gr32 = MOV32ri 3
91    %14:gr32 = MOV32ri 4
92    %15:gr32 = MOV32ri 5
93    %16:gr32 = MOV32ri 6
94    %17:gr32 = MOV32ri 7
95    %18:gr32 = MOV32ri 8
96    %19:gr32 = MOV32ri 9
97    %20:gr32 = MOV32ri 10
98    %21:gr32 = MOV32ri 11
99    %22:gr32 = MOV32ri 12
100    %23:gr32 = MOV32ri 13
101    %24:gr32 = MOV32ri 14
102    TEST32rr killed %4, %4, implicit-def $eflags, debug-location !15
103    JCC_1 %bb.2, 5, implicit killed $eflags, debug-location !17
104    JMP_1 %bb.1, debug-location !17
105
106  bb.1:
107    %30:gr32 = MOV32ri 0
108    %31:gr32 = MOV32ri 1
109    %32:gr32 = MOV32ri 2
110    %33:gr32 = MOV32ri 3
111    %34:gr32 = MOV32ri 4
112    %35:gr32 = MOV32ri 5
113    %36:gr32 = MOV32ri 6
114    %37:gr32 = MOV32ri 7
115    %38:gr32 = MOV32ri 8
116    %39:gr32 = MOV32ri 9
117    %40:gr32 = MOV32ri 10
118    %41:gr32 = MOV32ri 11
119    %42:gr32 = MOV32ri 12
120    %43:gr32 = MOV32ri 13
121    %44:gr32 = MOV32ri 14
122
123    ; CHECK-LABEL: bb.2:
124  bb.2:
125    %0:gr32 = PHI %1, %bb.0, %2, %bb.1, debug-instr-number 1, debug-location !18
126    %50:gr32 = PHI %10, %bb.0, %30, %bb.1, debug-location !18
127    %51:gr32 = PHI %11, %bb.0, %31, %bb.1, debug-location !18
128    %52:gr32 = PHI %12, %bb.0, %32, %bb.1, debug-location !18
129    %53:gr32 = PHI %13, %bb.0, %33, %bb.1, debug-location !18
130    %54:gr32 = PHI %14, %bb.0, %34, %bb.1, debug-location !18
131    %55:gr32 = PHI %15, %bb.0, %35, %bb.1, debug-location !18
132    %56:gr32 = PHI %16, %bb.0, %36, %bb.1, debug-location !18
133    %57:gr32 = PHI %17, %bb.0, %37, %bb.1, debug-location !18
134    %58:gr32 = PHI %18, %bb.0, %38, %bb.1, debug-location !18
135    %59:gr32 = PHI %19, %bb.0, %39, %bb.1, debug-location !18
136    %60:gr32 = PHI %20, %bb.0, %40, %bb.1, debug-location !18
137    %61:gr32 = PHI %21, %bb.0, %41, %bb.1, debug-location !18
138    %62:gr32 = PHI %22, %bb.0, %42, %bb.1, debug-location !18
139    %63:gr32 = PHI %23, %bb.0, %43, %bb.1, debug-location !18
140    %64:gr32 = PHI %24, %bb.0, %44, %bb.1, debug-location !18
141
142    DBG_INSTR_REF 1, 0, !14, !DIExpression(), debug-location !12
143    ; CHECK:      DBG_PHI %stack.1, 1, 32
144    ; CHECK:      renamable $eax = MOV32rm %stack.1,
145    ; CHECK:      DBG_INSTR_REF 1, 0
146    $eax = COPY killed %0, debug-location !19
147    RET 0, killed $eax, debug-location !19
148
149...
150