diff options
Diffstat (limited to 'llvm/lib/CodeGen/TwoAddressInstructionPass.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TwoAddressInstructionPass.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp index 774b76f84b7..539f8486192 100644 --- a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp +++ b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp @@ -1205,6 +1205,7 @@ bool TwoAddressInstructionPass::tryInstructionCommute(MachineInstr *MI, if (!MI->isCommutable()) return false; + bool MadeChange = false; unsigned DstOpReg = MI->getOperand(DstOpIdx).getReg(); unsigned BaseOpReg = MI->getOperand(BaseOpIdx).getReg(); unsigned OpsNum = MI->getDesc().getNumOperands(); @@ -1223,8 +1224,8 @@ bool TwoAddressInstructionPass::tryInstructionCommute(MachineInstr *MI, // If OtherOp dies but BaseOp does not, swap the OtherOp and BaseOp // operands. This makes the live ranges of DstOp and OtherOp joinable. - bool DoCommute = - !BaseOpKilled && isKilled(*MI, OtherOpReg, MRI, TII, LIS, false); + bool OtherOpKilled = isKilled(*MI, OtherOpReg, MRI, TII, LIS, false); + bool DoCommute = !BaseOpKilled && OtherOpKilled; if (!DoCommute && isProfitableToCommute(DstOpReg, BaseOpReg, OtherOpReg, MI, Dist)) { @@ -1235,13 +1236,21 @@ bool TwoAddressInstructionPass::tryInstructionCommute(MachineInstr *MI, // If it's profitable to commute, try to do so. if (DoCommute && commuteInstruction(MI, DstOpIdx, BaseOpIdx, OtherOpIdx, Dist)) { + MadeChange = true; ++NumCommuted; - if (AggressiveCommute) + if (AggressiveCommute) { ++NumAggrCommuted; - return true; + // There might be more than two commutable operands, update BaseOp and + // continue scanning. + BaseOpReg = OtherOpReg; + BaseOpKilled = OtherOpKilled; + continue; + } + // If this was a commute based on kill, we won't do better continuing. + return MadeChange; } } - return false; + return MadeChange; } /// For the case where an instruction has a single pair of tied register |