mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-24 23:28:41 +00:00
Fix an issue where the two-address conversion pass incorrectly rewrites untied
operands to an early clobber register. This fixes <rdar://problem/9566076>. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@132738 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1125,6 +1125,7 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) {
|
||||
break; // The tied operands have been eliminated.
|
||||
}
|
||||
|
||||
bool IsEarlyClobber = false;
|
||||
bool RemovedKillFlag = false;
|
||||
bool AllUsesCopied = true;
|
||||
unsigned LastCopiedReg = 0;
|
||||
@@ -1132,7 +1133,11 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) {
|
||||
for (unsigned tpi = 0, tpe = TiedPairs.size(); tpi != tpe; ++tpi) {
|
||||
unsigned SrcIdx = TiedPairs[tpi].first;
|
||||
unsigned DstIdx = TiedPairs[tpi].second;
|
||||
unsigned regA = mi->getOperand(DstIdx).getReg();
|
||||
|
||||
const MachineOperand &DstMO = mi->getOperand(DstIdx);
|
||||
unsigned regA = DstMO.getReg();
|
||||
IsEarlyClobber |= DstMO.isEarlyClobber();
|
||||
|
||||
// Grab regB from the instruction because it may have changed if the
|
||||
// instruction was commuted.
|
||||
regB = mi->getOperand(SrcIdx).getReg();
|
||||
@@ -1196,15 +1201,17 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) {
|
||||
}
|
||||
|
||||
if (AllUsesCopied) {
|
||||
// Replace other (un-tied) uses of regB with LastCopiedReg.
|
||||
for (unsigned i = 0, e = mi->getNumOperands(); i != e; ++i) {
|
||||
MachineOperand &MO = mi->getOperand(i);
|
||||
if (MO.isReg() && MO.getReg() == regB && MO.isUse()) {
|
||||
if (MO.isKill()) {
|
||||
MO.setIsKill(false);
|
||||
RemovedKillFlag = true;
|
||||
if (!IsEarlyClobber) {
|
||||
// Replace other (un-tied) uses of regB with LastCopiedReg.
|
||||
for (unsigned i = 0, e = mi->getNumOperands(); i != e; ++i) {
|
||||
MachineOperand &MO = mi->getOperand(i);
|
||||
if (MO.isReg() && MO.getReg() == regB && MO.isUse()) {
|
||||
if (MO.isKill()) {
|
||||
MO.setIsKill(false);
|
||||
RemovedKillFlag = true;
|
||||
}
|
||||
MO.setReg(LastCopiedReg);
|
||||
}
|
||||
MO.setReg(LastCopiedReg);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user