Two-address pass should use findCommutedOpIndices to determine what registers are...
authorEvan Cheng <evan.cheng@apple.com>
Sat, 11 Jul 2009 00:04:23 +0000 (00:04 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Sat, 11 Jul 2009 00:04:23 +0000 (00:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75317 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/TwoAddressInstructionPass.cpp

index 3c404046f15e49e875ccde2756fb780bd8b33bce..b67f84b0f943704e7e1d9dc633a150ee1f8cdf63 100644 (file)
@@ -909,9 +909,16 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) {
           }
 
           // If it's profitable to commute the instruction, do so.
-          if (TID.isCommutable() && mi->getNumOperands() >= 3) {
-            unsigned regC = mi->getOperand(3-si).getReg();
-            if (isProfitableToCommute(regB, regC, mi, mbbi, Dist))
+          unsigned SrcOp1, SrcOp2;
+          if (TID.isCommutable() && mi->getNumOperands() >= 3 &&
+              TII->findCommutedOpIndices(mi, SrcOp1, SrcOp2)) {
+            unsigned regC = 0;
+            if (si == SrcOp1)
+              regC = mi->getOperand(SrcOp2).getReg();
+            else if (si == SrcOp2)
+              regC = mi->getOperand(SrcOp1).getReg();
+            
+            if (regC && isProfitableToCommute(regB, regC, mi, mbbi, Dist))
               if (CommuteInstruction(mi, mbbi, regB, regC, Dist)) {
                 ++NumAggrCommuted;
                 ++NumCommuted;