From 1f81deee1fb8bbdece6245bc898ac08ab941b55c Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sun, 11 Sep 2016 06:00:15 +0000 Subject: [CodeGen] Make the TwoAddressInstructionPass check if the instruction is commutable before calling findCommutedOpIndices for every operand. Also make sure the operand is a register before each call to save some work on commutable instructions that might have an operand. llvm-svn: 281158 --- llvm/lib/CodeGen/TwoAddressInstructionPass.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'llvm/lib/CodeGen/TwoAddressInstructionPass.cpp') diff --git a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp index 16ae90de66e..704f596e56f 100644 --- a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp +++ b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp @@ -1171,6 +1171,9 @@ bool TwoAddressInstructionPass::tryInstructionCommute(MachineInstr *MI, unsigned BaseOpIdx, bool BaseOpKilled, unsigned Dist) { + if (!MI->isCommutable()) + return false; + unsigned DstOpReg = MI->getOperand(DstOpIdx).getReg(); unsigned BaseOpReg = MI->getOperand(BaseOpIdx).getReg(); unsigned OpsNum = MI->getDesc().getNumOperands(); @@ -1180,7 +1183,7 @@ bool TwoAddressInstructionPass::tryInstructionCommute(MachineInstr *MI, // and OtherOpIdx are commutable, it does not really search for // other commutable operands and does not change the values of passed // variables. - if (OtherOpIdx == BaseOpIdx || + if (OtherOpIdx == BaseOpIdx || !MI->getOperand(OtherOpIdx).isReg() || !TII->findCommutedOpIndices(*MI, BaseOpIdx, OtherOpIdx)) continue; -- cgit v1.2.3