summaryrefslogtreecommitdiff
path: root/lib/CodeGen/TargetInstrInfoImpl.cpp
diff options
context:
space:
mode:
authorJakob Stoklund Olesen <stoklund@2pi.dk>2011-09-01 17:18:50 +0000
committerJakob Stoklund Olesen <stoklund@2pi.dk>2011-09-01 17:18:50 +0000
commit9d548d0343774636e72713d678a078c8e808ed29 (patch)
tree04e15f64a3c3532669e1f5ed31c5129ae5fbc6bc /lib/CodeGen/TargetInstrInfoImpl.cpp
parent61560e205a7997749f066dcceaadd5f4b9b5e1be (diff)
downloadllvm-9d548d0343774636e72713d678a078c8e808ed29.tar.gz
llvm-9d548d0343774636e72713d678a078c8e808ed29.tar.bz2
llvm-9d548d0343774636e72713d678a078c8e808ed29.tar.xz
Prevent remat of partial register redefinitions.
An instruction that redefines only part of a larger register can never be rematerialized since the virtual register value depends on the old value in other parts of the register. This was fixed for the inline spiller in r138794. This patch fixes the problem for all register allocators, and includes a small test case. <rdar://problem/10032939> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138944 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/TargetInstrInfoImpl.cpp')
-rw-r--r--lib/CodeGen/TargetInstrInfoImpl.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/CodeGen/TargetInstrInfoImpl.cpp b/lib/CodeGen/TargetInstrInfoImpl.cpp
index ea0cfe2b94..1cd42ca2ae 100644
--- a/lib/CodeGen/TargetInstrInfoImpl.cpp
+++ b/lib/CodeGen/TargetInstrInfoImpl.cpp
@@ -362,6 +362,15 @@ isReallyTriviallyReMaterializableGeneric(const MachineInstr *MI,
const TargetInstrInfo &TII = *TM.getInstrInfo();
const TargetRegisterInfo &TRI = *TM.getRegisterInfo();
+ // A sub-register definition can only be rematerialized if the instruction
+ // doesn't read the other parts of the register. Otherwise it is really a
+ // read-modify-write operation on the full virtual register which cannot be
+ // moved safely.
+ unsigned Reg = MI->getOperand(0).getReg();
+ if (TargetRegisterInfo::isVirtualRegister(Reg) &&
+ MI->getOperand(0).getSubReg() && MI->readsVirtualRegister(Reg))
+ return false;
+
// A load from a fixed stack slot can be rematerialized. This may be
// redundant with subsequent checks, but it's target-independent,
// simple, and a common case.