From 89dbe9744255864445b1c9f9a613ae333d3f79c8 Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Fri, 14 Jun 2013 20:22:21 +0000 Subject: [PATCH] Mark rematerialized super/sub registers as dead. When we're rematerializing into a not-quite-right register we already add the real definition as an imp-def, but we should also be marking the "official" register as dead, since nothing else is going to use it as a result of this remat. Not doing this can affect pressure tracking. rdar://problem/14158833 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184002 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/RegisterCoalescer.cpp | 1 + test/CodeGen/X86/remat-phys-dead.ll | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/CodeGen/X86/remat-phys-dead.ll diff --git a/lib/CodeGen/RegisterCoalescer.cpp b/lib/CodeGen/RegisterCoalescer.cpp index 82043c2bf7d..7467bb595aa 100644 --- a/lib/CodeGen/RegisterCoalescer.cpp +++ b/lib/CodeGen/RegisterCoalescer.cpp @@ -843,6 +843,7 @@ bool RegisterCoalescer::reMaterializeTrivialDef(CoalescerPair &CP, // been asked for. If so it must implicitly define the whole thing. assert(TargetRegisterInfo::isPhysicalRegister(DstReg) && "Only expect virtual or physical registers in remat"); + NewMI->getOperand(0).setIsDead(true); NewMI->addOperand(MachineOperand::CreateReg(CopyDstReg, true /*IsDef*/, true /*IsImp*/, diff --git a/test/CodeGen/X86/remat-phys-dead.ll b/test/CodeGen/X86/remat-phys-dead.ll new file mode 100644 index 00000000000..4d7ee622a37 --- /dev/null +++ b/test/CodeGen/X86/remat-phys-dead.ll @@ -0,0 +1,23 @@ +; REQUIRES: asserts +; RUN: llc -mtriple=x86_64-apple-darwin -debug -o /dev/null < %s 2>&1 | FileCheck %s + +; We need to make sure that rematerialization into a physical register marks the +; super- or sub-register as dead after this rematerialization since only the +; original register is actually used later. Largely irrelevant for a trivial +; example like this, since EAX is never used again, but easy to test. + +define i8 @test_remat() { + ret i8 0 +; CHECK: REGISTER COALESCING +; CHECK: Remat: %EAX = MOV32r0 %EFLAGS, %AL +} + +; On the other hand, if it's already the correct width, we really shouldn't be +; marking the definition register as dead. + +define i32 @test_remat32() { + ret i32 0 +; CHECK: REGISTER COALESCING +; CHECK: Remat: %EAX = MOV32r0 %EFLAGS +} +