[llvm] [AMDGPU][MachineRegisterInfo] Extend the MRI live-ins check to account for Subreg (PR #126926)
Vikash Gupta via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 12 07:38:23 PST 2025
https://github.com/vg0204 created https://github.com/llvm/llvm-project/pull/126926
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.
>From 1b35f74721e3331f58409c941c1472c1e40cbe21 Mon Sep 17 00:00:00 2001
From: vikashgu <Vikash.Gupta at amd.com>
Date: Wed, 12 Feb 2025 15:23:23 +0000
Subject: [PATCH] [AMDGPU][MachineRegisterInfo] Extend the MRI live-ins check
by including the check against the subregs for live-ins.
---
llvm/include/llvm/CodeGen/MachineRegisterInfo.h | 2 +-
llvm/lib/CodeGen/MachineRegisterInfo.cpp | 16 ++++++++++++++--
2 files changed, 15 insertions(+), 3 deletions(-)
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;
}
More information about the llvm-commits
mailing list