1# RUN: llc %s -o - -mtriple=x86_64-unknown-unknown \ 2# RUN: -experimental-debug-variable-locations \ 3# RUN: -start-before=phi-node-elimination \ 4# RUN: -stop-after=register-coalescer \ 5# RUN: | FileCheck %s --check-prefix=DOESCOALESCE 6# RUN: llc %s -o - -mtriple=x86_64-unknown-unknown \ 7# RUN: -experimental-debug-variable-locations \ 8# RUN: -start-before=phi-node-elimination \ 9# RUN: -stop-after=virtregrewriter \ 10# RUN: | FileCheck %s --check-prefix=CHECK 11# 12# This is a sibling-test for phi-coalescing.mir, using similar code but where 13# registers are coalesced across subregisters. Specifically, vreg %2 below is 14# a 16-bit register, but will be coalesced into the lower 16 bits of a 32 bit 15# vreg during coalescing. We should survive this transformation, and emit a 16# DBG_PHI for $bx where the PHI was. 17--- | 18 ; ModuleID = 'promoted.ll' 19 source_filename = "test.c" 20 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 21 target triple = "x86_64-unknown-linux-gnu" 22 23 ; Function Attrs: noinline nounwind uwtable 24 define dso_local i32 @foo(i16 signext %bar, i16 signext %baz) !dbg !7 { 25 entry: 26 call void @llvm.dbg.value(metadata i16 %bar, metadata !12, metadata !DIExpression()), !dbg !13 27 call void @llvm.dbg.value(metadata i16 %baz, metadata !14, metadata !DIExpression()), !dbg !13 28 call void @ext(i16 signext %bar), !dbg !13 29 %conv = sext i16 %bar to i32, !dbg !13 30 %add = add nsw i32 %conv, 12, !dbg !13 31 %conv1 = trunc i32 %add to i16, !dbg !13 32 call void @llvm.dbg.value(metadata i16 %conv1, metadata !12, metadata !DIExpression()), !dbg !13 33 call void @ext(i16 signext %conv1), !dbg !13 34 %call = call signext i16 @getlong(), !dbg !13 35 %tobool = icmp ne i16 %call, 0, !dbg !13 36 br i1 %tobool, label %if.then, label %if.end, !dbg !13 37 38 if.then: ; preds = %entry 39 %conv2 = sext i16 %conv1 to i32, !dbg !13 40 %add3 = add nsw i32 %conv2, 1, !dbg !13 41 %conv4 = trunc i32 %add3 to i16, !dbg !13 42 call void @llvm.dbg.value(metadata i16 %conv4, metadata !12, metadata !DIExpression()), !dbg !13 43 br label %if.end, !dbg !13 44 45 if.end: ; preds = %if.then, %entry 46 %bar.addr.0 = phi i16 [ %conv4, %if.then ], [ %conv1, %entry ], !dbg !13 47 call void @llvm.dbg.value(metadata i16 %bar.addr.0, metadata !12, metadata !DIExpression()), !dbg !13 48 %conv5 = sext i16 %baz to i32, !dbg !13 49 %conv6 = sext i16 %bar.addr.0 to i32, !dbg !13 50 %add7 = add nsw i32 %conv6, %conv5, !dbg !13 51 %conv8 = trunc i32 %add7 to i16, !dbg !13 52 call void @llvm.dbg.value(metadata i16 %conv8, metadata !12, metadata !DIExpression()), !dbg !13 53 call void @ext(i16 signext %conv8), !dbg !13 54 %conv9 = sext i16 %conv8 to i32, !dbg !13 55 ret i32 %conv9, !dbg !13 56 } 57 58 ; Function Attrs: nounwind readnone speculatable willreturn 59 declare void @llvm.dbg.declare(metadata, metadata, metadata) 60 61 declare dso_local void @ext(i16 signext) 62 63 declare dso_local signext i16 @getlong() 64 65 ; Function Attrs: nounwind readnone speculatable willreturn 66 declare void @llvm.dbg.value(metadata, metadata, metadata) 67 68 !llvm.dbg.cu = !{!0} 69 !llvm.module.flags = !{!3, !4, !5} 70 !llvm.ident = !{!6} 71 72 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 12.0.0 (git@github.com:llvm/llvm-project 79a35789efdf2378f97642ae4a5f3099b9087a11)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None) 73 !1 = !DIFile(filename: "test.c", directory: "/fast/fs/llvm3/llvm/test/DebugInfo/MIR/InstrRef") 74 !2 = !{} 75 !3 = !{i32 7, !"Dwarf Version", i32 4} 76 !4 = !{i32 2, !"Debug Info Version", i32 3} 77 !5 = !{i32 1, !"wchar_size", i32 4} 78 !6 = !{!"clang version 12.0.0 (git@github.com:llvm/llvm-project 79a35789efdf2378f97642ae4a5f3099b9087a11)"} 79 !7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !8, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) 80 !8 = !DISubroutineType(types: !9) 81 !9 = !{!10, !11, !11} 82 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 83 !11 = !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed) 84 !12 = !DILocalVariable(name: "bar", arg: 1, scope: !7, file: !1, line: 3, type: !11) 85 !13 = !DILocation(line: 0, scope: !7) 86 !14 = !DILocalVariable(name: "baz", arg: 2, scope: !7, file: !1, line: 3, type: !11) 87 !15 = distinct !DILexicalBlock(scope: !7, file: !1, line: 8, column: 7) 88 89... 90--- 91name: foo 92alignment: 16 93tracksRegLiveness: true 94debugInstrRef: true 95liveins: 96 - { reg: '$edi', virtual-reg: '%3' } 97 - { reg: '$esi', virtual-reg: '%4' } 98frameInfo: 99 maxAlignment: 1 100 adjustsStack: true 101 hasCalls: true 102machineFunctionInfo: {} 103body: | 104 bb.0.entry: 105 liveins: $edi, $esi 106 107 %4:gr32 = COPY $esi 108 %3:gr32 = COPY $edi 109 %6:gr16 = COPY %4.sub_16bit 110 %5:gr16 = COPY %3.sub_16bit 111 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13 112 %15:gr32 = MOVSX32rr16 %5, debug-location !13 113 $edi = COPY %15, debug-location !13 114 CALL64pcrel32 @ext, csr_64, implicit $rsp, implicit $ssp, implicit $edi, debug-location !13 115 ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13 116 %14:gr32 = MOVSX32rr16 %5, debug-location !13 117 %13:gr32 = ADD32ri8 killed %14, 12, implicit-def $eflags, debug-location !13 118 %11:gr16 = COPY killed %13.sub_16bit, debug-location !13 119 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13 120 %9:gr32 = MOVSX32rr16 %11, debug-location !13 121 $edi = COPY %9, debug-location !13 122 CALL64pcrel32 @ext, csr_64, implicit $rsp, implicit $ssp, implicit $edi, debug-location !13 123 ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, 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 CALL64pcrel32 @getlong, csr_64, implicit $rsp, implicit $ssp, implicit-def $ax, debug-location !13 126 ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13 127 %8:gr16 = COPY $ax, debug-location !13 128 CMP16ri8 %8, 0, implicit-def $eflags, debug-location !13 129 JCC_1 %bb.2, 4, implicit $eflags, debug-location !13 130 131 ; DOESCOALESCE-LABEL: bb.1.if.then: 132 ; CHECK-LABEL: bb.1.if.then: 133 bb.1.if.then: 134 %20:gr32 = MOVSX32rr16 %11, debug-location !13 135 %19:gr32 = ADD32ri8 killed %20, 1, implicit-def $eflags, debug-location !13 136 %17:gr16 = COPY killed %19.sub_16bit, debug-location !13 137 138 ; Verify that vreg 17 is coalesced into a gr32, and not copied any further. 139 ; DOESCOALESCE: %{{[0-9]+}}:gr32 = ADD32ri8 140 ; DOESCOALESCE-NOT: COPY 141 ; Verify those registers land in $bx 142 ; CHECK: renamable $ebp = ADD32ri8 143 144 ; DOESCOALESCE-LABEL: bb.2.if.end: 145 ; CHECK-LABEL: bb.2.if.end: 146 bb.2.if.end: 147 %2:gr16 = PHI %11, %bb.0, %17, %bb.1, debug-instr-number 1, debug-location !13 148 ; CHECK: DBG_PHI $bp, 1 149 DBG_INSTR_REF !12, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location !13 150 %31:gr32 = MOVSX32rr16 %6, debug-location !13 151 %30:gr32 = MOVSX32rr16 killed %2, debug-location !13 152 %29:gr32 = ADD32rr killed %30, killed %31, implicit-def $eflags, debug-location !13 153 %26:gr16 = COPY killed %29.sub_16bit, debug-location !13 154 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13 155 %24:gr32 = MOVSX32rr16 %26, debug-location !13 156 $edi = COPY %24, debug-location !13 157 CALL64pcrel32 @ext, csr_64, implicit $rsp, implicit $ssp, implicit $edi, debug-location !13 158 ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp, debug-location !13 159 %23:gr32 = MOVSX32rr16 %26, debug-location !13 160 $eax = COPY %23, debug-location !13 161 RET64 implicit $eax, debug-location !13 162 163... 164