Skip to content

Conversation

@s-barannikov
Copy link
Contributor

@s-barannikov s-barannikov commented Nov 13, 2025

getLanesWithProperty() is called with virtual registers only.

@llvmbot
Copy link
Member

llvmbot commented Nov 13, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: Sergei Barannikov (s-barannikov)

Changes

This synchronizes the copy & paste with recent changes to RPTracker.


Full diff: https://github.com/llvm/llvm-project/pull/167891.diff

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/GCNRegPressure.cpp (+9-8)
  • (modified) llvm/lib/Target/AMDGPU/GCNRegPressure.h (+1-1)
diff --git a/llvm/lib/Target/AMDGPU/GCNRegPressure.cpp b/llvm/lib/Target/AMDGPU/GCNRegPressure.cpp
index 0c5e3d0837800..43a35a54912d2 100644
--- a/llvm/lib/Target/AMDGPU/GCNRegPressure.cpp
+++ b/llvm/lib/Target/AMDGPU/GCNRegPressure.cpp
@@ -313,11 +313,11 @@ collectVirtualRegUses(SmallVectorImpl<VRegMaskOrUnit> &VRegMaskOrUnits,
 /// Mostly copy/paste from CodeGen/RegisterPressure.cpp
 static LaneBitmask getLanesWithProperty(
     const LiveIntervals &LIS, const MachineRegisterInfo &MRI,
-    bool TrackLaneMasks, Register RegUnit, SlotIndex Pos,
+    bool TrackLaneMasks, VirtRegOrUnit VRegOrUnit, SlotIndex Pos,
     LaneBitmask SafeDefault,
     function_ref<bool(const LiveRange &LR, SlotIndex Pos)> Property) {
-  if (RegUnit.isVirtual()) {
-    const LiveInterval &LI = LIS.getInterval(RegUnit);
+  if (VRegOrUnit.isVirtualReg()) {
+    const LiveInterval &LI = LIS.getInterval(VRegOrUnit.asVirtualReg());
     LaneBitmask Result;
     if (TrackLaneMasks && LI.hasSubRanges()) {
       for (const LiveInterval::SubRange &SR : LI.subranges()) {
@@ -325,14 +325,15 @@ static LaneBitmask getLanesWithProperty(
           Result |= SR.LaneMask;
       }
     } else if (Property(LI, Pos)) {
-      Result = TrackLaneMasks ? MRI.getMaxLaneMaskForVReg(RegUnit)
+      Result = TrackLaneMasks
+                   ? MRI.getMaxLaneMaskForVReg(VRegOrUnit.asVirtualReg())
                               : LaneBitmask::getAll();
     }
 
     return Result;
   }
 
-  const LiveRange *LR = LIS.getCachedRegUnit(RegUnit);
+  const LiveRange *LR = LIS.getCachedRegUnit(VRegOrUnit.asMCRegUnit());
   if (LR == nullptr)
     return SafeDefault;
   return Property(*LR, Pos) ? LaneBitmask::getAll() : LaneBitmask::getNone();
@@ -503,10 +504,10 @@ void GCNRPTracker::reset(const MachineRegisterInfo &MRI_,
 }
 
 /// Mostly copy/paste from CodeGen/RegisterPressure.cpp
-LaneBitmask GCNRPTracker::getLastUsedLanes(Register RegUnit,
+LaneBitmask GCNRPTracker::getLastUsedLanes(VirtRegOrUnit VRegOrUnit,
                                            SlotIndex Pos) const {
   return getLanesWithProperty(
-      LIS, *MRI, true, RegUnit, Pos.getBaseIndex(), LaneBitmask::getNone(),
+      LIS, *MRI, true, VRegOrUnit, Pos.getBaseIndex(), LaneBitmask::getNone(),
       [](const LiveRange &LR, SlotIndex Pos) {
         const LiveRange::Segment *S = LR.getSegmentContaining(Pos);
         return S != nullptr && S->end == Pos.getRegSlot();
@@ -752,7 +753,7 @@ GCNDownwardRPTracker::bumpDownwardPressure(const MachineInstr *MI,
     if (!Use.VRegOrUnit.isVirtualReg())
       continue;
     Register Reg = Use.VRegOrUnit.asVirtualReg();
-    LaneBitmask LastUseMask = getLastUsedLanes(Reg, SlotIdx);
+    LaneBitmask LastUseMask = getLastUsedLanes(Use.VRegOrUnit, SlotIdx);
     if (LastUseMask.none())
       continue;
     // The LastUseMask is queried from the liveness information of instruction
diff --git a/llvm/lib/Target/AMDGPU/GCNRegPressure.h b/llvm/lib/Target/AMDGPU/GCNRegPressure.h
index 4b22c68ef01c5..ea0e2bdcb7122 100644
--- a/llvm/lib/Target/AMDGPU/GCNRegPressure.h
+++ b/llvm/lib/Target/AMDGPU/GCNRegPressure.h
@@ -292,7 +292,7 @@ class GCNRPTracker {
   /// Mostly copy/paste from CodeGen/RegisterPressure.cpp
   void bumpDeadDefs(ArrayRef<VRegMaskOrUnit> DeadDefs);
 
-  LaneBitmask getLastUsedLanes(Register RegUnit, SlotIndex Pos) const;
+  LaneBitmask getLastUsedLanes(VirtRegOrUnit VRegOrUnit, SlotIndex Pos) const;
 
 public:
   // reset tracker and set live register set to the specified value.

@github-actions
Copy link

github-actions bot commented Nov 13, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

}

const LiveRange *LR = LIS.getCachedRegUnit(RegUnit);
const LiveRange *LR = LIS.getCachedRegUnit(VRegOrUnit.asMCRegUnit());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually dead code because getLastUsedLanes is called only when VRegOrUnit.isVirtualReg() below returns true. Not sure what is best: keep the copy synchronized with the source or delete the dead code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably delete dead code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done

This synchronizes the copy & paste with recent changes to RPTracker.
@s-barannikov s-barannikov changed the title [AMDGPU] Use VirtRegOrUnit (NFC) [AMDGPU] Delete some dead code (NFC) Nov 14, 2025
Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a bug but ok

@s-barannikov
Copy link
Contributor Author

FWIW The original function can be called with MCRegUnit; AMDGPU version is only called with virtual registers.

@s-barannikov s-barannikov merged commit 321a97e into llvm:main Nov 15, 2025
10 checks passed
@s-barannikov s-barannikov deleted the amdgpu-virt-reg-or-unit branch November 15, 2025 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants