<div dir="ltr">This looks like result of the patch<div><a href="https://lab.llvm.org/buildbot/#/builders/5/builds/22712/steps/15/logs/stdio" target="_blank">https://lab.llvm.org/buildbot/#/builders/5/builds/22712/steps/15/logs/stdio</a><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 25 Apr 2022 at 07:50, Jeremy Morse via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Author: Jeremy Morse<br>
Date: 2022-04-25T15:50:15+01:00<br>
New Revision: 5db925023169f8a19419e68153682d1e518f8392<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/5db925023169f8a19419e68153682d1e518f8392" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/5db925023169f8a19419e68153682d1e518f8392</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/5db925023169f8a19419e68153682d1e518f8392.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/5db925023169f8a19419e68153682d1e518f8392.diff</a><br>
<br>
LOG: Reapply D124184, [DebugInfo][InstrRef] Add a size operand to DBG_PHI<br>
<br>
This was applied in fda4305e53784, reverted in 13815e8cbf8d49, the problem<br>
was that fp80 X86 registers that were spilt to the stack aren't expected by<br>
LiveDebugValues. It pre-allocates a position number for all register sizes<br>
that can be spilt, and 80 bits isn't exactly common.<br>
<br>
The solution is to scan the register classes to find any unrecognised<br>
register sizes, adn pre-allocate those position numbers, avoiding a later<br>
assertion.<br>
<br>
Added: <br>
    llvm/test/DebugInfo/MIR/InstrRef/dbg-phis-in-ldv2.mir<br>
    llvm/test/DebugInfo/MIR/InstrRef/phi-on-stack-coalesced.mir<br>
    llvm/test/DebugInfo/MIR/InstrRef/phi-on-stack-coalesced2.mir<br>
<br>
Modified: <br>
    llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp<br>
    llvm/lib/CodeGen/LiveDebugVariables.cpp<br>
    llvm/test/DebugInfo/MIR/InstrRef/phi-regallocd-to-stack.mir<br>
    llvm/unittests/CodeGen/InstrRefLDVTest.cpp<br>
<br>
Removed: <br>
<br>
<br>
<br>
################################################################################<br>
diff  --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp<br>
index 74f6e6e8fbe7b..ab1fb3f743ea8 100644<br>
--- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp<br>
+++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp<br>
@@ -722,6 +722,20 @@ MLocTracker::MLocTracker(MachineFunction &MF, const TargetInstrInfo &TII,<br>
     StackSlotIdxes.insert({{Size, Offs}, Idx});<br>
   }<br>
<br>
+  // There may also be strange register class sizes (think x86 fp80s).<br>
+  for (const TargetRegisterClass *RC : TRI.regclasses()) {<br>
+    unsigned Size = TRI.getRegSizeInBits(*RC);<br>
+<br>
+    // We might see special reserved values as sizes, and classes for other<br>
+    // stuff the machine tries to model. If it's more than 512 bits, then it<br>
+    // is very unlikely to be a register than can be spilt.<br>
+    if (Size > 512)<br>
+      continue;<br>
+<br>
+    unsigned Idx = StackSlotIdxes.size();<br>
+    StackSlotIdxes.insert({{Size, 0}, Idx});<br>
+  }<br>
+<br>
   for (auto &Idx : StackSlotIdxes)<br>
     StackIdxesToPos[Idx.second] = Idx.first;<br>
<br>
@@ -1293,41 +1307,16 @@ bool InstrRefBasedLDV::transferDebugPHI(MachineInstr &MI) {<br>
     if (!SpillNo)<br>
       return EmitBadPHI();<br>
<br>
-    // Problem: what value should we extract from the stack? LLVM does not<br>
-    // record what size the last store to the slot was, and it would become<br>
-    // sketchy after stack slot colouring anyway. Take a look at what values<br>
-    // are stored on the stack, and pick the largest one that wasn't def'd<br>
-    // by a spill (i.e., the value most likely to have been def'd in a register<br>
-    // and then spilt.<br>
-    std::array<unsigned, 4> CandidateSizes = {64, 32, 16, 8};<br>
-    Optional<ValueIDNum> Result = None;<br>
-    Optional<LocIdx> SpillLoc = None;<br>
-    for (unsigned CS : CandidateSizes) {<br>
-      unsigned SpillID = MTracker->getLocID(*SpillNo, {CS, 0});<br>
-      SpillLoc = MTracker->getSpillMLoc(SpillID);<br>
-      ValueIDNum Val = MTracker->readMLoc(*SpillLoc);<br>
-      // If this value was defined in it's own position, then it was probably<br>
-      // an aliasing index of a small value that was spilt.<br>
-      if (Val.getLoc() != SpillLoc->asU64()) {<br>
-        Result = Val;<br>
-        break;<br>
-      }<br>
-    }<br>
+    // Any stack location DBG_PHI should have an associate bit-size.<br>
+    assert(MI.getNumOperands() == 3 && "Stack DBG_PHI with no size?");<br>
+    unsigned slotBitSize = MI.getOperand(2).getImm();<br>
<br>
-    // If we didn't find anything, we're probably looking at a PHI, or a memory<br>
-    // store folded into an instruction. FIXME: Take a guess that's it's 64<br>
-    // bits. This isn't ideal, but tracking the size that the spill is<br>
-    // "supposed" to be is more complex, and benefits a small number of<br>
-    // locations.<br>
-    if (!Result) {<br>
-      unsigned SpillID = MTracker->getLocID(*SpillNo, {64, 0});<br>
-      SpillLoc = MTracker->getSpillMLoc(SpillID);<br>
-      Result = MTracker->readMLoc(*SpillLoc);<br>
-    }<br>
+    unsigned SpillID = MTracker->getLocID(*SpillNo, {slotBitSize, 0});<br>
+    LocIdx SpillLoc = MTracker->getSpillMLoc(SpillID);<br>
+    ValueIDNum Result = MTracker->readMLoc(SpillLoc);<br>
<br>
     // Record this DBG_PHI for later analysis.<br>
-    auto DbgPHI =<br>
-        DebugPHIRecord({InstrNum, MI.getParent(), *Result, *SpillLoc});<br>
+    auto DbgPHI = DebugPHIRecord({InstrNum, MI.getParent(), Result, SpillLoc});<br>
     DebugPHINumToValue.push_back(DbgPHI);<br>
   } else {<br>
     // Else: if the operand is neither a legal register or a stack slot, then<br>
<br>
diff  --git a/llvm/lib/CodeGen/LiveDebugVariables.cpp b/llvm/lib/CodeGen/LiveDebugVariables.cpp<br>
index ce350b78d7534..320e68241e4ef 100644<br>
--- a/llvm/lib/CodeGen/LiveDebugVariables.cpp<br>
+++ b/llvm/lib/CodeGen/LiveDebugVariables.cpp<br>
@@ -1850,16 +1850,33 @@ void LDVImpl::emitDebugValues(VirtRegMap *VRM) {<br>
       const TargetRegisterClass *TRC = MRI.getRegClass(Reg);<br>
       unsigned SpillSize, SpillOffset;<br>
<br>
-      // Test whether this location is legal with the given subreg.<br>
+      unsigned regSizeInBits = TRI->getRegSizeInBits(*TRC);<br>
+      if (SubReg)<br>
+        regSizeInBits = TRI->getSubRegIdxSize(SubReg);<br>
+<br>
+      // Test whether this location is legal with the given subreg. If the<br>
+      // subregister has a nonzero offset, drop this location, it's too complex<br>
+      // to describe. (TODO: future work).<br>
       bool Success =<br>
           TII->getStackSlotRange(TRC, SubReg, SpillSize, SpillOffset, *MF);<br>
<br>
-      if (Success) {<br>
+      if (Success && SpillOffset == 0) {<br>
         auto Builder = BuildMI(*OrigMBB, OrigMBB->begin(), DebugLoc(),<br>
                                TII->get(TargetOpcode::DBG_PHI));<br>
         Builder.addFrameIndex(VRM->getStackSlot(Reg));<br>
         Builder.addImm(InstNum);<br>
+        // Record how large the original value is. The stack slot might be<br>
+        // merged and altered during optimisation, but we will want to know how<br>
+        // large the value is, at this DBG_PHI.<br>
+        Builder.addImm(regSizeInBits);<br>
+      }<br>
+<br>
+      LLVM_DEBUG(<br>
+      if (SpillOffset != 0) {<br>
+        dbgs() << "DBG_PHI for Vreg " << Reg << " subreg " << SubReg <<<br>
+                  " has nonzero offset\n";<br>
       }<br>
+      );<br>
     }<br>
     // If there was no mapping for a value ID, it's optimized out. Create no<br>
     // DBG_PHI, and any variables using this value will become optimized out.<br>
<br>
diff  --git a/llvm/test/DebugInfo/MIR/InstrRef/dbg-phis-in-ldv2.mir b/llvm/test/DebugInfo/MIR/InstrRef/dbg-phis-in-ldv2.mir<br>
new file mode 100644<br>
index 0000000000000..ac42364ae22f5<br>
--- /dev/null<br>
+++ b/llvm/test/DebugInfo/MIR/InstrRef/dbg-phis-in-ldv2.mir<br>
@@ -0,0 +1,128 @@<br>
+# RUN: llc %s -o - -mtriple=x86_64-unknown-unknown \<br>
+# RUN:    -experimental-debug-variable-locations -run-pass=livedebugvalues\<br>
+# RUN:    | FileCheck %s<br>
+#<br>
+# Test that a DBG_INSTR_REF that refers to a DBG_PHI, will be translated into a<br>
+# DBG_VALUE of the value read at that DBG_PHI -- in this test, when the value<br>
+# is on the stack.<br>
+# <br>
+--- |<br>
+  target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"<br>
+  target triple = "x86_64-unknown-linux-gnu"<br>
+  <br>
+  define dso_local i32 @foo(i64 %bar, i64 %baz) !dbg !7 {<br>
+    ret i32 0<br>
+  }<br>
+  <br>
+  declare dso_local void @ext(i64)<br>
+  <br>
+  declare dso_local i64 @getlong()<br>
+  <br>
+  !<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!0}<br>
+  !llvm.module.flags = !{!3, !4, !5}<br>
+  !llvm.ident = !{!6}<br>
+  <br>
+  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)<br>
+  !1 = !DIFile(filename: "test.c", directory: "/tmp/out.c")<br>
+  !2 = !{}<br>
+  !3 = !{i32 7, !"Dwarf Version", i32 4}<br>
+  !4 = !{i32 2, !"Debug Info Version", i32 3}<br>
+  !5 = !{i32 1, !"wchar_size", i32 4}<br>
+  !6 = !{!""}<br>
+  !7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !8, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)<br>
+  !8 = !DISubroutineType(types: !9)<br>
+  !9 = !{!10, !11, !11}<br>
+  !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)<br>
+  !11 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)<br>
+  !12 = !DILocalVariable(name: "bar", arg: 1, scope: !7, file: !1, line: 3, type: !11)<br>
+  !13 = !DILocation(line: 0, scope: !7)<br>
+  !14 = !DILocalVariable(name: "baz", arg: 2, scope: !7, file: !1, line: 3, type: !11)<br>
+  !19 = distinct !DILexicalBlock(scope: !7, file: !1, line: 8, column: 7)<br>
+  !26 = !DILocation(line: 13, column: 3, scope: !7)<br>
+<br>
+...<br>
+---<br>
+name:            foo<br>
+alignment:       16<br>
+tracksRegLiveness: true<br>
+liveins:<br>
+  - { reg: '$rdi' }<br>
+  - { reg: '$rsi' }<br>
+frameInfo:<br>
+  stackSize:       24<br>
+  offsetAdjustment: -24<br>
+  maxAlignment:    1<br>
+  adjustsStack:    true<br>
+  hasCalls:        true<br>
+  maxCallFrameSize: 0<br>
+  cvBytesOfCalleeSavedRegisters: 16<br>
+fixedStack:<br>
+  - { id: 0, type: spill-slot, offset: -24, size: 8, alignment: 8, callee-saved-register: '$rbx' }<br>
+  - { id: 1, type: spill-slot, offset: -16, size: 8, alignment: 16, callee-saved-register: '$r14' }<br>
+machineFunctionInfo: {}<br>
+stack:<br>
+  - { id: 0, name: '', type: spill-slot, offset: 0, size: 8, alignment: 8,<br>
+      stack-id: default, callee-saved-register: '', callee-saved-restored: true,<br>
+      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }<br>
+<br>
+body:             |<br>
+  bb.0:<br>
+    liveins: $rdi, $rsi, $r14, $rbx<br>
+    ; CHECK-LABEL: bb.0:<br>
+  <br>
+    $r14 = MOV64rr $rsi<br>
+    $rbx = MOV64rr $rdi<br>
+    $rax = MOV64ri 0<br>
+    MOV64mr $rsp, 1, $noreg, 16, $noreg, $rax :: (store 8 into %stack.0)<br>
+    $rax = MOV64ri 0<br>
+<br>
+    ;; A DBG_PHI of the stack should resolve to the stack location.<br>
+    DBG_PHI %stack.0, 1, 64<br>
+<br>
+    ;; Reload value, clobber stack location.<br>
+    $rcx = MOV64rm $rsp, 1, $noreg, 8, $noreg :: (load 8 from %stack.0)<br>
+    MOV64mr $rsp, 1, $noreg, 16, $noreg, $rax :: (store 8 into %stack.0)<br>
+<br>
+    ;; This should resolve to the loaded register.<br>
+    DBG_INSTR_REF 1, 0, !12, !DIExpression(), debug-location !13<br>
+    ; CHECK:      DBG_INSTR_REF 1, 0,<br>
+    ; CHECK-NEXT: DBG_VALUE $rcx<br>
+<br>
+    ;; And if we say it's a smaller size, we should be able to pick out smaller<br>
+    ;; subregisters within the stack slot.<br>
+    DBG_PHI %stack.0, 2, 32<br>
+    $rax = MOV64ri 0<br>
+    $rcx = MOV64rm $rsp, 1, $noreg, 8, $noreg :: (load 8 from %stack.0)<br>
+    MOV64mr $rsp, 1, $noreg, 16, $noreg, $rax :: (store 8 into %stack.0)<br>
+<br>
+    ;; This should pick out the 32 bit value.<br>
+    DBG_INSTR_REF 2, 0, !12, !DIExpression(), debug-location !13<br>
+    ; CHECK:      DBG_INSTR_REF 2, 0,<br>
+    ; CHECK-NEXT: DBG_VALUE $ecx<br>
+<br>
+    ;; Try all the other subregs.<br>
+    DBG_PHI %stack.0, 3, 16<br>
+    $rax = MOV64ri 0<br>
+    $rcx = MOV64rm $rsp, 1, $noreg, 8, $noreg :: (load 8 from %stack.0)<br>
+    MOV64mr $rsp, 1, $noreg, 16, $noreg, $rax :: (store 8 into %stack.0)<br>
+<br>
+    DBG_INSTR_REF 3, 0, !12, !DIExpression(), debug-location !13<br>
+    ; CHECK:      DBG_INSTR_REF 3, 0,<br>
+    ; CHECK-NEXT: DBG_VALUE $cx<br>
+<br>
+    DBG_PHI %stack.0, 4, 8<br>
+    $rax = MOV64ri 0<br>
+    $rcx = MOV64rm $rsp, 1, $noreg, 8, $noreg :: (load 8 from %stack.0)<br>
+    MOV64mr $rsp, 1, $noreg, 16, $noreg, $rax :: (store 8 into %stack.0)<br>
+<br>
+    DBG_INSTR_REF 4, 0, !12, !DIExpression(), debug-location !13<br>
+    ; CHECK:      DBG_INSTR_REF 4, 0,<br>
+    ; CHECK-NEXT: DBG_VALUE $cl<br>
+<br>
+    ;; We can't, at this time, describe subregister fields with nonzero offset.<br>
+    ;; It's easily achieved by attaching more data to stack DBG_PHIs, but it's<br>
+    ;; not clear that LLVM will ever merge registers to generate such locations.<br>
+<br>
+    RET64 implicit $eax, debug-location !26<br>
+<br>
+...<br>
<br>
diff  --git a/llvm/test/DebugInfo/MIR/InstrRef/phi-on-stack-coalesced.mir b/llvm/test/DebugInfo/MIR/InstrRef/phi-on-stack-coalesced.mir<br>
new file mode 100644<br>
index 0000000000000..a0b6d796ce64c<br>
--- /dev/null<br>
+++ b/llvm/test/DebugInfo/MIR/InstrRef/phi-on-stack-coalesced.mir<br>
@@ -0,0 +1,156 @@<br>
+# RUN: llc %s -o - -mtriple=x86_64-unknown-unknown \<br>
+# RUN:    -experimental-debug-variable-locations \<br>
+# RUN:    -start-before=phi-node-elimination -stop-after=virtregrewriter \<br>
+# RUN:    | FileCheck %s<br>
+#<br>
+# Like phi-through-regalloc.mir, pass a PHI node into register allocation, and<br>
+# test that it correctly comes out, in a stack slot. In this test the desired<br>
+# value is a 16 bit copy of an argument, and the PHI register class is 16 bits.<br>
+# It's subsequently coalesced into a larger vreg, which is then spilt as a 32<br>
+# bit value.<br>
+# Test that the coalescing happens (32 bits stored and loaded), but that we<br>
+# record in the relevant DBG_PHI that the original value was 16 bits in size.<br>
+# This avoids later ambiguity about how large the value on the stack is.<br>
+<br>
+--- |<br>
+  ; ModuleID = 'promoted.ll'<br>
+  source_filename = "test.c"<br>
+  target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"<br>
+  target triple = "x86_64-unknown-linux-gnu"<br>
+<br>
+  define dso_local i32 @foo(i32 %bar, i32 %baz) !dbg !7 {<br>
+  entry:<br>
+    ret i32 0, !dbg !19<br>
+  }<br>
+<br>
+  declare dso_local i32 @ext(i32)<br>
+<br>
+  ; Function Attrs: nounwind readnone speculatable willreturn<br>
+  declare void @llvm.dbg.value(metadata, metadata, metadata)<br>
+<br>
+  !<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!0}<br>
+  !llvm.module.flags = !{!3, !4, !5}<br>
+  !llvm.ident = !{!6}<br>
+<br>
+  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)<br>
+  !1 = !DIFile(filename: "test.c", directory: ".")<br>
+  !2 = !{}<br>
+  !3 = !{i32 7, !"Dwarf Version", i32 4}<br>
+  !4 = !{i32 2, !"Debug Info Version", i32 3}<br>
+  !5 = !{i32 1, !"wchar_size", i32 4}<br>
+  !6 = !{!"."}<br>
+  !7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)<br>
+  !8 = !DISubroutineType(types: !9)<br>
+  !9 = !{!10, !10, !10}<br>
+  !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)<br>
+  !11 = !DILocalVariable(name: "bar", arg: 1, scope: !7, file: !1, line: 2, type: !10)<br>
+  !12 = !DILocation(line: 0, scope: !7)<br>
+  !13 = !DILocalVariable(name: "baz", arg: 2, scope: !7, file: !1, line: 2, type: !10)<br>
+  !14 = !DILocalVariable(name: "either", scope: !7, file: !1, line: 3, type: !10)<br>
+  !15 = !DILocation(line: 4, column: 7, scope: !16)<br>
+  !16 = distinct !DILexicalBlock(scope: !7, file: !1, line: 4, column: 7)<br>
+  !17 = !DILocation(line: 4, column: 7, scope: !7)<br>
+  !18 = !DILocation(line: 0, scope: !16)<br>
+  !19 = !DILocation(line: 9, column: 3, scope: !7)<br>
+<br>
+...<br>
+---<br>
+name:            foo<br>
+alignment:       16<br>
+tracksRegLiveness: true<br>
+registers:<br>
+  - { id: 0, class: gr16 }<br>
+  - { id: 1, class: gr32 }<br>
+  - { id: 2, class: gr32 }<br>
+  - { id: 3, class: gr32 }<br>
+  - { id: 4, class: gr32 }<br>
+liveins:<br>
+  - { reg: '$edi', virtual-reg: '%1' }<br>
+  - { reg: '$esi', virtual-reg: '%2' }<br>
+frameInfo:<br>
+  maxAlignment:    1<br>
+  hasCalls:        true<br>
+machineFunctionInfo: {}<br>
+body:             |<br>
+  ; CHECK-LABEL: bb.0:<br>
+  ; CHECK:       MOV32mr %stack.0, 1, $noreg, 0, $noreg, $edi<br>
+  bb.0:<br>
+    successors: %bb.2(0x50000000), %bb.1(0x30000000)<br>
+    liveins: $edi, $esi<br>
+<br>
+    DBG_VALUE $edi, $noreg, !11, !DIExpression(), debug-location !12<br>
+    DBG_VALUE $esi, $noreg, !13, !DIExpression(), debug-location !12<br>
+    %2:gr32 = COPY killed $esi<br>
+    %1:gr32 = COPY killed $edi<br>
+    %5:gr16 = COPY %1.sub_16bit<br>
+    %6:gr16 = COPY %1.sub_16bit<br>
+    ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !15<br>
+    %3:gr32 = MOV32r0 implicit-def dead $eflags<br>
+    $edi = COPY killed %3, debug-location !15<br>
+    CALL64pcrel32 @ext, csr_64, implicit $rsp, implicit $ssp, implicit killed $edi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-location !15<br>
+    ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !15<br>
+    %4:gr32 = COPY killed $eax, debug-location !15<br>
+    %10:gr32 = MOV32ri 0<br>
+    %11:gr32 = MOV32ri 1<br>
+    %12:gr32 = MOV32ri 2<br>
+    %13:gr32 = MOV32ri 3<br>
+    %14:gr32 = MOV32ri 4<br>
+    %15:gr32 = MOV32ri 5<br>
+    %16:gr32 = MOV32ri 6<br>
+    %17:gr32 = MOV32ri 7<br>
+    %18:gr32 = MOV32ri 8<br>
+    %19:gr32 = MOV32ri 9<br>
+    %20:gr32 = MOV32ri 10<br>
+    %21:gr32 = MOV32ri 11<br>
+    %22:gr32 = MOV32ri 12<br>
+    %23:gr32 = MOV32ri 13<br>
+    %24:gr32 = MOV32ri 14<br>
+    TEST32rr killed %4, %4, implicit-def $eflags, debug-location !15<br>
+    JCC_1 %bb.2, 5, implicit killed $eflags, debug-location !17<br>
+    JMP_1 %bb.1, debug-location !17<br>
+<br>
+  bb.1:<br>
+    %30:gr32 = MOV32ri 0<br>
+    %31:gr32 = MOV32ri 1<br>
+    %32:gr32 = MOV32ri 2<br>
+    %33:gr32 = MOV32ri 3<br>
+    %34:gr32 = MOV32ri 4<br>
+    %35:gr32 = MOV32ri 5<br>
+    %36:gr32 = MOV32ri 6<br>
+    %37:gr32 = MOV32ri 7<br>
+    %38:gr32 = MOV32ri 8<br>
+    %39:gr32 = MOV32ri 9<br>
+    %40:gr32 = MOV32ri 10<br>
+    %41:gr32 = MOV32ri 11<br>
+    %42:gr32 = MOV32ri 12<br>
+    %43:gr32 = MOV32ri 13<br>
+    %44:gr32 = MOV32ri 14<br>
+<br>
+    ; CHECK-LABEL: bb.2:<br>
+  bb.2:<br>
+    %0:gr16 = PHI %5, %bb.0, %6, %bb.1, debug-instr-number 1, debug-location !18<br>
+    %50:gr32 = PHI %10, %bb.0, %30, %bb.1, debug-location !18<br>
+    %51:gr32 = PHI %11, %bb.0, %31, %bb.1, debug-location !18<br>
+    %52:gr32 = PHI %12, %bb.0, %32, %bb.1, debug-location !18<br>
+    %53:gr32 = PHI %13, %bb.0, %33, %bb.1, debug-location !18<br>
+    %54:gr32 = PHI %14, %bb.0, %34, %bb.1, debug-location !18<br>
+    %55:gr32 = PHI %15, %bb.0, %35, %bb.1, debug-location !18<br>
+    %56:gr32 = PHI %16, %bb.0, %36, %bb.1, debug-location !18<br>
+    %57:gr32 = PHI %17, %bb.0, %37, %bb.1, debug-location !18<br>
+    %58:gr32 = PHI %18, %bb.0, %38, %bb.1, debug-location !18<br>
+    %59:gr32 = PHI %19, %bb.0, %39, %bb.1, debug-location !18<br>
+    %60:gr32 = PHI %20, %bb.0, %40, %bb.1, debug-location !18<br>
+    %61:gr32 = PHI %21, %bb.0, %41, %bb.1, debug-location !18<br>
+    %62:gr32 = PHI %22, %bb.0, %42, %bb.1, debug-location !18<br>
+    %63:gr32 = PHI %23, %bb.0, %43, %bb.1, debug-location !18<br>
+    %64:gr32 = PHI %24, %bb.0, %44, %bb.1, debug-location !18<br>
+<br>
+    INLINEASM &"", 1, 12, %50, 12, %51, 12, %52, 12, %53, 12, %54, 12, %55, 12, %56, 12, %57, 12, %58, 12, %59, 12, %60, 12, %61, 12, %62, 12, %63, 12, %64<br>
+    DBG_INSTR_REF 1, 0, !14, !DIExpression(), debug-location !12<br>
+    ; CHECK:      DBG_PHI %stack.0, 1, 16<br>
+    ; CHECK:      DBG_INSTR_REF 1, 0<br>
+    ; CHECK:      renamable $eax = MOV32rm %stack.0,<br>
+    $eax = COPY killed %0, debug-location !19<br>
+    RET 0, killed $eax, debug-location !19<br>
+<br>
+...<br>
<br>
diff  --git a/llvm/test/DebugInfo/MIR/InstrRef/phi-on-stack-coalesced2.mir b/llvm/test/DebugInfo/MIR/InstrRef/phi-on-stack-coalesced2.mir<br>
new file mode 100644<br>
index 0000000000000..1047c005a5ad6<br>
--- /dev/null<br>
+++ b/llvm/test/DebugInfo/MIR/InstrRef/phi-on-stack-coalesced2.mir<br>
@@ -0,0 +1,155 @@<br>
+# RUN: llc %s -o - -mtriple=x86_64-unknown-unknown \<br>
+# RUN:    -experimental-debug-variable-locations \<br>
+# RUN:    -start-before=phi-node-elimination -stop-after=virtregrewriter \<br>
+# RUN:    | FileCheck %s<br>
+#<br>
+# Pass a PHI node into register allocation, and test that it is correctly<br>
+# dropped.  In this test the desired value is an 8 bit copy of an argument,<br>
+# but it's located in an upper subregister field. That coalesces back to the<br>
+# whole argument, which is spilt to the stack.<br>
+#<br>
+# Currently, DBG_PHIs can't describe non-zero offsets in stack slots, therefore<br>
+# no DBG_PHI should be emitted. (This means there is no value for that<br>
+# instruction/operand number, and any DBG_INSTR_REF will become a<br>
+# DBG_VALUE $noreg.<br>
+<br>
+--- |<br>
+  ; ModuleID = 'promoted.ll'<br>
+  source_filename = "test.c"<br>
+  target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"<br>
+  target triple = "x86_64-unknown-linux-gnu"<br>
+<br>
+  define dso_local i32 @foo(i32 %bar, i32 %baz) !dbg !7 {<br>
+  entry:<br>
+    ret i32 0, !dbg !19<br>
+  }<br>
+<br>
+  declare dso_local i32 @ext(i32)<br>
+<br>
+  ; Function Attrs: nounwind readnone speculatable willreturn<br>
+  declare void @llvm.dbg.value(metadata, metadata, metadata)<br>
+<br>
+  !<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!0}<br>
+  !llvm.module.flags = !{!3, !4, !5}<br>
+  !llvm.ident = !{!6}<br>
+<br>
+  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)<br>
+  !1 = !DIFile(filename: "test.c", directory: ".")<br>
+  !2 = !{}<br>
+  !3 = !{i32 7, !"Dwarf Version", i32 4}<br>
+  !4 = !{i32 2, !"Debug Info Version", i32 3}<br>
+  !5 = !{i32 1, !"wchar_size", i32 4}<br>
+  !6 = !{!"."}<br>
+  !7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)<br>
+  !8 = !DISubroutineType(types: !9)<br>
+  !9 = !{!10, !10, !10}<br>
+  !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)<br>
+  !11 = !DILocalVariable(name: "bar", arg: 1, scope: !7, file: !1, line: 2, type: !10)<br>
+  !12 = !DILocation(line: 0, scope: !7)<br>
+  !13 = !DILocalVariable(name: "baz", arg: 2, scope: !7, file: !1, line: 2, type: !10)<br>
+  !14 = !DILocalVariable(name: "either", scope: !7, file: !1, line: 3, type: !10)<br>
+  !15 = !DILocation(line: 4, column: 7, scope: !16)<br>
+  !16 = distinct !DILexicalBlock(scope: !7, file: !1, line: 4, column: 7)<br>
+  !17 = !DILocation(line: 4, column: 7, scope: !7)<br>
+  !18 = !DILocation(line: 0, scope: !16)<br>
+  !19 = !DILocation(line: 9, column: 3, scope: !7)<br>
+<br>
+...<br>
+---<br>
+name:            foo<br>
+alignment:       16<br>
+tracksRegLiveness: true<br>
+registers:<br>
+  - { id: 0, class: gr8 }<br>
+  - { id: 1, class: gr32_abcd }<br>
+  - { id: 2, class: gr32_abcd }<br>
+  - { id: 3, class: gr32 }<br>
+  - { id: 4, class: gr32 }<br>
+liveins:<br>
+  - { reg: '$edi', virtual-reg: '%1' }<br>
+  - { reg: '$esi', virtual-reg: '%2' }<br>
+frameInfo:<br>
+  maxAlignment:    1<br>
+  hasCalls:        true<br>
+machineFunctionInfo: {}<br>
+body:             |<br>
+  bb.0:<br>
+    successors: %bb.2(0x50000000), %bb.1(0x30000000)<br>
+    liveins: $edi, $esi<br>
+<br>
+    DBG_VALUE $edi, $noreg, !11, !DIExpression(), debug-location !12<br>
+    DBG_VALUE $esi, $noreg, !13, !DIExpression(), debug-location !12<br>
+    %2:gr32_abcd = COPY killed $esi<br>
+    %1:gr32_abcd = COPY killed $edi<br>
+    %5:gr8 = COPY %1.sub_8bit_hi<br>
+    %6:gr8 = COPY %1.sub_8bit_hi<br>
+    ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !15<br>
+    %3:gr32 = MOV32r0 implicit-def dead $eflags<br>
+    $edi = COPY killed %3, debug-location !15<br>
+    CALL64pcrel32 @ext, csr_64, implicit $rsp, implicit $ssp, implicit killed $edi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-location !15<br>
+    ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !15<br>
+    %4:gr32 = COPY killed $eax, debug-location !15<br>
+    %10:gr32 = MOV32ri 0<br>
+    %11:gr32 = MOV32ri 1<br>
+    %12:gr32 = MOV32ri 2<br>
+    %13:gr32 = MOV32ri 3<br>
+    %14:gr32 = MOV32ri 4<br>
+    %15:gr32 = MOV32ri 5<br>
+    %16:gr32 = MOV32ri 6<br>
+    %17:gr32 = MOV32ri 7<br>
+    %18:gr32 = MOV32ri 8<br>
+    %19:gr32 = MOV32ri 9<br>
+    %20:gr32 = MOV32ri 10<br>
+    %21:gr32 = MOV32ri 11<br>
+    %22:gr32 = MOV32ri 12<br>
+    %23:gr32 = MOV32ri 13<br>
+    %24:gr32 = MOV32ri 14<br>
+    TEST32rr killed %4, %4, implicit-def $eflags, debug-location !15<br>
+    JCC_1 %bb.2, 5, implicit killed $eflags, debug-location !17<br>
+    JMP_1 %bb.1, debug-location !17<br>
+<br>
+  bb.1:<br>
+    %30:gr32 = MOV32ri 0<br>
+    %31:gr32 = MOV32ri 1<br>
+    %32:gr32 = MOV32ri 2<br>
+    %33:gr32 = MOV32ri 3<br>
+    %34:gr32 = MOV32ri 4<br>
+    %35:gr32 = MOV32ri 5<br>
+    %36:gr32 = MOV32ri 6<br>
+    %37:gr32 = MOV32ri 7<br>
+    %38:gr32 = MOV32ri 8<br>
+    %39:gr32 = MOV32ri 9<br>
+    %40:gr32 = MOV32ri 10<br>
+    %41:gr32 = MOV32ri 11<br>
+    %42:gr32 = MOV32ri 12<br>
+    %43:gr32 = MOV32ri 13<br>
+    %44:gr32 = MOV32ri 14<br>
+<br>
+    ; CHECK-LABEL: bb.2:<br>
+  bb.2:<br>
+    %0:gr8 = PHI %5, %bb.0, %6, %bb.1, debug-instr-number 1, debug-location !18<br>
+    %50:gr32 = PHI %10, %bb.0, %30, %bb.1, debug-location !18<br>
+    %51:gr32 = PHI %11, %bb.0, %31, %bb.1, debug-location !18<br>
+    %52:gr32 = PHI %12, %bb.0, %32, %bb.1, debug-location !18<br>
+    %53:gr32 = PHI %13, %bb.0, %33, %bb.1, debug-location !18<br>
+    %54:gr32 = PHI %14, %bb.0, %34, %bb.1, debug-location !18<br>
+    %55:gr32 = PHI %15, %bb.0, %35, %bb.1, debug-location !18<br>
+    %56:gr32 = PHI %16, %bb.0, %36, %bb.1, debug-location !18<br>
+    %57:gr32 = PHI %17, %bb.0, %37, %bb.1, debug-location !18<br>
+    %58:gr32 = PHI %18, %bb.0, %38, %bb.1, debug-location !18<br>
+    %59:gr32 = PHI %19, %bb.0, %39, %bb.1, debug-location !18<br>
+    %60:gr32 = PHI %20, %bb.0, %40, %bb.1, debug-location !18<br>
+    %61:gr32 = PHI %21, %bb.0, %41, %bb.1, debug-location !18<br>
+    %62:gr32 = PHI %22, %bb.0, %42, %bb.1, debug-location !18<br>
+    %63:gr32 = PHI %23, %bb.0, %43, %bb.1, debug-location !18<br>
+    %64:gr32 = PHI %24, %bb.0, %44, %bb.1, debug-location !18<br>
+<br>
+    INLINEASM &"", 1, 12, %50, 12, %51, 12, %52, 12, %53, 12, %54, 12, %55, 12, %56, 12, %57, 12, %58, 12, %59, 12, %60, 12, %61, 12, %62, 12, %63, 12, %64<br>
+    DBG_INSTR_REF 1, 0, !14, !DIExpression(), debug-location !12<br>
+    ; CHECK-NOT:  DBG_PHI<br>
+    ; CHECK:      DBG_INSTR_REF 1, 0<br>
+    ; CHECK-NOT:  DBG_PHI<br>
+    $eax = COPY killed %0, debug-location !19<br>
+    RET 0, killed $eax, debug-location !19<br>
+<br>
+...<br>
<br>
diff  --git a/llvm/test/DebugInfo/MIR/InstrRef/phi-regallocd-to-stack.mir b/llvm/test/DebugInfo/MIR/InstrRef/phi-regallocd-to-stack.mir<br>
index b40f2ae9cb6d0..f8733e1128f95 100644<br>
--- a/llvm/test/DebugInfo/MIR/InstrRef/phi-regallocd-to-stack.mir<br>
+++ b/llvm/test/DebugInfo/MIR/InstrRef/phi-regallocd-to-stack.mir<br>
@@ -140,7 +140,7 @@ body:             |<br>
     %64:gr32 = PHI %24, %bb.0, %44, %bb.1, debug-location !18<br>
<br>
     DBG_INSTR_REF 1, 0, !14, !DIExpression(), debug-location !12<br>
-    ; CHECK:      DBG_PHI %stack.1, 1<br>
+    ; CHECK:      DBG_PHI %stack.1, 1, 32<br>
     ; CHECK:      renamable $eax = MOV32rm %stack.1,<br>
     ; CHECK:      DBG_INSTR_REF 1, 0<br>
     $eax = COPY killed %0, debug-location !19<br>
<br>
diff  --git a/llvm/unittests/CodeGen/InstrRefLDVTest.cpp b/llvm/unittests/CodeGen/InstrRefLDVTest.cpp<br>
index c47c83ad65162..db9107b9b5bcd 100644<br>
--- a/llvm/unittests/CodeGen/InstrRefLDVTest.cpp<br>
+++ b/llvm/unittests/CodeGen/InstrRefLDVTest.cpp<br>
@@ -1113,9 +1113,10 @@ TEST_F(InstrRefLDVTest, MLocDiamondSpills) {<br>
   // Create a stack location and ensure it's tracked.<br>
   SpillLoc SL = {getRegByName("RSP"), StackOffset::getFixed(-8)};<br>
   SpillLocationNo SpillNo = *MTracker->getOrTrackSpillLoc(SL);<br>
-  ASSERT_EQ(MTracker->getNumLocs(), 10u); // Tracks all possible stack locs.<br>
+  ASSERT_EQ(MTracker->getNumLocs(), 11u); // Tracks all possible stack locs.<br>
   // Locations are: RSP, stack slots from 2^3 bits wide up to 2^9 for zmm regs,<br>
   // then slots for sub_8bit_hi and sub_16bit_hi ({8, 8} and {16, 16}).<br>
+  // Finally, one for spilt fp80 registers.<br>
<br>
   // Pick out the locations on the stack that various x86 regs would be written<br>
   // to. HAX is the upper 16 bits of EAX.<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>