This is an archive of the discontinued LLVM Phabricator instance.

RFC: RegAlloc: Avoid repeated calls to freezeReservedRegs
AcceptedPublic

Authored by foad on Feb 10 2022, 6:45 AM.

Details

Summary

With split register allocation, only call MRI->freezeReservedRegs if
they are not already frozen. This makes a measurable difference on
AMDGPU where regalloc is split in two and
SIRegisterInfo::getReservedRegs is expensive due to the large register
file and many subregs.

I measured a ~5% speed up with:

$ cat empty.ll
define void @f() {

ret void

}
$ perf stat -r 1000 -- llc -march amdgcn -mcpu gfx1030 empty.ll -filetype null

FIXME: The assertion I added fails on a few AArch64 CodeGen tests,
apparently because AArch64RegisterInfo::hasBasePointer changes after
FinalizeISel. How should this be handled? Is the target required to
call freezeReservedRegs again whenever the set of reserved regs might
have changed?

Diff Detail

Event Timeline

foad created this revision.Feb 10 2022, 6:45 AM
foad requested review of this revision.Feb 10 2022, 6:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2022, 6:45 AM

freezeReservedRegs is actually called 3-5 times. It's first called in finalizeLowering, again in the allocators, and then again in SILowerSGPRSpills.

We may be able to get away without re-freezing the SGPR spills if we make them all live throughout every block

foad added a comment.Feb 10 2022, 6:53 AM

and then again in SILowerSGPRSpills

OK but I'm less concerned about that because it only happens if there are some spills, and in any function that's large enough to have spills the fixed cost of getReservedRegs will be a lower proportion of the overall compile time.

foad added a comment.Feb 10 2022, 7:17 AM

FIXME: The assertion I added fails on a few AArch64 CodeGen tests,
apparently because AArch64RegisterInfo::hasBasePointer changes after
FinalizeISel.

Digging a little deeper, this is because hasBasePointer depends on the local frame size, which is set up by the LocalStackSlotAllocation pass.

arsenm added inline comments.Feb 10 2022, 7:07 PM
llvm/lib/CodeGen/RegAllocBase.cpp
66–69

Can this just assert the regs are frozen? Why does anything reach here without having done this already?

foad updated this revision to Diff 407788.Feb 11 2022, 12:18 AM

Simplify.

foad updated this revision to Diff 407791.Feb 11 2022, 12:23 AM
foad marked an inline comment as done.

Simplify.

arsenm accepted this revision.Feb 11 2022, 7:08 AM
This revision is now accepted and ready to land.Feb 11 2022, 7:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2022, 3:34 PM
foad added a comment.Mar 29 2022, 5:39 AM

LGTM

Thanks but I can't commit it because I don't know how to fix this:

FIXME: The assertion I added fails on a few AArch64 CodeGen tests,
apparently because AArch64RegisterInfo::hasBasePointer changes after
FinalizeISel. How should this be handled? Is the target required to
call freezeReservedRegs again whenever the set of reserved regs might
have changed?

llvm/lib/CodeGen/RegAllocBase.cpp
66–69

Good point. Simplified accordingly.