diff options
author | Chris Lattner <sabre@nondot.org> | 2005-01-19 07:08:42 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2005-01-19 07:08:42 +0000 |
commit | ea42c15da9eec9fb3b959d2e54e3b34483e23ab2 (patch) | |
tree | 248c36b26190354473f6f27ac57794364e88d623 /llvm/lib/CodeGen/TwoAddressInstructionPass.cpp | |
parent | f6932b700b8ac520ebf4d6a45b20dd927f2a6739 (diff) | |
download | bcm5719-llvm-ea42c15da9eec9fb3b959d2e54e3b34483e23ab2.tar.gz bcm5719-llvm-ea42c15da9eec9fb3b959d2e54e3b34483e23ab2.zip |
Use the TargetInstrInfo::commuteInstruction method to commute instructions
instead of doing it manually.
llvm-svn: 19685
Diffstat (limited to 'llvm/lib/CodeGen/TwoAddressInstructionPass.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TwoAddressInstructionPass.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp index a03966802b5..df632100de6 100644 --- a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp +++ b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp @@ -141,12 +141,23 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) { unsigned regC = mi->getOperand(2).getReg(); if (LV.KillsRegister(mi, regC)) { DEBUG(std::cerr << "2addr: COMMUTING : " << *mi); - mi->SetMachineOperandReg(2, regB); - mi->SetMachineOperandReg(1, regC); - DEBUG(std::cerr << "2addr: COMMUTED TO: " << *mi); - ++NumCommuted; - regB = regC; - goto InstructionRearranged; + MachineInstr *NewMI = TII.commuteInstruction(mi); + if (NewMI == 0) { + DEBUG(std::cerr << "2addr: COMMUTING FAILED!\n"); + } else { + DEBUG(std::cerr << "2addr: COMMUTED TO: " << *NewMI); + // If the instruction changed to commute it, update livevar. + if (NewMI != mi) { + LV.instructionChanged(mi, NewMI); // Update live variables + mbbi->insert(mi, NewMI); // Insert the new inst + mbbi->erase(mi); // Nuke the old inst. + mi = NewMI; + } + + ++NumCommuted; + regB = regC; + goto InstructionRearranged; + } } } // If this instruction is potentially convertible to a true |