This is an archive of the discontinued LLVM Phabricator instance.

[AVR] Remove unused register scavenger
ClosedPublic

Authored by aykevl on Jan 22 2022, 10:29 AM.

Details

Summary

It was necessary in the past, but is not necessary anymore today. Instead, rely on the register allocator to allocate the correct registers.

The LPMW/ELPMW instruction can be modified to use an earlyclobber, which prevents it from using the Z register as an output register.

Also see: D131844

Diff Detail

Event Timeline

aykevl created this revision.Jan 22 2022, 10:29 AM
aykevl requested review of this revision.Jan 22 2022, 10:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 22 2022, 10:29 AM
benshi001 added inline comments.Jan 23 2022, 7:42 AM
llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp
751–752

Remove this comment line.

benshi001 added inline comments.Jan 23 2022, 8:04 AM
llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp
792–793

I did not understand how this assert is guranteed for LPM/ELPM.

benshi001 added inline comments.Jan 25 2022, 6:15 AM
llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp
792–793

Do we need a constraint like Constraints = "$src != $rd" in the definition of LPM/ELPM to gurantee that ?

since https://reviews.llvm.org/D131844 is accepted, can we close this one ?

Herald added a project: Restricted Project. · View Herald TranscriptAug 15 2022, 12:55 AM
aykevl planned changes to this revision.Aug 15 2022, 5:31 AM

No, I plan to update this PR so that it only includes the LPMW/ELPMW changes and to fix your review comments.

aykevl updated this revision to Diff 477536.Nov 23 2022, 9:23 AM
aykevl edited the summary of this revision. (Show Details)
aykevl added inline comments.Nov 23 2022, 9:25 AM
llvm/lib/Target/AVR/AVRInstrInfo.td
1682

I tried $dst != $z but that led to a "ran out of registers during register allocation" assert. So I'm using @earlyclobber instead (even though it is slightly more conservative).

aykevl updated this revision to Diff 477541.Nov 23 2022, 9:31 AM
aykevl updated this revision to Diff 477542.
benshi001 accepted this revision.Nov 24 2022, 11:26 PM

LGTM. Thanks.

llvm/lib/Target/AVR/AVRInstrInfo.td
1682

I think @earlyclobber is fine.

This revision is now accepted and ready to land.Nov 24 2022, 11:26 PM
benshi001 added inline comments.Nov 24 2022, 11:28 PM
llvm/test/CodeGen/AVR/pseudo/ELPMWRdZ.mir
32

Are the last two lines necessary ? I think the front 3 lines are OK enough.

aykevl marked an inline comment as done.Nov 27 2022, 6:30 AM

Thank you!

llvm/test/CodeGen/AVR/pseudo/ELPMWRdZ.mir
32

Yes. This way the register allocator will try to use R31R30 for %3 to avoid a copy but because of the earlyclobber flag it is forced to pick a different register pair. Therefore, it's a way to test that the earlyclobber works.

This revision was automatically updated to reflect the committed changes.
aykevl marked an inline comment as done.