This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Remove dead frame indices after sgpr spill.
ClosedPublic

Authored by hsmhsm on Oct 5 2021, 6:50 AM.

Details

Summary

All those frame indices which are dead after sgpr spill should be removed from
the function frame. Othewise, there is a side effect such as re-mapping of free
frame index ids by the later pass(es) like "stack slot coloring" which in turn
could mess-up with the book keeping of "frame index to VGPR lane".

Diff Detail

Event Timeline

hsmhsm created this revision.Oct 5 2021, 6:50 AM
hsmhsm requested review of this revision.Oct 5 2021, 6:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2021, 6:50 AM
hsmhsm updated this revision to Diff 377203.Oct 5 2021, 6:54 AM

Fix spell mistake in the comment and in assert line.

foad added inline comments.Oct 5 2021, 6:55 AM
llvm/test/CodeGen/AMDGPU/sgpr-spill-incorrect-fi-bookkeeping-bug.ll
9

This doesn't do anything unless you run FileCheck.

hsmhsm updated this revision to Diff 377221.Oct 5 2021, 7:01 AM

Fix missing FileCheck in the lit test. Thanks Jay for noticing it.

hsmhsm marked an inline comment as done.Oct 5 2021, 7:01 AM
foad added inline comments.Oct 5 2021, 7:02 AM
llvm/test/CodeGen/AMDGPU/sgpr-spill-incorrect-fi-bookkeeping-bug.ll
2

Does this work? It usually needs to be ... | FileCheck %s.

hsmhsm added inline comments.Oct 5 2021, 7:07 AM
llvm/test/CodeGen/AMDGPU/sgpr-spill-incorrect-fi-bookkeeping-bug.ll
2

No, it does not, it is again an incorrect check :( I have updated it. I am doing a clean build now, will run one round of lit test before pushing the updated fix.

hsmhsm updated this revision to Diff 377239.Oct 5 2021, 7:50 AM

Fix FileCheck command line.

hsmhsm marked an inline comment as done.Oct 5 2021, 7:51 AM
cdevadas added inline comments.Oct 5 2021, 9:18 AM
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
457

Isn't it possible to avoid this loop by handling the erase inside the original loop itself?
Maybe convert the range-based loop above into an iterator-based one?

llvm/test/CodeGen/AMDGPU/sgpr-spill-incorrect-fi-bookkeeping-bug.ll
12

Can you avoid all the unnamed variables?

rampitec added inline comments.Oct 5 2021, 12:27 PM
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
450

DenseSet, avoid std:: when possible.

hsmhsm marked 3 inline comments as done.Oct 5 2021, 11:44 PM
hsmhsm added inline comments.
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
450

Will update it soon.

457

As I understand it, it does not help. The llvm DensMap<>::erase() function does not return next iterator. So, erasing DensMap entries while iterating it seems to be *not* possible. Please let me know if you have any idea.

llvm/test/CodeGen/AMDGPU/sgpr-spill-incorrect-fi-bookkeeping-bug.ll
12

I am coming up with altogether a different lit test. Will update it soon.

cdevadas added inline comments.Oct 6 2021, 12:02 AM
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
457

If erase doesn't return the iterator, better retain this loop. Thanks.

hsmhsm updated this revision to Diff 377443.Oct 6 2021, 12:10 AM
hsmhsm marked 3 inline comments as done.

Fix few review comments by CD and Stas.

foad added inline comments.Oct 6 2021, 1:00 AM
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
457

If you write the loop as for (auto &R : make_early_inc_range(SGPRToVGPRSpills)) then you can erase R inside the loop.

hsmhsm updated this revision to Diff 377484.Oct 6 2021, 2:57 AM

Do make_early_inc_range traversal of SGPRToVGPRSpills container so that
the entries can be erased while iterating itself.

hsmhsm marked 2 inline comments as done.Oct 6 2021, 2:58 AM
hsmhsm added inline comments.
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
457

Thanks Jay. This is a useful LLVM related information that I was not aware of.

hsmhsm added a reviewer: foad.Oct 6 2021, 3:00 AM
foad added inline comments.Oct 6 2021, 3:00 AM
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
453

erase(R) should be slightly more efficient as it does not have to do another lookup in the map.

hsmhsm marked 2 inline comments as done.Oct 6 2021, 3:07 AM
hsmhsm added inline comments.
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
453

DenseMap<>::erase() (overloaded) functions takes either key or iterator as arguments. Here R is neither key nor iterator. It is an item (key value pair).

https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/ADT/DenseMap.h#L302

foad added inline comments.Oct 6 2021, 3:10 AM
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
453

Oh yes, you're right. So it would be slightly more efficient to use an iterator-based for loop, but neater to use a range-based for loop! I don't mind which you choose.

hsmhsm updated this revision to Diff 378486.Oct 9 2021, 7:58 PM
hsmhsm marked an inline comment as done.

Rebase.

cdevadas accepted this revision.Oct 10 2021, 9:58 PM

LGTM with a nitpick.

llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
445–451

The extra comment line.

This revision is now accepted and ready to land.Oct 10 2021, 9:58 PM
hsmhsm updated this revision to Diff 378569.Oct 10 2021, 10:41 PM

Update comment.

hsmhsm marked an inline comment as done.Oct 10 2021, 10:42 PM
This revision was automatically updated to reflect the committed changes.