-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[llvm][RISCV] Implement Zilsd load/store pair optimization #158640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
4bbf382
5722750
569a86c
ce8fc11
2ff058f
a4cca81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -853,6 +853,44 @@ bool RISCVRegisterInfo::getRegAllocationHints( | |
const MachineRegisterInfo *MRI = &MF.getRegInfo(); | ||
auto &Subtarget = MF.getSubtarget<RISCVSubtarget>(); | ||
|
||
// Handle RegPairEven/RegPairOdd hints for Zilsd register pairs | ||
std::pair<unsigned, Register> Hint = MRI->getRegAllocationHint(VirtReg); | ||
unsigned HintType = Hint.first; | ||
Register Partner = Hint.second; | ||
|
||
if (HintType == RISCVRI::RegPairEven || HintType == RISCVRI::RegPairOdd) { | ||
// Check if we want the even or odd register of a consecutive pair | ||
bool WantOdd = (HintType == RISCVRI::RegPairOdd); | ||
|
||
// First priority: Check if partner is already allocated | ||
if (Partner.isVirtual() && VRM && VRM->hasPhys(Partner)) { | ||
MCPhysReg PartnerPhys = VRM->getPhys(Partner); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getPhy doesn't return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. then how do we know if the register is already allocated lol? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't a question of allocated or not. MCPhysReg is a typedef for You should use Once you cahnge |
||
// Calculate the exact register we need for consecutive pairing | ||
MCPhysReg TargetReg = PartnerPhys + (WantOdd ? 1 : -1); | ||
|
||
// Verify it's valid and available | ||
if (RISCV::GPRRegClass.contains(TargetReg) && | ||
is_contained(Order, TargetReg)) { | ||
Hints.push_back(TargetReg); | ||
} | ||
} | ||
|
||
// Second priority: Try to find consecutive register pairs in the allocation | ||
// order | ||
for (MCPhysReg PhysReg : Order) { | ||
if (!PhysReg) | ||
continue; | ||
|
||
unsigned RegNum = getEncodingValue(PhysReg); | ||
// Check if this register matches the even/odd requirement | ||
bool IsOdd = (RegNum % 2 != 0); | ||
|
||
// Verify the pair register exists and is in the same register class | ||
if ((WantOdd && IsOdd) || (!WantOdd && !IsOdd)) | ||
Hints.push_back(PhysReg); | ||
} | ||
} | ||
|
||
bool BaseImplRetVal = TargetRegisterInfo::getRegAllocationHints( | ||
VirtReg, Order, Hints, MF, VRM, Matrix); | ||
|
||
|
@@ -994,6 +1032,36 @@ bool RISCVRegisterInfo::getRegAllocationHints( | |
return BaseImplRetVal; | ||
} | ||
|
||
void RISCVRegisterInfo::updateRegAllocHint(Register Reg, Register NewReg, | ||
MachineFunction &MF) const { | ||
MachineRegisterInfo *MRI = &MF.getRegInfo(); | ||
std::pair<unsigned, Register> Hint = MRI->getRegAllocationHint(Reg); | ||
|
||
// Handle RegPairEven/RegPairOdd hints for Zilsd register pairs | ||
if ((Hint.first == RISCVRI::RegPairOdd || | ||
Hint.first == RISCVRI::RegPairEven) && | ||
Hint.second.isVirtual()) { | ||
// If 'Reg' is one of the even/odd register pair and it's now changed | ||
// (e.g. coalesced) into a different register, the other register of the | ||
// pair allocation hint must be updated to reflect the relationship change. | ||
Register Partner = Hint.second; | ||
std::pair<unsigned, Register> PartnerHint = | ||
MRI->getRegAllocationHint(Partner); | ||
|
||
// Make sure partner still points to us | ||
if (PartnerHint.second == Reg) { | ||
// Update partner to point to NewReg instead of Reg | ||
MRI->setRegAllocationHint(Partner, PartnerHint.first, NewReg); | ||
|
||
// If NewReg is virtual, set up the reciprocal hint | ||
// NewReg takes over Reg's role, so it gets the SAME hint type as Reg | ||
if (NewReg.isVirtual()) { | ||
topperc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
MRI->setRegAllocationHint(NewReg, Hint.first, Partner); | ||
} | ||
} | ||
} | ||
} | ||
|
||
Register | ||
RISCVRegisterInfo::findVRegWithEncoding(const TargetRegisterClass &RegClass, | ||
uint16_t Encoding) const { | ||
|
Uh oh!
There was an error while loading. Please reload this page.