Know some simple identities. This improves codegen for (1LL << N).
[oota-llvm.git] / lib / CodeGen / VirtRegMap.cpp
index 4608cdeaf5374662648b4930e00c9601f93b9f58..c72c18a94c00d8435a50684766b8fed506c95b30 100644 (file)
@@ -28,6 +28,7 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/STLExtras.h"
+#include <algorithm>
 using namespace llvm;
 
 namespace {
@@ -323,11 +324,13 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, const VirtRegMap &VRM) {
             std::map<int, unsigned>::iterator SSI =
               SpillSlotsAvailable.find(StackSlot);
             if (SSI != SpillSlotsAvailable.end()) {
+              DEBUG(std::cerr << "Reusing SS#" << StackSlot << " from physreg "
+                              << MRI->getName(SSI->second) << " for vreg"
+                              << VirtReg <<" instead of reloading into physreg "
+                              << MRI->getName(VRM.getPhys(VirtReg)) << "\n");
               // If this stack slot value is already available, reuse it!
               PhysReg = SSI->second;
               MI.SetMachineOperandReg(i, PhysReg);
-              DEBUG(std::cerr << "Reusing SS#" << StackSlot << " from physreg "
-                              << MRI->getName(SSI->second) << "\n");
 
               // The only technical detail we have is that we don't know that
               // PhysReg won't be clobbered by a reloaded stack slot that occurs
@@ -350,6 +353,7 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, const VirtRegMap &VRM) {
               // Otherwise, reload it and remember that we have it.
               PhysReg = VRM.getPhys(VirtReg);
 
+            RecheckRegister:
               // Note that, if we reused a register for a previous operand, the
               // register we want to reload into might not actually be
               // available.  If this occurs, use the register indicated by the
@@ -359,7 +363,7 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, const VirtRegMap &VRM) {
                   if (ReusedOperands[ro].PhysRegReused == PhysReg) {
                     // Yup, use the reload register that we didn't use before.
                     PhysReg = ReusedOperands[ro].AssignedPhysReg;
-                    break;
+                    goto RecheckRegister;
                   } else {
                     ReusedOp &Op = ReusedOperands[ro];
                     unsigned PRRU = Op.PhysRegReused;
@@ -434,8 +438,8 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, const VirtRegMap &VRM) {
     // If we have folded references to memory operands, make sure we clear all
     // physical registers that may contain the value of the spilled virtual
     // register
-    VirtRegMap::MI2VirtMapTy::const_iterator I, E;
-    for (tie(I, E) = VRM.getFoldedVirts(&MI); I != E; ++I) {
+    VirtRegMap::MI2VirtMapTy::const_iterator I, End;
+    for (tie(I, End) = VRM.getFoldedVirts(&MI); I != End; ++I) {
       DEBUG(std::cerr << "Folded vreg: " << I->second.first << "  MR: "
                       << I->second.second);
       unsigned VirtReg = I->second.first;
@@ -519,6 +523,7 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, const VirtRegMap &VRM) {
           // If there is a dead store to this stack slot, nuke it now.
           MachineInstr *&LastStore = MaybeDeadStores[StackSlot];
           if (LastStore) {
+            DEBUG(std::cerr << " Killed store:\t" << *LastStore);
             ++NumDSE;
             MBB.erase(LastStore);
           }
@@ -539,7 +544,8 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, const VirtRegMap &VRM) {
           PhysRegsAvailable[PhysReg] = StackSlot;
           SpillSlotsAvailable[StackSlot] = PhysReg;
           DEBUG(std::cerr << "Updating SS#" << StackSlot <<" in physreg "
-                          << MRI->getName(PhysReg) << "\n");
+                          << MRI->getName(PhysReg) << " for virtreg #"
+                          << VirtReg << "\n");
 
           ++NumStores;
           VirtReg = PhysReg;