Fix a bug where splitting cause some unnecessary spilling.
authorEvan Cheng <evan.cheng@apple.com>
Sat, 1 Dec 2007 04:42:39 +0000 (04:42 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Sat, 1 Dec 2007 04:42:39 +0000 (04:42 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44482 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/LiveIntervalAnalysis.cpp

index 2b22faf1cc4693e55b01f1b4b781be77e0edac67..77a5505ca8303143a50927324919199bb533259f 100644 (file)
@@ -995,9 +995,9 @@ rewriteInstructionsForSpills(const LiveInterval &li, bool TrySplit,
           if (VNI)
             HasKill = anyKillInMBBAfterIdx(li, VNI, MBB, getDefIndex(index));
         }
+        std::map<unsigned, std::vector<SRInfo> >::iterator SII =
+          SpillIdxes.find(MBBId);
         if (!HasKill) {
-          std::map<unsigned, std::vector<SRInfo> >::iterator SII =
-            SpillIdxes.find(MBBId);
           if (SII == SpillIdxes.end()) {
             std::vector<SRInfo> S;
             S.push_back(SRInfo(index, NewVReg, true));
@@ -1013,6 +1013,16 @@ rewriteInstructionsForSpills(const LiveInterval &li, bool TrySplit,
             Info.canFold = !HasUse;
           }
           SpillMBBs.set(MBBId);
+        } else if (SII != SpillIdxes.end() &&
+                   SII->second.back().vreg == NewVReg &&
+                   (int)index > SII->second.back().index) {
+          // There is an earlier def that's not killed (must be two-address).
+          // The spill is no longer needed.
+          SII->second.pop_back();
+          if (SII->second.empty()) {
+            SpillIdxes.erase(MBBId);
+            SpillMBBs.reset(MBBId);
+          }
         }
       }
     }