[llvm-commits] [llvm] r85045 - /llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp

Evan Cheng evan.cheng at apple.com
Sun Oct 25 00:48:51 PDT 2009


Author: evancheng
Date: Sun Oct 25 02:48:51 2009
New Revision: 85045

URL: http://llvm.org/viewvc/llvm-project?rev=85045&view=rev
Log:
Do not delete identity insert_subreg even if dest is virtual. Let later passes delete them. This avoids register scavenger complain.

Modified:
    llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp

Modified: llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp?rev=85045&r1=85044&r2=85045&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp (original)
+++ llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp Sun Oct 25 02:48:51 2009
@@ -922,7 +922,7 @@
       DefMI->getOperand(DeadIdx).setIsDead();
     else
       DefMI->addOperand(MachineOperand::CreateReg(li.reg,
-                                                  true, true, false, true));
+                   /*def*/true, /*implicit*/true, /*kill*/false, /*dead*/true));
     LRStart = li_->getNextSlot(LRStart);
   }
 }
@@ -1853,7 +1853,7 @@
         tii_->isMoveInstr(*DefMI, SrcReg, DstReg, SrcSubIdx, DstSubIdx) &&
         DstReg == li.reg && SrcReg == Reg) {
       // Cache computed info.
-      LR->valno->def  = LR->start;
+      LR->valno->def = LR->start;
       LR->valno->setCopy(DefMI);
       return true;
     }
@@ -2006,7 +2006,7 @@
   // RHS into, update the value number info for the LHS to indicate that the
   // value number is defined where the RHS value number was.
   const VNInfo *VNI = RHS.getValNumInfo(0);
-  LHSValNo->def  = VNI->def;
+  LHSValNo->def = VNI->def;
   LHSValNo->setCopy(VNI->getCopy());
 
   // Okay, the final step is to loop over the RHS live intervals, adding them to
@@ -2489,8 +2489,7 @@
       MachineOperand &Use = I.getOperand();
       MachineInstr *UseMI = Use.getParent();
       unsigned SrcReg, DstReg, SrcSubIdx, DstSubIdx;
-      if (tii_->isMoveInstr(*UseMI, SrcReg, DstReg, SrcSubIdx, DstSubIdx) &&
-          SrcReg == DstReg)
+      if (tii_->isIdentityCopy(*UseMI, SrcReg, DstReg, SrcSubIdx, DstSubIdx))
         // Ignore identity copies.
         continue;
       LiveIndex Idx = li_->getInstructionIndex(UseMI);
@@ -2516,8 +2515,7 @@
 
     // Ignore identity copies.
     unsigned SrcReg, DstReg, SrcSubIdx, DstSubIdx;
-    if (!(tii_->isMoveInstr(*MI, SrcReg, DstReg, SrcSubIdx, DstSubIdx) &&
-          SrcReg == DstReg))
+    if (!tii_->isIdentityCopy(*MI, SrcReg, DstReg, SrcSubIdx, DstSubIdx))
       for (unsigned i = 0, NumOps = MI->getNumOperands(); i != NumOps; ++i) {
         MachineOperand &Use = MI->getOperand(i);
         if (Use.isReg() && Use.isUse() && Use.getReg() &&
@@ -2570,7 +2568,11 @@
     for (MachineBasicBlock::const_iterator mii = MBB->begin(), mie = MBB->end();
          mii != mie; ++mii) {
       const MachineInstr *MI = mii;
-      if (tii_->isIdentityCopy(*MI))
+      unsigned SrcReg, DstReg, SrcSubIdx, DstSubIdx;
+      if (tii_->isIdentityCopy(*MI, SrcReg, DstReg, SrcSubIdx, DstSubIdx))
+        continue;
+
+      if (MI->getOpcode() == TargetInstrInfo::IMPLICIT_DEF)
         continue;
 
       for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
@@ -2601,8 +2603,7 @@
         float Weight = li_->getSpillWeight(HasDef, HasUse, loopDepth);
         if (HasDef && isExiting) {
           // Looks like this is a loop count variable update.
-          LiveIndex DefIdx =
-            li_->getDefIndex(li_->getInstructionIndex(MI));
+          LiveIndex DefIdx = li_->getDefIndex(li_->getInstructionIndex(MI));
           const LiveRange *DLR =
             li_->getInterval(Reg).getLiveRangeContaining(DefIdx);
           if (DLR->end > MBBEnd)
@@ -2704,27 +2705,34 @@
                   MI->getOpcode() == TargetInstrInfo::SUBREG_TO_REG) &&
                  "Unrecognized copy instruction");
           DstReg = MI->getOperand(0).getReg();
+          // Do not delete subreg_to_reg, insert_subreg with undef source unless
+          // the definition is dead. e.g.
+          // %DO<def> = INSERT_SUBREG %D0<undef>, %S0<kill>, 1
+          // or else the scavenger may complain. These will be eliminated by the
+          // rewriter or the subreg lowering pass.
           if (TargetRegisterInfo::isPhysicalRegister(DstReg))
-            // Do not delete extract_subreg, insert_subreg of physical
-            // registers unless the definition is dead. e.g.
-            // %DO<def> = INSERT_SUBREG %D0<undef>, %S0<kill>, 1
-            // or else the scavenger may complain. LowerSubregs will
-            // change this to an IMPLICIT_DEF later.
+            // Don't delete extract_subreg of a physical register.
+            DoDelete = false;
+          else if (MI->getOpcode() == TargetInstrInfo::SUBREG_TO_REG ||
+                   (MI->getOpcode() == TargetInstrInfo::INSERT_SUBREG &&
+                    MI->getOperand(1).isUndef()))
             DoDelete = false;
         }
+
         if (MI->registerDefIsDead(DstReg)) {
           LiveInterval &li = li_->getInterval(DstReg);
           if (!ShortenDeadCopySrcLiveRange(li, MI))
             ShortenDeadCopyLiveRange(li, MI);
           DoDelete = true;
         }
-        if (!DoDelete)
+
+        if (!DoDelete) {
           mii = next(mii);
-        else {
+        } else {
           li_->RemoveMachineInstrFromMaps(MI);
           mii = mbbi->erase(mii);
-          ++numPeep;
         }
+        ++numPeep;
         continue;
       }
 
@@ -2762,8 +2770,7 @@
       }
 
       // If the move will be an identity move delete it
-      bool isMove= tii_->isMoveInstr(*MI, SrcReg, DstReg, SrcSubIdx, DstSubIdx);
-      if (isMove && SrcReg == DstReg) {
+      if (tii_->isIdentityCopy(*MI, SrcReg, DstReg, SrcSubIdx, DstSubIdx)) {
         if (li_->hasInterval(SrcReg)) {
           LiveInterval &RegInt = li_->getInterval(SrcReg);
           // If def of this move instruction is dead, remove its live range





More information about the llvm-commits mailing list