This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] [SIFrameLowering] Replace LivePhysRegs with LiveRegUnits
Needs RevisionPublic

Authored by tanejapranav on Aug 11 2023, 7:42 AM.

Details

Summary

SIFrameLowering currently uses the LivePhysRegs utility class to
track the liveness of registers. The LiveRegUnits appear to be a
better design that works on register units and expected to be a
slightly more compile time efficient, especially for targets that
have register tuples.

Diff Detail

Unit TestsFailed

Event Timeline

tanejapranav created this revision.Aug 11 2023, 7:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 11 2023, 7:42 AM
tanejapranav requested review of this revision.Aug 11 2023, 7:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 11 2023, 7:42 AM
foad added inline comments.Aug 11 2023, 7:51 AM
llvm/lib/CodeGen/LiveRegUnits.cpp
89

Isn't this just:
return !MRI.isReserved(Reg) && available(Reg);
?

99

Could rewrite this using none_of since you're moving this code anyway.

arsenm added inline comments.Aug 11 2023, 7:52 AM
llvm/include/llvm/CodeGen/LiveRegUnits.h
115–120

This is potentially confusing, I think either they need to have separate names indicating one considers reserved registers or not. Or there should just be the one that does consider reserved registers. Can't think of a case off the top of my head where you would ever want to ignore reservations

llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
34–37

The isPhysRegUsed check should be redundant

This loop seems backwards, we could start by finding unused regunits and go up to the the register

cdevadas added inline comments.Aug 13 2023, 10:17 PM
llvm/include/llvm/CodeGen/LiveRegUnits.h
115–120

I'm more inclined towards including the reserved reg check in the existing available function itself. @MatzeB can you confirm if it is really needed to keep a definition without the reserved reg check in it?

arsenm requested changes to this revision.Aug 14 2023, 7:57 AM
This revision now requires changes to proceed.Aug 14 2023, 7:57 AM
tanejapranav added inline comments.Aug 21 2023, 5:10 AM
llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
34–37

The utility for finding the used physical registers in a function is already available by querying the alias register set. However, in the case of Register Units, appears like we don't have one ready in the LiveRegUnits implementation that would help us track the used Register Units.

At this point, we may have to compute the information on used register units which would require iterating over all instructions in the function, further worsening the complexity. Would it be worth going in that direction.

arsenm added inline comments.Aug 21 2023, 1:33 PM
llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
34–37

Ideally UsedPhysRegMask would use register units and be up-to-date by this point