From 51bfd452d5d748abc5e65b71b8f7213a13e10569 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Wed, 5 May 2010 23:07:41 +0000 Subject: [PATCH] Fix PR6520. An earlyclobber physreg must not be allocated to anything else. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103133 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/RegAllocLocal.cpp | 14 +++++++-- .../X86/2010-05-05-LocalAllocEarlyClobber.ll | 31 +++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 test/CodeGen/X86/2010-05-05-LocalAllocEarlyClobber.ll diff --git a/lib/CodeGen/RegAllocLocal.cpp b/lib/CodeGen/RegAllocLocal.cpp index 94456d14385..a3d2f9d2c2e 100644 --- a/lib/CodeGen/RegAllocLocal.cpp +++ b/lib/CodeGen/RegAllocLocal.cpp @@ -843,8 +843,18 @@ void RALocal::AllocateBasicBlock(MachineBasicBlock &MBB) { SmallVector Kills; for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { MachineOperand &MO = MI->getOperand(i); - if (!MO.isReg() || !MO.isKill()) continue; - + if (!MO.isReg()) continue; + unsigned Reg = MO.getReg(); + if (!Reg) continue; + + // Avoid allocating assigned early clobbers below. + if (MO.isEarlyClobber() && TargetRegisterInfo::isPhysicalRegister(Reg)) { + spillPhysReg(MBB, MI, Reg, true); // Spill any existing value in reg + PhysRegsUsed[Reg] = 0; // It is free and reserved now + AddToPhysRegsUseOrder(Reg); + } + + if (!MO.isKill()) continue; if (!MO.isImplicit()) Kills.push_back(MO.getReg()); else if (!isReadModWriteImplicitKill(MI, MO.getReg())) diff --git a/test/CodeGen/X86/2010-05-05-LocalAllocEarlyClobber.ll b/test/CodeGen/X86/2010-05-05-LocalAllocEarlyClobber.ll new file mode 100644 index 00000000000..4b6a94d58c3 --- /dev/null +++ b/test/CodeGen/X86/2010-05-05-LocalAllocEarlyClobber.ll @@ -0,0 +1,31 @@ +; RUN: llc < %s -O0 -regalloc=local | FileCheck %s +; PR6520 +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32" +target triple = "i386-apple-darwin10.0.0" + +%0 = type { i8*, i8*, i32 } + +define i8* @func() nounwind ssp { +entry: + %retval = alloca i8*, align 4 ; [#uses=2] + %ret = alloca i8*, align 4 ; [#uses=2] + %p = alloca i8*, align 4 ; [#uses=1] + %t = alloca i32, align 4 ; [#uses=1] +; The earlyclobber $1 should only appear once. It should not be shared. +; CHECK: deafbeef, [[REG:%e.x]] +; CHECK-NOT: [[REG]] +; CHECK: InlineAsm End + %0 = call %0 asm "mov $$0xdeafbeef, $1\0A\09mov $$0xcafebabe, $0\0A\09mov $0, $2\0A\09", "=&r,=&r,=&{cx},~{dirflag},~{fpsr},~{flags}"() nounwind, !srcloc !0 ; <%0> [#uses=3] + %asmresult = extractvalue %0 %0, 0 ; [#uses=1] + %asmresult1 = extractvalue %0 %0, 1 ; [#uses=1] + %asmresult2 = extractvalue %0 %0, 2 ; [#uses=1] + store i8* %asmresult, i8** %ret + store i8* %asmresult1, i8** %p + store i32 %asmresult2, i32* %t + %tmp = load i8** %ret ; [#uses=1] + store i8* %tmp, i8** %retval + %1 = load i8** %retval ; [#uses=1] + ret i8* %1 +} + +!0 = metadata !{i32 79}