1 # RUN: llc %s -o - -mtriple=x86_64-unknown-unknown \
2 # RUN: -experimental-debug-variable-locations \
3 # RUN: -run-pass=phi-node-elimination,register-coalescer \
4 # RUN: | FileCheck %s --check-prefix=DOESCOALESCE
5 # RUN: llc %s -o - -mtriple=x86_64-unknown-unknown \
6 # RUN: -experimental-debug-variable-locations \
7 # RUN: -run-pass=phi-node-elimination,register-coalescer,livedebugvars,greedy,virtregrewriter \
8 # RUN: | FileCheck %s --check-prefix=CHECK
10 # Test that a PHI with a debug instruction number attached survives register
11 # coalescing, when its vreg gets coalesced. This test comes in two parts, first
12 # that coalescing actually happens, second that a DBG_PHI is still produced
15 # Original C code, the PHI is of the value of 'bar' after the control flow.
16 # Compiled at -O0, applied -mem2reg, llc -O0, then manually added the PHI
17 # instruction label. Additional variable locations removed.
21 # int foo(long bar, long baz) {
35 ; ModuleID = 'promoted.ll'
36 source_filename = "test.c"
37 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
38 target triple = "x86_64-unknown-linux-gnu"
40 define dso_local i32 @foo(i64 %bar, i64 %baz) !dbg !7 {
42 call void @llvm.dbg.value(metadata i64 %bar, metadata !12, metadata !DIExpression()), !dbg !13
43 call void @llvm.dbg.value(metadata i64 %baz, metadata !14, metadata !DIExpression()), !dbg !13
44 call void @ext(i64 %bar), !dbg !13
45 %add = add nsw i64 %bar, 12, !dbg !13
46 call void @llvm.dbg.value(metadata i64 %add, metadata !12, metadata !DIExpression()), !dbg !13
47 call void @ext(i64 %add), !dbg !13
48 %call = call i64 @getlong(), !dbg !13
49 %tobool = icmp ne i64 %call, 0, !dbg !13
50 br i1 %tobool, label %if.then, label %if.end, !dbg !13
52 if.then: ; preds = %entry
53 %add1 = add nsw i64 %add, 1, !dbg !13
54 call void @llvm.dbg.value(metadata i64 %add1, metadata !12, metadata !DIExpression()), !dbg !13
55 br label %if.end, !dbg !13
57 if.end: ; preds = %if.then, %entry
58 %bar.addr.0 = phi i64 [ %add1, %if.then ], [ %add, %entry ], !dbg !13
59 call void @llvm.dbg.value(metadata i64 %bar.addr.0, metadata !12, metadata !DIExpression()), !dbg !13
60 %add2 = add nsw i64 %bar.addr.0, %baz, !dbg !13
61 call void @llvm.dbg.value(metadata i64 %add2, metadata !12, metadata !DIExpression()), !dbg !13
62 call void @ext(i64 %add2), !dbg !13
63 %conv = trunc i64 %add2 to i32, !dbg !13
64 ret i32 %conv, !dbg !13
67 ; Function Attrs: nounwind readnone speculatable willreturn
68 declare void @llvm.dbg.declare(metadata, metadata, metadata)
70 declare dso_local void @ext(i64)
72 declare dso_local i64 @getlong()
74 ; Function Attrs: nounwind readnone speculatable willreturn
75 declare void @llvm.dbg.value(metadata, metadata, metadata)
78 !llvm.module.flags = !{!3, !4, !5}
81 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
82 !1 = !DIFile(filename: "test.c", directory: "/tmp/out.c")
84 !3 = !{i32 7, !"Dwarf Version", i32 4}
85 !4 = !{i32 2, !"Debug Info Version", i32 3}
86 !5 = !{i32 1, !"wchar_size", i32 4}
88 !7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !8, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
89 !8 = !DISubroutineType(types: !9)
91 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
92 !11 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)
93 !12 = !DILocalVariable(name: "bar", arg: 1, scope: !7, file: !1, line: 3, type: !11)
94 !13 = !DILocation(line: 0, scope: !7)
95 !14 = !DILocalVariable(name: "baz", arg: 2, scope: !7, file: !1, line: 3, type: !11)
96 !15 = distinct !DILexicalBlock(scope: !7, file: !1, line: 8, column: 7)
102 tracksRegLiveness: true
105 - { reg: '$rdi', virtual-reg: '%3' }
106 - { reg: '$rsi', virtual-reg: '%5' }
110 machineFunctionInfo: {}
117 %4:gr64 = COPY killed %3
118 %6:gr64 = COPY killed %5
119 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13
120 $rdi = COPY %4, debug-location !13
121 CALL64pcrel32 @ext, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, debug-location !13
122 ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13
123 %9:gr64 = ADD64ri32 %4, 12, implicit-def $eflags, debug-location !13
124 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13
125 $rdi = COPY %9, debug-location !13
126 CALL64pcrel32 @ext, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, debug-location !13
127 ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13
128 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13
129 CALL64pcrel32 @getlong, csr_64, implicit $rsp, implicit $ssp, implicit-def $rax, debug-location !13
130 ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13
131 %8:gr64 = COPY $rax, debug-location !13
132 CMP64ri8 %8, 0, implicit-def $eflags, debug-location !13
133 JCC_1 %bb.2, 4, implicit $eflags, debug-location !13
135 ; DOESCOALESCE-LABEL: bb.1.if.then:
136 ; CHECK-LABEL: bb.1.if.then:
138 %10:gr64 = ADD64ri32 %9, 1, implicit-def $eflags, debug-location !13
140 ; Verify that the vreg is different immediately after register coalescing.
141 ; DOESCOALESCE-NOT: %10:gr64 ADD64ri32
142 ; DOESCOALESCE: %{{[0-9]+}}:gr64_with_sub_8bit = ADD64ri32
143 ; Verify that all these registers land in r14.
144 ; CHECK: renamable $r14 = ADD64ri32 killed renamable $r14
146 ; DOESCOALESCE-LABEL: bb.2.if.end:
147 ; CHECK-LABEL: bb.2.if.end:
149 %2:gr64 = PHI %9, %bb.0, %10, %bb.1, debug-instr-number 1, debug-location !13
150 ; CHECK: DBG_PHI $r14, 1
151 DBG_INSTR_REF !12, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location !13
152 %2:gr64 = ADD64rr killed %2, %6, implicit-def $eflags, debug-location !13
153 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13
154 $rdi = COPY %2, debug-location !13
155 CALL64pcrel32 @ext, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, debug-location !13
156 ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13
157 %13:gr32 = COPY %2.sub_32bit, debug-location !13
158 $eax = COPY %13, debug-location !13
159 RET64 implicit $eax, debug-location !13