aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/TwoAddressInstructionPass.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-01-19 07:08:42 +0000
committerChris Lattner <sabre@nondot.org>2005-01-19 07:08:42 +0000
commitc71d6949b91e19610f0f85f57b402b4df43019a5 (patch)
tree73835252ae66f6fbab344aa49a5f66489a3898bb /lib/CodeGen/TwoAddressInstructionPass.cpp
parent167b10cba4eff57718feeb30f567e324b96a9263 (diff)
Use the TargetInstrInfo::commuteInstruction method to commute instructions
instead of doing it manually. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19685 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/TwoAddressInstructionPass.cpp')
-rw-r--r--lib/CodeGen/TwoAddressInstructionPass.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/lib/CodeGen/TwoAddressInstructionPass.cpp b/lib/CodeGen/TwoAddressInstructionPass.cpp
index a03966802b..df632100de 100644
--- a/lib/CodeGen/TwoAddressInstructionPass.cpp
+++ b/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