[llvm] r250596 - RegisterPressure: allocatable physreg uses are always kills

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 16 17:46:57 PDT 2015


Author: matze
Date: Fri Oct 16 19:46:57 2015
New Revision: 250596

URL: http://llvm.org/viewvc/llvm-project?rev=250596&view=rev
Log:
RegisterPressure: allocatable physreg uses are always kills

This property was already used in the code path when no liveness
intervals are present. Unfortunately the code path that uses liveness
intervals tried to query a cached live interval for an allocatable
physreg, those are usually not computed so a conservative default was
used.

This doesn't affect any of the lit testcases. This is a foreclosure to
upcoming changes which should be NFC but without this patch this tidbit
wouldn't be NFC.

Modified:
    llvm/trunk/include/llvm/CodeGen/RegisterPressure.h
    llvm/trunk/lib/CodeGen/RegisterPressure.cpp

Modified: llvm/trunk/include/llvm/CodeGen/RegisterPressure.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/RegisterPressure.h?rev=250596&r1=250595&r2=250596&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/RegisterPressure.h (original)
+++ llvm/trunk/include/llvm/CodeGen/RegisterPressure.h Fri Oct 16 19:46:57 2015
@@ -418,6 +418,8 @@ public:
 protected:
   const LiveRange *getLiveRange(unsigned Reg) const;
 
+  bool isLastUse(unsigned VRegOrUnit, SlotIndex Pos) const;
+
   void increaseRegPressure(ArrayRef<unsigned> Regs);
   void decreaseRegPressure(ArrayRef<unsigned> Regs);
 

Modified: llvm/trunk/lib/CodeGen/RegisterPressure.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegisterPressure.cpp?rev=250596&r1=250595&r2=250596&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/RegisterPressure.cpp (original)
+++ llvm/trunk/lib/CodeGen/RegisterPressure.cpp Fri Oct 16 19:46:57 2015
@@ -561,6 +561,17 @@ bool RegPressureTracker::recede(SmallVec
   return true;
 }
 
+bool RegPressureTracker::isLastUse(unsigned VRegOrUnit, SlotIndex Pos) const {
+  // Allocatable physregs are always single-use before register rewriting.
+  if (!TargetRegisterInfo::isVirtualRegister(VRegOrUnit))
+    return true;
+  // Without liveness information we conservatively assume "no last use".
+  if (!RequireIntervals)
+    return false;
+  const LiveRange *LR = getLiveRange(VRegOrUnit);
+  return LR && LR->Query(Pos).isKill();
+}
+
 /// Advance across the current instruction.
 bool RegPressureTracker::advance() {
   assert(!TrackUntiedDefs && "unsupported mode");
@@ -595,21 +606,15 @@ bool RegPressureTracker::advance() {
     if (!isLive)
       discoverLiveIn(Reg);
     // Kill liveness at last uses.
-    bool lastUse = false;
-    if (RequireIntervals) {
-      const LiveRange *LR = getLiveRange(Reg);
-      lastUse = LR && LR->Query(SlotIdx).isKill();
-    }
-    else {
-      // Allocatable physregs are always single-use before register rewriting.
-      lastUse = !TargetRegisterInfo::isVirtualRegister(Reg);
-    }
-    if (lastUse && isLive) {
-      LiveRegs.erase(Reg);
-      decreaseRegPressure(Reg);
-    }
-    else if (!lastUse && !isLive)
+    if (isLastUse(Reg, SlotIdx)) {
+      if (isLive) {
+        LiveRegs.erase(Reg);
+        decreaseRegPressure(Reg);
+      }
+    } else if(!isLive) {
+      // We discovered a live which was not last used here, adjust pressure.
       increaseRegPressure(Reg);
+    }
   }
 
   // Generate liveness for defs.
@@ -924,21 +929,18 @@ void RegPressureTracker::bumpDownwardPre
 
   for (unsigned i = 0, e = RegOpers.Uses.size(); i < e; ++i) {
     unsigned Reg = RegOpers.Uses[i];
-    if (RequireIntervals) {
+    bool IsLastUse = isLastUse(Reg, SlotIdx);
+    // We had a last use at MIs position. To know the situation for the current
+    // position we have to check if there exist other uses in between.
+    if (IsLastUse && TargetRegisterInfo::isVirtualRegister(Reg)) {
+      SlotIndex CurrIdx = getCurrSlot();
       // FIXME: allow the caller to pass in the list of vreg uses that remain
       // to be bottom-scheduled to avoid searching uses at each query.
-      SlotIndex CurrIdx = getCurrSlot();
-      const LiveRange *LR = getLiveRange(Reg);
-      if (LR) {
-        LiveQueryResult LRQ = LR->Query(SlotIdx);
-        if (LRQ.isKill() && !findUseBetween(Reg, CurrIdx, SlotIdx, *MRI, LIS))
-          decreaseRegPressure(Reg);
-      }
+      if (findUseBetween(Reg, CurrIdx, SlotIdx, *MRI, LIS))
+        IsLastUse = false;
     }
-    else if (!TargetRegisterInfo::isVirtualRegister(Reg)) {
-      // Allocatable physregs are always single-use before register rewriting.
+    if (IsLastUse)
       decreaseRegPressure(Reg);
-    }
   }
 
   // Generate liveness for defs.




More information about the llvm-commits mailing list