[llvm-commits] [llvm] r61611 - in /llvm/trunk: include/llvm/CodeGen/ScheduleDAGSDNodes.h lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp lib/CodeGen/SelectionDAG/ScheduleDAGSDNodesEmit.cpp

Dan Gohman gohman at apple.com
Sat Jan 3 10:01:47 PST 2009


Author: djg
Date: Sat Jan  3 12:01:46 2009
New Revision: 61611

URL: http://llvm.org/viewvc/llvm-project?rev=61611&view=rev
Log:
Remove the code from the scheduler that commuted two-address
instructions to avoid copies, because TwoAddressInstructionPass
also does this optimization.  The scheduler's version didn't
account for live-out values, which resulted in spurious commutes
and missed opportunities.

Now, TwoAddressInstructionPass handles all the opportunities,
instead of just those that the scheduler missed. The result is
usually the same, though there are occasional trivial differences
resulting from the avoidance of spurious commutes.

Modified:
    llvm/trunk/include/llvm/CodeGen/ScheduleDAGSDNodes.h
    llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodesEmit.cpp

Modified: llvm/trunk/include/llvm/CodeGen/ScheduleDAGSDNodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/ScheduleDAGSDNodes.h?rev=61611&r1=61610&r2=61611&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/ScheduleDAGSDNodes.h (original)
+++ llvm/trunk/include/llvm/CodeGen/ScheduleDAGSDNodes.h Sat Jan  3 12:01:46 2009
@@ -17,7 +17,6 @@
 
 #include "llvm/CodeGen/ScheduleDAG.h"
 #include "llvm/CodeGen/SelectionDAG.h"
-#include "llvm/ADT/SmallSet.h"
 
 namespace llvm {
   /// HazardRecognizer - This determines whether or not an instruction can be
@@ -75,8 +74,6 @@
   ///
   class ScheduleDAGSDNodes : public ScheduleDAG {
   public:
-    SmallSet<SDNode*, 16> CommuteSet;     // Nodes that should be commuted.
-
     ScheduleDAGSDNodes(SelectionDAG *dag, MachineBasicBlock *bb,
                        const TargetMachine &tm);
 

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp?rev=61611&r1=61610&r2=61611&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp Sat Jan  3 12:01:46 2009
@@ -186,60 +186,6 @@
     ListScheduleTopDown();
   
   AvailableQueue->releaseState();
-
-  CommuteNodesToReducePressure();
-}
-
-/// CommuteNodesToReducePressure - If a node is two-address and commutable, and
-/// it is not the last use of its first operand, add it to the CommuteSet if
-/// possible. It will be commuted when it is translated to a MI.
-void ScheduleDAGRRList::CommuteNodesToReducePressure() {
-  SmallPtrSet<SUnit*, 4> OperandSeen;
-  for (unsigned i = Sequence.size(); i != 0; ) {
-    --i;
-    SUnit *SU = Sequence[i];
-    if (!SU || !SU->getNode()) continue;
-    if (SU->isCommutable) {
-      unsigned Opc = SU->getNode()->getMachineOpcode();
-      const TargetInstrDesc &TID = TII->get(Opc);
-      unsigned NumRes = TID.getNumDefs();
-      unsigned NumOps = TID.getNumOperands() - NumRes;
-      for (unsigned j = 0; j != NumOps; ++j) {
-        if (TID.getOperandConstraint(j+NumRes, TOI::TIED_TO) == -1)
-          continue;
-
-        SDNode *OpN = SU->getNode()->getOperand(j).getNode();
-        SUnit *OpSU = isPassiveNode(OpN) ? NULL : &SUnits[OpN->getNodeId()];
-        if (OpSU && OperandSeen.count(OpSU) == 1) {
-          // Ok, so SU is not the last use of OpSU, but SU is two-address so
-          // it will clobber OpSU. Try to commute SU if no other source operands
-          // are live below.
-          bool DoCommute = true;
-          for (unsigned k = 0; k < NumOps; ++k) {
-            if (k != j) {
-              OpN = SU->getNode()->getOperand(k).getNode();
-              OpSU = isPassiveNode(OpN) ? NULL : &SUnits[OpN->getNodeId()];
-              if (OpSU && OperandSeen.count(OpSU) == 1) {
-                DoCommute = false;
-                break;
-              }
-            }
-          }
-          if (DoCommute)
-            CommuteSet.insert(SU->getNode());
-        }
-
-        // Only look at the first use&def node for now.
-        break;
-      }
-    }
-
-    for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
-         I != E; ++I) {
-      if (!I->isCtrl())
-        OperandSeen.insert(I->getSUnit()->OrigNode);
-    }
-  }
 }
 
 //===----------------------------------------------------------------------===//

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodesEmit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodesEmit.cpp?rev=61611&r1=61610&r2=61611&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodesEmit.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodesEmit.cpp Sat Jan  3 12:01:46 2009
@@ -28,8 +28,6 @@
 #include "llvm/Support/MathExtras.h"
 using namespace llvm;
 
-STATISTIC(NumCommutes,   "Number of instructions commuted");
-
 /// getInstrOperandRegClass - Return register class of the operand of an
 /// instruction of the specified TargetInstrDesc.
 static const TargetRegisterClass*
@@ -500,21 +498,6 @@
     for (unsigned i = NodeOperands; i != MemOperandsEnd; ++i)
       AddMemOperand(MI, cast<MemOperandSDNode>(Node->getOperand(i))->MO);
 
-    // Commute node if it has been determined to be profitable.
-    if (CommuteSet.count(Node)) {
-      MachineInstr *NewMI = TII->commuteInstruction(MI);
-      if (NewMI == 0)
-        DOUT << "Sched: COMMUTING FAILED!\n";
-      else {
-        DOUT << "Sched: COMMUTED TO: " << *NewMI;
-        if (MI != NewMI) {
-          MF->DeleteMachineInstr(MI);
-          MI = NewMI;
-        }
-        ++NumCommutes;
-      }
-    }
-
     if (II.usesCustomDAGSchedInsertionHook())
       // Insert this instruction into the basic block using a target
       // specific inserter which may returns a new basic block.





More information about the llvm-commits mailing list