This is an archive of the discontinued LLVM Phabricator instance.

RegAllocGreedy: Avoid overflowing priority bitfields
ClosedPublic

Authored by arsenm on Jul 23 2022, 9:56 AM.

Details

Summary

The class priority is expected to be at most 5 bits before it starts
clobbering bits used for other fields. Also clamp the instruction
distance in case we have millions of instructions.

AMDGPU was accidentally overflowing into the global priority bit in
some cases. I think in principal we would have wanted this, but in the
cases I've looked at, it had the counter intuitive effect and
de-prioritized the large register tuple.

Avoid using weird bit hack PPC uses for global priority. The
AllocationPriority field is really 5 bits, and PPC was relying on
overflowing this to 6-bits to forcibly set the global priority
bit. Split this out as a separate flag to avoid having magic behavior
for values above 31.

Diff Detail

Event Timeline

arsenm created this revision.Jul 23 2022, 9:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 23 2022, 9:56 AM
arsenm requested review of this revision.Jul 23 2022, 9:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 23 2022, 9:56 AM
Herald added a subscriber: wdng. · View Herald Transcript
barannikov88 added inline comments.
llvm/include/llvm/Target/Target.td
291

Nit: '0' -> 'false'

arsenm updated this revision to Diff 447135.Jul 24 2022, 7:40 AM
foad added inline comments.Jul 25 2022, 2:24 AM
llvm/lib/CodeGen/RegAllocGreedy.cpp
352–353

These two get swapped by RegClassPriorityTrumpsGlobalness.

llvm/lib/Target/PowerPC/PPCRegisterInfoMMA.td
80–81

Shouldn't this be 36 - 32 = 4 to preserve current behaviour?

llvm/utils/TableGen/CodeGenRegisters.cpp
806–807

The < 0 check seems redundant.

arsenm updated this revision to Diff 448199.Jul 27 2022, 4:04 PM

Address comments

arsenm marked 4 inline comments as done.Jul 27 2022, 4:07 PM
foad added a subscriber: hfinkel.Jul 28 2022, 3:41 AM

LGTM with the comment fixed, but it would be nice to get an ack from the PPC maintainers (or maybe @hfinkel).

llvm/lib/CodeGen/RegAllocGreedy.cpp
352–353

You've got the if/else cases the wrong way round.

arsenm updated this revision to Diff 460397.Sep 15 2022, 7:00 AM

Fix comment

arsenm marked an inline comment as done.Sep 15 2022, 7:00 AM
foad accepted this revision.Sep 15 2022, 7:12 AM
This revision is now accepted and ready to land.Sep 15 2022, 7:12 AM