OSDN Git Service

[CodeGen] Make the TwoAddressInstructionPass check if the instruction is commutable...
authorCraig Topper <craig.topper@gmail.com>
Sun, 11 Sep 2016 06:00:15 +0000 (06:00 +0000)
committerCraig Topper <craig.topper@gmail.com>
Sun, 11 Sep 2016 06:00:15 +0000 (06:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281158 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/TwoAddressInstructionPass.cpp

index 16ae90d..704f596 100644 (file)
@@ -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;