163 lines · plain
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=DOESCOALESCE5# 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=CHECK9#10# Test that a PHI with a debug instruction number attached survives register11# coalescing, when its vreg gets coalesced. This test comes in two parts, first12# that coalescing actually happens, second that a DBG_PHI is still produced13# afterwards.14#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 PHI17# instruction label. Additional variable locations removed.18#19# void ext(long);20# long getlong(void);21# int foo(long bar, long baz) {22# ext(bar);23# bar += 12;24# ext(bar);25# 26# if (getlong())27# bar += 1;28# 29# bar += baz;30# ext(bar);31# return bar;32# }33#34--- |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"39 40 define dso_local i32 @foo(i64 %bar, i64 %baz) !dbg !7 {41 entry:42 call void @llvm.dbg.value(metadata i64 %bar, metadata !12, metadata !DIExpression()), !dbg !1343 call void @llvm.dbg.value(metadata i64 %baz, metadata !14, metadata !DIExpression()), !dbg !1344 call void @ext(i64 %bar), !dbg !1345 %add = add nsw i64 %bar, 12, !dbg !1346 call void @llvm.dbg.value(metadata i64 %add, metadata !12, metadata !DIExpression()), !dbg !1347 call void @ext(i64 %add), !dbg !1348 %call = call i64 @getlong(), !dbg !1349 %tobool = icmp ne i64 %call, 0, !dbg !1350 br i1 %tobool, label %if.then, label %if.end, !dbg !1351 52 if.then: ; preds = %entry53 %add1 = add nsw i64 %add, 1, !dbg !1354 call void @llvm.dbg.value(metadata i64 %add1, metadata !12, metadata !DIExpression()), !dbg !1355 br label %if.end, !dbg !1356 57 if.end: ; preds = %if.then, %entry58 %bar.addr.0 = phi i64 [ %add1, %if.then ], [ %add, %entry ], !dbg !1359 call void @llvm.dbg.value(metadata i64 %bar.addr.0, metadata !12, metadata !DIExpression()), !dbg !1360 %add2 = add nsw i64 %bar.addr.0, %baz, !dbg !1361 call void @llvm.dbg.value(metadata i64 %add2, metadata !12, metadata !DIExpression()), !dbg !1362 call void @ext(i64 %add2), !dbg !1363 %conv = trunc i64 %add2 to i32, !dbg !1364 ret i32 %conv, !dbg !1365 }66 67 ; Function Attrs: nounwind readnone speculatable willreturn68 declare void @llvm.dbg.declare(metadata, metadata, metadata)69 70 declare dso_local void @ext(i64)71 72 declare dso_local i64 @getlong()73 74 ; Function Attrs: nounwind readnone speculatable willreturn75 declare void @llvm.dbg.value(metadata, metadata, metadata)76 77 !llvm.dbg.cu = !{!0}78 !llvm.module.flags = !{!3, !4, !5}79 !llvm.ident = !{!6}80 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")83 !2 = !{}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}87 !6 = !{!""}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)90 !9 = !{!10, !11, !11}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)97 98...99---100name: foo101alignment: 16102tracksRegLiveness: true103debugInstrRef: true104liveins:105 - { reg: '$rdi', virtual-reg: '%3' }106 - { reg: '$rsi', virtual-reg: '%5' }107frameInfo:108 maxAlignment: 1109 adjustsStack: true110 hasCalls: true111machineFunctionInfo: {}112body: |113 bb.0.entry:114 liveins: $rdi, $rsi115 116 %5:gr64 = COPY $rsi117 %3:gr64 = COPY $rdi118 %4:gr64 = COPY killed %3119 %6:gr64 = COPY killed %5120 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13121 $rdi = COPY %4, debug-location !13122 CALL64pcrel32 @ext, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, debug-location !13123 ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13124 %9:gr64 = ADD64ri32 %4, 12, implicit-def $eflags, debug-location !13125 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13126 $rdi = COPY %9, debug-location !13127 CALL64pcrel32 @ext, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, debug-location !13128 ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13129 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13130 CALL64pcrel32 @getlong, csr_64, implicit $rsp, implicit $ssp, implicit-def $rax, debug-location !13131 ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13132 %8:gr64 = COPY $rax, debug-location !13133 CMP64ri8 %8, 0, implicit-def $eflags, debug-location !13134 JCC_1 %bb.2, 4, implicit $eflags, debug-location !13135 136 ; DOESCOALESCE-LABEL: bb.1.if.then:137 ; CHECK-LABEL: bb.1.if.then:138 bb.1.if.then:139 %10:gr64 = ADD64ri32 %9, 1, implicit-def $eflags, debug-location !13140 141 ; Verify that the vreg is different immediately after register coalescing.142 ; DOESCOALESCE-NOT: %10:gr64 ADD64ri32143 ; DOESCOALESCE: %{{[0-9]+}}:gr64_with_sub_8bit = ADD64ri32144 ; Verify that all these registers land in r14.145 ; CHECK: renamable $r14 = ADD64ri32 killed renamable $r14146 147 ; DOESCOALESCE-LABEL: bb.2.if.end:148 ; CHECK-LABEL: bb.2.if.end:149 bb.2.if.end:150 %2:gr64 = PHI %9, %bb.0, %10, %bb.1, debug-instr-number 1, debug-location !13151 ; CHECK: DBG_PHI $r14, 1152 DBG_INSTR_REF !12, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location !13153 %2:gr64 = ADD64rr killed %2, %6, implicit-def $eflags, debug-location !13154 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13155 $rdi = COPY %2, debug-location !13156 CALL64pcrel32 @ext, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, debug-location !13157 ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13158 %13:gr32 = COPY %2.sub_32bit, debug-location !13159 $eax = COPY %13, debug-location !13160 RET64 implicit $eax, debug-location !13161 162...163