1 # RUN: llc %s -o - -mtriple=x86_64-unknown-unknown \
2 # RUN: -experimental-debug-variable-locations \
3 # RUN: -run-pass=phi-node-elimination,simple-register-coalescing \
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,simple-register-coalescing,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
104 - { reg: '$rdi', virtual-reg: '%3' }
105 - { reg: '$rsi', virtual-reg: '%5' }
109 machineFunctionInfo: {}
116 %4:gr64 = COPY killed %3
117 %6:gr64 = COPY killed %5
118 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13
119 $rdi = COPY %4, debug-location !13
120 CALL64pcrel32 @ext, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, debug-location !13
121 ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13
122 %9:gr64 = ADD64ri32 %4, 12, implicit-def $eflags, debug-location !13
123 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13
124 $rdi = COPY %9, debug-location !13
125 CALL64pcrel32 @ext, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, debug-location !13
126 ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13
127 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13
128 CALL64pcrel32 @getlong, csr_64, implicit $rsp, implicit $ssp, implicit-def $rax, debug-location !13
129 ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13
130 %8:gr64 = COPY $rax, debug-location !13
131 CMP64ri8 %8, 0, implicit-def $eflags, debug-location !13
132 JCC_1 %bb.2, 4, implicit $eflags, debug-location !13
134 ; DOESCOALESCE-LABEL: bb.1.if.then:
135 ; CHECK-LABEL: bb.1.if.then:
137 %10:gr64 = ADD64ri32 %9, 1, implicit-def $eflags, debug-location !13
139 ; Verify that the vreg is different immediately after register coalescing.
140 ; DOESCOALESCE-NOT: %10:gr64 ADD64ri32
141 ; DOESCOALESCE: %{{[0-9]+}}:gr64 = ADD64ri32
142 ; Verify that all these registers land in rbx.
143 ; CHECK: renamable $rbx = ADD64ri32 killed renamable $rbx
145 ; DOESCOALESCE-LABEL: bb.2.if.end:
146 ; CHECK-LABEL: bb.2.if.end:
148 %2:gr64 = PHI %9, %bb.0, %10, %bb.1, debug-instr-number 1, debug-location !13
149 ; CHECK: DBG_PHI $rbx, 1
150 DBG_INSTR_REF 1, 0, !12, !DIExpression(), debug-location !13
151 %14:gr64 = ADD64rr killed %2, %6, implicit-def $eflags, debug-location !13
152 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13
153 $rdi = COPY %14, debug-location !13
154 CALL64pcrel32 @ext, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, debug-location !13
155 ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13
156 %13:gr32 = COPY %14.sub_32bit, debug-location !13
157 $eax = COPY %13, debug-location !13
158 RETQ implicit $eax, debug-location !13