This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Consider Code Fragments during regreassign
ClosedPublic

Authored by hzq on Jan 17 2023, 6:47 AM.

Details

Summary

During register swapping, the code fragments associated with the
function need to be swapped together (which may be generated during
PGO optimization).

Fix https://github.com/llvm/llvm-project/issues/59730

Diff Detail

Event Timeline

hzq created this revision.Jan 17 2023, 6:47 AM
Herald added a reviewer: maksfb. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
hzq requested review of this revision.Jan 17 2023, 6:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 17 2023, 6:47 AM

Thanks for fixing this, @hzq !

Some suggestions below.

Ideally we would have a test case loosely similar to this one (https://reviews.llvm.org/D138245) that shows that the fix is working as intended. Let me know if you need help writing this.

Finally, be aware that this pass is also experimental because it does not update debug info. So it really depends on how serious you are about keeping debug info accurate.

bolt/include/bolt/Core/BinaryFunction.h
377
1798–1800
bolt/lib/Passes/RegReAssign.cpp
326–328
378–380
hzq added a comment.Jan 17 2023, 5:27 PM

Ideally we would have a test case loosely similar to this one (https://reviews.llvm.org/D138245) that shows that the fix is working as intended. Let me know if you need help writing this.

Finally, be aware that this pass is also experimental because it does not update debug info. So it really depends on how serious you are about keeping debug info accurate.

Thanks. will modify and try to write test cases.

hzq updated this revision to Diff 538326.Jul 7 2023, 11:36 PM
hzq edited the summary of this revision. (Show Details)
hzq added a comment.Jul 9 2023, 3:34 AM

Hi, @rafauler , I'm sorry for the delayed response. Could you please help me take a look at this test case to see if it is valid?

hzq abandoned this revision.Jul 10 2023, 6:15 PM
hzq updated this revision to Diff 539600.Jul 12 2023, 9:28 AM
hzq added a subscriber: rafauler.

update test case and code.

hzq updated this revision to Diff 546864.Aug 3 2023, 7:41 AM
hzq retitled this revision from [BOLT] Fix error for -reg-reassign option to [BOLT] Consider Code Fragments during regreassign.
hzq edited the summary of this revision. (Show Details)

Update.

Thanks! Mostly formatting nits:

bolt/include/bolt/Core/BinaryFunction.h
377

Since you added a new getter for "getParentFraments", move this "using" to line 369 and change ParentFragments to use FrafmentsSetTy, just like Fragments.

bolt/lib/Passes/RegReAssign.cpp
195–197

nit: drop braces here:

198–202
229

clang-format

230–232
342

clang-format

343–345
bolt/test/X86/reg-reassign-swap-cold.s
12 ↗(On Diff #546864)

Because this tests runs the produced output, we need to move this test to the folder test/runtime/X86

hzq updated this revision to Diff 548231.Aug 8 2023, 8:06 AM

update+format

rafauler accepted this revision.Aug 8 2023, 1:44 PM

Thanks! LGTM with some modifications I made to the test file available here: https://pastebin.com/3abP1S5G

I modified the test to fail if the optimization is applied just to main, but not to main.cold, and vice-versa. Please commit this version. I also used basic block labels when generating FDATA instead of hardcoded offsets, so the test is resilient to changes in it. I further modified main.cold to be a global symbol, so the symbol is not stripped when we run llvm-strip. We do need to run llvm-strip because I'm not declaring bb labels as temp symbols anymore (.L1, etc), in order to use their names when generating fdata. That's the way we usually write the tests (function names are globals, bb names are locals but non-temp so we don't need to hardcode fdata).

This revision is now accepted and ready to land.Aug 8 2023, 1:44 PM
hzq updated this revision to Diff 548404.Aug 8 2023, 5:06 PM

update testcase.

hzq added a comment.Aug 8 2023, 5:07 PM

Thanks! LGTM with some modifications I made to the test file available here: https://pastebin.com/3abP1S5G

I modified the test to fail if the optimization is applied just to main, but not to main.cold, and vice-versa. Please commit this version. I also used basic block labels when generating FDATA instead of hardcoded offsets, so the test is resilient to changes in it. I further modified main.cold to be a global symbol, so the symbol is not stripped when we run llvm-strip. We do need to run llvm-strip because I'm not declaring bb labels as temp symbols anymore (.L1, etc), in order to use their names when generating fdata. That's the way we usually write the tests (function names are globals, bb names are locals but non-temp so we don't need to hardcode fdata).

Thanks very much for your assistance. It has been a great help to me.

This revision was automatically updated to reflect the committed changes.