This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Use RegUnits in RegisterClassInfo::getLastCalleeSavedAlias
Needs ReviewPublic

Authored by foad on Mar 23 2023, 9:49 AM.

Details

Reviewers
qcolombet
MatzeB
Summary

Change the implementation of getLastCalleeSavedAlias to use RegUnits
instead of register aliases. This is much faster on targets like AMDGPU
which define a very large number of overlapping register tuples.

No functional change intended. If PhysReg overlaps multiple CSRs then
getLastCalleeSavedAlias(PhysReg) could conceivably return a different
arbitrary one, but currently it is only used for some debug printing
anyway.

Diff Detail

Event Timeline

foad created this revision.Mar 23 2023, 9:49 AM
foad requested review of this revision.Mar 23 2023, 9:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 23 2023, 9:49 AM
qcolombet added inline comments.Apr 4 2023, 6:16 AM
llvm/include/llvm/CodeGen/RegisterClassInfo.h
121

Cannot this get out of range?
I.e., I believe we could assert that *UI is bigger than CalleeSavedAliases.size().

I am wondering why the check was there in the previous implementation.

foad added inline comments.Apr 4 2023, 6:22 AM
llvm/include/llvm/CodeGen/RegisterClassInfo.h
121

I don't know! I just found that when I removed the check, everything still worked.

qcolombet added inline comments.Apr 4 2023, 6:50 AM
llvm/include/llvm/CodeGen/RegisterClassInfo.h
121

Oh boy!
Looking at the history of the change, I don't see any explanation why we needed that check. (Unless I am mistaken, the check has been introduced with https://reviews.llvm.org/D28566.)

Could it be possible to call getLastCalleeSavedAlias before CalleeSavedAliases has been initialized?

arsenm added a subscriber: arsenm.Apr 4 2023, 6:56 AM
arsenm added inline comments.
llvm/include/llvm/CodeGen/RegisterClassInfo.h
121

My guess would be to handle calling conventions with 0 callee saved registers. Given that would cover the most common case for AMDGPU this is probably ok

arsenm added inline comments.Apr 4 2023, 6:57 AM
llvm/include/llvm/CodeGen/RegisterClassInfo.h
60

SmallVector<4> seems like a weird way to map this. I'd expect all sets of registers to be BitVectors?

foad added inline comments.Apr 5 2023, 3:41 AM
llvm/include/llvm/CodeGen/RegisterClassInfo.h
60

Not sure what you mean. We just want an array here, so we can lookup the CSR corresponding to a particular regunit as quickly as possible. (I agree the "4" is weird.)