mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-17 03:30:28 +00:00
Make local RA smarter about reusing input register of a copy
as output. Needed for (functional) correctness in inline asm, and should be generally beneficial. 7361612. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95050 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
44eedb9805
commit
5ce0ee9c09
@ -764,8 +764,11 @@ void RALocal::AllocateBasicBlock(MachineBasicBlock &MBB) {
|
|||||||
// Determine whether this is a copy instruction. The cases where the
|
// Determine whether this is a copy instruction. The cases where the
|
||||||
// source or destination are phys regs are handled specially.
|
// source or destination are phys regs are handled specially.
|
||||||
unsigned SrcCopyReg, DstCopyReg, SrcCopySubReg, DstCopySubReg;
|
unsigned SrcCopyReg, DstCopyReg, SrcCopySubReg, DstCopySubReg;
|
||||||
|
unsigned SrcCopyPhysReg = 0U;
|
||||||
bool isCopy = TII->isMoveInstr(*MI, SrcCopyReg, DstCopyReg,
|
bool isCopy = TII->isMoveInstr(*MI, SrcCopyReg, DstCopyReg,
|
||||||
SrcCopySubReg, DstCopySubReg);
|
SrcCopySubReg, DstCopySubReg);
|
||||||
|
if (isCopy && TargetRegisterInfo::isVirtualRegister(SrcCopyReg))
|
||||||
|
SrcCopyPhysReg = getVirt2PhysRegMapSlot(SrcCopyReg);
|
||||||
|
|
||||||
// Loop over the implicit uses, making sure that they are at the head of the
|
// Loop over the implicit uses, making sure that they are at the head of the
|
||||||
// use order list, so they don't get reallocated.
|
// use order list, so they don't get reallocated.
|
||||||
@ -977,13 +980,24 @@ void RALocal::AllocateBasicBlock(MachineBasicBlock &MBB) {
|
|||||||
|
|
||||||
// If DestVirtReg already has a value, use it.
|
// If DestVirtReg already has a value, use it.
|
||||||
if (!(DestPhysReg = getVirt2PhysRegMapSlot(DestVirtReg))) {
|
if (!(DestPhysReg = getVirt2PhysRegMapSlot(DestVirtReg))) {
|
||||||
|
// If this is a copy try to reuse the input as the output;
|
||||||
|
// that will make the copy go away.
|
||||||
// If this is a copy, the source reg is a phys reg, and
|
// If this is a copy, the source reg is a phys reg, and
|
||||||
// that reg is available, use that phys reg for DestPhysReg.
|
// that reg is available, use that phys reg for DestPhysReg.
|
||||||
|
// If this is a copy, the source reg is a virtual reg, and
|
||||||
|
// the phys reg that was assigned to that virtual reg is now
|
||||||
|
// available, use that phys reg for DestPhysReg. (If it's now
|
||||||
|
// available that means this was the last use of the source.)
|
||||||
if (isCopy &&
|
if (isCopy &&
|
||||||
TargetRegisterInfo::isPhysicalRegister(SrcCopyReg) &&
|
TargetRegisterInfo::isPhysicalRegister(SrcCopyReg) &&
|
||||||
isPhysRegAvailable(SrcCopyReg)) {
|
isPhysRegAvailable(SrcCopyReg)) {
|
||||||
DestPhysReg = SrcCopyReg;
|
DestPhysReg = SrcCopyReg;
|
||||||
assignVirtToPhysReg(DestVirtReg, DestPhysReg);
|
assignVirtToPhysReg(DestVirtReg, DestPhysReg);
|
||||||
|
} else if (isCopy &&
|
||||||
|
TargetRegisterInfo::isVirtualRegister(SrcCopyReg) &&
|
||||||
|
SrcCopyPhysReg && isPhysRegAvailable(SrcCopyPhysReg)) {
|
||||||
|
DestPhysReg = SrcCopyPhysReg;
|
||||||
|
assignVirtToPhysReg(DestVirtReg, DestPhysReg);
|
||||||
} else
|
} else
|
||||||
DestPhysReg = getReg(MBB, MI, DestVirtReg);
|
DestPhysReg = getReg(MBB, MI, DestVirtReg);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
; RUN: llc < %s | grep {subfc r3,r5,r4}
|
; RUN: llc < %s | grep {subfc r3,r5,r4}
|
||||||
; RUN: llc < %s | grep {subfze r4,r2}
|
; RUN: llc < %s | grep {subfze r4,r2}
|
||||||
; RUN: llc < %s -regalloc=local | grep {subfc r5,r4,r3}
|
; RUN: llc < %s -regalloc=local | grep {subfc r2,r5,r4}
|
||||||
; RUN: llc < %s -regalloc=local | grep {subfze r2,r2}
|
; RUN: llc < %s -regalloc=local | grep {subfze r3,r3}
|
||||||
; The first argument of subfc must not be the same as any other register.
|
; The first argument of subfc must not be the same as any other register.
|
||||||
|
|
||||||
; PR1357
|
; PR1357
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
; RUN: llc < %s -march=x86 -mtriple=i386-apple-darwin9 -regalloc=local | FileCheck %s
|
; RUN: llc < %s -march=x86 -mtriple=i386-apple-darwin9 -regalloc=local | FileCheck %s
|
||||||
|
; RUN: llc -O0 < %s -march=x86 -mtriple=i386-apple-darwin9 -regalloc=local | FileCheck %s
|
||||||
|
; CHECKed instructions should be the same with or without -O0.
|
||||||
|
|
||||||
@.str = private constant [12 x i8] c"x + y = %i\0A\00", align 1 ; <[12 x i8]*> [#uses=1]
|
@.str = private constant [12 x i8] c"x + y = %i\0A\00", align 1 ; <[12 x i8]*> [#uses=1]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user