[llvm-commits] [llvm] r147902 - /llvm/trunk/lib/CodeGen/MachineCSE.cpp

Evan Cheng evan.cheng at apple.com
Tue Jan 10 16:38:11 PST 2012


Author: evancheng
Date: Tue Jan 10 18:38:11 2012
New Revision: 147902

URL: http://llvm.org/viewvc/llvm-project?rev=147902&view=rev
Log:
Avoid CSE of instructions which define physical registers across MBBs unless
the physical registers are not allocatable.

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

Modified: llvm/trunk/lib/CodeGen/MachineCSE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineCSE.cpp?rev=147902&r1=147901&r2=147902&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineCSE.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineCSE.cpp Tue Jan 10 18:38:11 2012
@@ -87,6 +87,7 @@
                                SmallVector<unsigned,2> &PhysDefs) const;
     bool PhysRegDefsReach(MachineInstr *CSMI, MachineInstr *MI,
                           SmallSet<unsigned,8> &PhysRefs,
+                          SmallVector<unsigned,2> &PhysDefs,
                           bool &NonLocal) const;
     bool isCSECandidate(MachineInstr *MI);
     bool isProfitableToCSE(unsigned CSReg, unsigned Reg,
@@ -222,6 +223,7 @@
 
 bool MachineCSE::PhysRegDefsReach(MachineInstr *CSMI, MachineInstr *MI,
                                   SmallSet<unsigned,8> &PhysRefs,
+                                  SmallVector<unsigned,2> &PhysDefs,
                                   bool &NonLocal) const {
   // For now conservatively returns false if the common subexpression is
   // not in the same basic block as the given instruction. The only exception
@@ -231,10 +233,16 @@
 
   bool CrossMBB = false;
   if (CSMBB != MBB) {
-    if (MBB->pred_size() == 1 && *MBB->pred_begin() == CSMBB)
-      CrossMBB = true;
-    else
+    if (MBB->pred_size() != 1 || *MBB->pred_begin() != CSMBB)
       return false;
+
+    for (unsigned i = 0, e = PhysDefs.size(); i != e; ++i) {
+      if (TRI->isInAllocatableClass(PhysDefs[i]))
+        // Avoid extending live range of physical registers unless
+        // they are unallocatable.
+        return false;
+    }
+    CrossMBB = true;
   }
   MachineBasicBlock::const_iterator I = CSMI; I = llvm::next(I);
   MachineBasicBlock::const_iterator E = MI;
@@ -429,7 +437,7 @@
       // in between and the physical register uses were not clobbered.
       unsigned CSVN = VNT.lookup(MI);
       MachineInstr *CSMI = Exps[CSVN];
-      if (PhysRegDefsReach(CSMI, MI, PhysRefs, CrossMBBPhysDef))
+      if (PhysRegDefsReach(CSMI, MI, PhysRefs, PhysDefs, CrossMBBPhysDef))
         FoundCSE = true;
     }
 





More information about the llvm-commits mailing list