[llvm] [CodeGen] Add assertion to MachineBasicBlock::addLiveIn and friends (PR #140527)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Wed May 21 03:06:08 PDT 2025
https://github.com/jayfoad updated https://github.com/llvm/llvm-project/pull/140527
>From d8115b38c643ef2d1cea6c503b16149da2cf888f Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Mon, 19 May 2025 11:23:22 +0100
Subject: [PATCH 1/2] [CodeGen] Add assertion to MachineBasicBlock::addLiveIn
and friends
Assert that the MCRegister passed into addLiveIn, removeLiveIn, isLiveIn
and computeRegisterLiveness is physical.
---
llvm/include/llvm/CodeGen/MachineBasicBlock.h | 6 ++++--
llvm/lib/CodeGen/MachineBasicBlock.cpp | 3 +++
llvm/lib/CodeGen/RegAllocFast.cpp | 3 ++-
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
index 9c563d761c1d9..be3621a8d1d0b 100644
--- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h
+++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
@@ -134,8 +134,10 @@ class MachineBasicBlock
MCRegister PhysReg;
LaneBitmask LaneMask;
- RegisterMaskPair(MCPhysReg PhysReg, LaneBitmask LaneMask)
- : PhysReg(PhysReg), LaneMask(LaneMask) {}
+ RegisterMaskPair(MCRegister PhysReg, LaneBitmask LaneMask)
+ : PhysReg(PhysReg), LaneMask(LaneMask) {
+ assert(PhysReg.isPhysical());
+ }
bool operator==(const RegisterMaskPair &other) const {
return PhysReg == other.PhysReg && LaneMask == other.LaneMask;
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index 37fe37fd6e423..8e30ce79a2cd7 100644
--- a/llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -598,6 +598,7 @@ void MachineBasicBlock::printAsOperand(raw_ostream &OS,
}
void MachineBasicBlock::removeLiveIn(MCRegister Reg, LaneBitmask LaneMask) {
+ assert(Reg.isPhysical());
LiveInVector::iterator I = find_if(
LiveIns, [Reg](const RegisterMaskPair &LI) { return LI.PhysReg == Reg; });
if (I == LiveIns.end())
@@ -616,6 +617,7 @@ MachineBasicBlock::removeLiveIn(MachineBasicBlock::livein_iterator I) {
}
bool MachineBasicBlock::isLiveIn(MCRegister Reg, LaneBitmask LaneMask) const {
+ assert(Reg.isPhysical());
livein_iterator I = find_if(
LiveIns, [Reg](const RegisterMaskPair &LI) { return LI.PhysReg == Reg; });
return I != livein_end() && (I->LaneMask & LaneMask).any();
@@ -1657,6 +1659,7 @@ MachineBasicBlock::LivenessQueryResult
MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI,
MCRegister Reg, const_iterator Before,
unsigned Neighborhood) const {
+ assert(Reg.isPhysical());
unsigned N = Neighborhood;
// Try searching forwards from Before, looking for reads or defs.
diff --git a/llvm/lib/CodeGen/RegAllocFast.cpp b/llvm/lib/CodeGen/RegAllocFast.cpp
index bb118dd9e1867..9279763e0cb3a 100644
--- a/llvm/lib/CodeGen/RegAllocFast.cpp
+++ b/llvm/lib/CodeGen/RegAllocFast.cpp
@@ -503,7 +503,8 @@ bool RegAllocFastImpl::mayBeSpillFromInlineAsmBr(const MachineInstr &MI) const {
if (MBB->isInlineAsmBrIndirectTarget() && TII->isStoreToStackSlot(MI, FI) &&
MFI->isSpillSlotObjectIndex(FI))
for (const auto &Op : MI.operands())
- if (Op.isReg() && MBB->isLiveIn(Op.getReg()))
+ if (Op.isReg() && Op.getReg() != MCRegister::NoRegister &&
+ MBB->isLiveIn(Op.getReg()))
return true;
return false;
}
>From 22b3054b54cfac520477419c931bb46001a43e28 Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Wed, 21 May 2025 10:59:01 +0100
Subject: [PATCH 2/2] isValid
---
llvm/lib/CodeGen/RegAllocFast.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/lib/CodeGen/RegAllocFast.cpp b/llvm/lib/CodeGen/RegAllocFast.cpp
index 9279763e0cb3a..8a54d5c901f59 100644
--- a/llvm/lib/CodeGen/RegAllocFast.cpp
+++ b/llvm/lib/CodeGen/RegAllocFast.cpp
@@ -503,8 +503,7 @@ bool RegAllocFastImpl::mayBeSpillFromInlineAsmBr(const MachineInstr &MI) const {
if (MBB->isInlineAsmBrIndirectTarget() && TII->isStoreToStackSlot(MI, FI) &&
MFI->isSpillSlotObjectIndex(FI))
for (const auto &Op : MI.operands())
- if (Op.isReg() && Op.getReg() != MCRegister::NoRegister &&
- MBB->isLiveIn(Op.getReg()))
+ if (Op.isReg() && Op.getReg().isValid() && MBB->isLiveIn(Op.getReg()))
return true;
return false;
}
More information about the llvm-commits
mailing list