Skip to content

Commit

Permalink
[CodeGen] Make the TwoAddressInstructionPass check if the instruction…
Browse files Browse the repository at this point in the history
… 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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281158 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
topperc committed Sep 11, 2016
1 parent d3eebe7 commit 2628aff
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/CodeGen/TwoAddressInstructionPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;

Expand Down

0 comments on commit 2628aff

Please sign in to comment.