[llvm] [AMDGPU][MachineRegisterInfo] Extend the MRI live-ins check to account for Subreg (PR #126926)

via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 12 07:38:52 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: Vikash Gupta (vg0204)

<details>
<summary>Changes</summary>

This support extends live-in check for MRI, by adding check for sub-register checks also. It solves a BUG related to SILowerSGPRSpill, where KILL flag is introduced based on MRI live-in list. Now, if a SuperReg is in live-ins, it implies its immediate usage as well as any subpart of it. But, currently, only exact register match is taken care by MRI, bypassing the immediately utilized subregs as not used, thus marking it as Killed, and later machine verfier starts giving error for using killed subreg. 

Refer https://github.com/llvm/llvm-project/pull/126696 for more details.

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


2 Files Affected:

- (modified) llvm/include/llvm/CodeGen/MachineRegisterInfo.h (+1-1) 
- (modified) llvm/lib/CodeGen/MachineRegisterInfo.cpp (+14-2) 


``````````diff
diff --git a/llvm/include/llvm/CodeGen/MachineRegisterInfo.h b/llvm/include/llvm/CodeGen/MachineRegisterInfo.h
index 1c465741cb462..f182b42d2a24a 100644
--- a/llvm/include/llvm/CodeGen/MachineRegisterInfo.h
+++ b/llvm/include/llvm/CodeGen/MachineRegisterInfo.h
@@ -1020,7 +1020,7 @@ class MachineRegisterInfo {
     return LiveIns;
   }
 
-  bool isLiveIn(Register Reg) const;
+  bool isLiveIn(Register Reg, bool CheckForSubreg = false) const;
 
   /// getLiveInPhysReg - If VReg is a live-in virtual register, return the
   /// corresponding live-in physical register.
diff --git a/llvm/lib/CodeGen/MachineRegisterInfo.cpp b/llvm/lib/CodeGen/MachineRegisterInfo.cpp
index 937f63f6c5e00..341b0c7207092 100644
--- a/llvm/lib/CodeGen/MachineRegisterInfo.cpp
+++ b/llvm/lib/CodeGen/MachineRegisterInfo.cpp
@@ -447,10 +447,22 @@ void MachineRegisterInfo::clearKillFlags(Register Reg) const {
     MO.setIsKill(false);
 }
 
-bool MachineRegisterInfo::isLiveIn(Register Reg) const {
-  for (const std::pair<MCRegister, Register> &LI : liveins())
+bool MachineRegisterInfo::isLiveIn(Register Reg, bool CheckForSubreg) const {
+  for (const std::pair<MCRegister, Register> &LI : liveins()) {
     if ((Register)LI.first == Reg || LI.second == Reg)
       return true;
+
+    // Check if Reg is a subreg of live-in register
+    if (CheckForSubreg) {
+      MCRegister PhysReg = LI.first;
+      if (!PhysReg.isValid())
+        continue;
+
+      for (MCPhysReg SubReg : getTargetRegisterInfo()->subregs(PhysReg))
+        if (SubReg == Reg)
+          return true;
+    }
+  }
   return false;
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/126926


More information about the llvm-commits mailing list