Skip to content

Commit 80abbec

Browse files
committed
[Inline Spiller] Consider bundles when marking defs as dead
Fix bug where the code expects just a single MI, but a series of bundled MIs need to be handled instead. The semi-formed bundled are created by SplitKit for the case where not all lanes are live (buildSingleSubRegCopy). Then the remat kicks in, and since the values that are copied in the bundle do not need to be preserved due to the remat (dead defs), all instructions in the bundle should be marked as dead. However, only the first one gets marked as dead, which causes the verifier to complain later with error: "Live range continues after dead def flag". Differential Revision: https://reviews.llvm.org/D156999
1 parent 24865a6 commit 80abbec

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

llvm/lib/CodeGen/InlineSpiller.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,35 @@ void InlineSpiller::reMaterializeAll() {
753753
continue;
754754
LLVM_DEBUG(dbgs() << "All defs dead: " << *MI);
755755
DeadDefs.push_back(MI);
756+
// If MI is a bundle header, also try removing copies inside the bundle,
757+
// otherwise the verifier would complain "live range continues after dead
758+
// def flag".
759+
if (MI->isBundledWithSucc() && !MI->isBundledWithPred()) {
760+
MachineBasicBlock::instr_iterator BeginIt = MI->getIterator(),
761+
EndIt = MI->getParent()->instr_end();
762+
++BeginIt; // Skip MI that was already handled.
763+
764+
bool OnlyDeadCopies = true;
765+
for (MachineBasicBlock::instr_iterator It = BeginIt;
766+
It != EndIt && It->isBundledWithPred(); ++It) {
767+
768+
auto DestSrc = TII.isCopyInstr(*It);
769+
bool IsCopyToDeadReg =
770+
DestSrc && DestSrc->Destination->getReg() == Reg;
771+
if (!IsCopyToDeadReg) {
772+
OnlyDeadCopies = false;
773+
break;
774+
}
775+
}
776+
if (OnlyDeadCopies) {
777+
for (MachineBasicBlock::instr_iterator It = BeginIt;
778+
It != EndIt && It->isBundledWithPred(); ++It) {
779+
It->addRegisterDead(Reg, &TRI);
780+
LLVM_DEBUG(dbgs() << "All defs dead: " << *It);
781+
DeadDefs.push_back(&*It);
782+
}
783+
}
784+
}
756785
}
757786
}
758787

llvm/test/CodeGen/AMDGPU/dead_bundle.mir

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2-
# RUN: llc -mtriple=amdgcn--amdpal -march=amdgcn -mcpu=gfx1100 -verify-machineinstrs=0 -start-before=greedy,0 -stop-after=virtregrewriter,0 -stress-regalloc=5 %s -o - | FileCheck %s
2+
# RUN: llc -mtriple=amdgcn--amdpal -march=amdgcn -mcpu=gfx1100 -verify-machineinstrs=1 -start-before=greedy,0 -stop-after=virtregrewriter,0 -stress-regalloc=5 %s -o - | FileCheck %s
33

4-
# This test currently fails with verify-machineinstrs=1 due to dead bundle mishandling: "Live range continues after dead def flag".
4+
# This test checks that dead bundles are handled correctly.
55
---
66
name: psmain
77
tracksRegLiveness: true
@@ -20,7 +20,6 @@ body: |
2020
; CHECK-NEXT: renamable $sgpr1 = KILL undef $sgpr1
2121
; CHECK-NEXT: renamable $sgpr4_sgpr5_sgpr6_sgpr7_sgpr8_sgpr9_sgpr10_sgpr11 = S_BUFFER_LOAD_DWORDX8_IMM undef renamable $sgpr0_sgpr1_sgpr2_sgpr3, 416, 0 :: (dereferenceable invariant load (s256), align 4)
2222
; CHECK-NEXT: dead [[V_CVT_U32_F32_e64_:%[0-9]+]]:vgpr_32 = V_CVT_U32_F32_e64 0, $sgpr4, 0, 0, implicit $mode, implicit $exec
23-
; CHECK-NEXT: SI_SPILL_S256_SAVE renamable $sgpr4_sgpr5_sgpr6_sgpr7_sgpr8_sgpr9_sgpr10_sgpr11, %stack.0, implicit $exec, implicit $sgpr32 :: (store (s256) into %stack.0, align 4, addrspace 5)
2423
; CHECK-NEXT: dead renamable $sgpr4_sgpr5_sgpr6_sgpr7_sgpr8_sgpr9_sgpr10_sgpr11_sgpr12_sgpr13_sgpr14_sgpr15_sgpr16_sgpr17_sgpr18_sgpr19 = IMPLICIT_DEF
2524
; CHECK-NEXT: renamable $sgpr4_sgpr5_sgpr6_sgpr7_sgpr8_sgpr9_sgpr10_sgpr11 = S_BUFFER_LOAD_DWORDX8_IMM undef renamable $sgpr0_sgpr1_sgpr2_sgpr3, 416, 0 :: (dereferenceable invariant load (s256), align 4)
2625
; CHECK-NEXT: renamable $sgpr3 = COPY killed renamable $sgpr7

0 commit comments

Comments
 (0)