[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 23:18:10 PST 2025
https://github.com/vg0204 updated https://github.com/llvm/llvm-project/pull/126926
>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 1/2] [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;
}
>From efc25870025d5d45976abde8d3cff2fddfe14178 Mon Sep 17 00:00:00 2001
From: vikashgu <Vikash.Gupta at amd.com>
Date: Thu, 13 Feb 2025 07:17:45 +0000
Subject: [PATCH 2/2] Modified MRI liviIn check to have unconditional subreg
check
---
llvm/include/llvm/CodeGen/MachineRegisterInfo.h | 2 +-
llvm/lib/CodeGen/MachineRegisterInfo.cpp | 16 +++++++---------
2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/MachineRegisterInfo.h b/llvm/include/llvm/CodeGen/MachineRegisterInfo.h
index f182b42d2a24a..1c465741cb462 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, bool CheckForSubreg = false) const;
+ bool isLiveIn(Register Reg) 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 341b0c7207092..edac380dcf363 100644
--- a/llvm/lib/CodeGen/MachineRegisterInfo.cpp
+++ b/llvm/lib/CodeGen/MachineRegisterInfo.cpp
@@ -447,21 +447,19 @@ void MachineRegisterInfo::clearKillFlags(Register Reg) const {
MO.setIsKill(false);
}
-bool MachineRegisterInfo::isLiveIn(Register Reg, bool CheckForSubreg) const {
+bool MachineRegisterInfo::isLiveIn(Register Reg) 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;
+ MCRegister PhysReg = LI.first;
+ if (!PhysReg.isValid())
+ continue;
- for (MCPhysReg SubReg : getTargetRegisterInfo()->subregs(PhysReg))
- if (SubReg == Reg)
- return true;
- }
+ for (MCPhysReg SubReg : getTargetRegisterInfo()->subregs(PhysReg))
+ if (SubReg == Reg)
+ return true;
}
return false;
}
More information about the llvm-commits
mailing list