This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Fix AARCH64 registers aliasing
ClosedPublic

Authored by yota9 on Jan 15 2022, 4:36 AM.

Details

Summary

The aarch64 platform has special registers like X0_X1_X2_X3_X4_X5_X6_X7.
Using the downwars propagation this register will become a super
register for all X0..X7 and its subregisters which is not right. This
patch replaces the downwars propagation with caching all the aliases using MCRegAliasIterator.

Vladislav Khmelevsky,
Advanced Software Technology Lab, Huawei

Diff Detail

Event Timeline

yota9 created this revision.Jan 15 2022, 4:36 AM
yota9 requested review of this revision.Jan 15 2022, 4:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 15 2022, 4:36 AM
fhahn added a subscriber: fhahn.Jan 17 2022, 2:06 AM

Is it possible to add a test?

yota9 added a comment.Jan 17 2022, 2:13 AM

@fhahn This is very internal function of the BOLT, so I'm not sure hot to add such a testcase

fhahn added a comment.Jan 17 2022, 2:17 AM

@fhahn This is very internal function of the BOLT, so I'm not sure hot to add such a testcase

It fixes something, so there should be a way to test this change in behavior I assume, although I have no idea about how unit tests for bolt look like.

yota9 added a comment.Jan 17 2022, 5:08 AM

@fhahn The problem was not found during bolt usage, i.e. wrong output, but accidentally while I was investigating the aarch64 indirect branch support level. Currently the bolt uses tests like "input file" -> "output file", but I don't have an example of input file where the problem might occur and I don't know the way to test particular function from bolt internals. Maybe the reviewers will give me a hint on this

yota9 added a comment.Jan 20 2022, 2:58 AM

Very gentle ping to @maksfb @rafauler @Amir :))

maksfb accepted this revision.Jan 23 2022, 11:11 PM

Thanks for the fix! Please spellcheck the summary before committing.

This revision is now accepted and ready to land.Jan 23 2022, 11:11 PM

Thanks for the fix! Please spellcheck the summary before committing.

There remains the question of and how this can be tested I think.

Thanks for the fix! Please spellcheck the summary before committing.

There remains the question of and how this can be tested I think.

That's a good point. @yota9, if the testing can only be done via unit tests, we should add it. Which means we also have to add necessary changes to /bolt, as we currently don't have unit tests setup.

yota9 updated this revision to Diff 403061.Jan 25 2022, 3:52 PM

Hello @maksfb I was able to add unit tests support and to test this particular function :)

Amir added a comment.Jan 25 2022, 4:35 PM

@yota9
That's very impressive! But can you please split out adding the unit test infrastructure to a separate diff?

That's fantastic. Thank you, @yota9.

yota9 updated this revision to Diff 403409.Jan 26 2022, 2:37 PM

Reabased patch, add x86 reg aliasing test

yota9 updated this revision to Diff 403416.Jan 26 2022, 2:55 PM

Test refactor

yota9 updated this revision to Diff 403431.Jan 26 2022, 4:02 PM

Add target-specific includes under ifdef

yota9 added a comment.Jan 27 2022, 1:53 PM

Gentle ping to reviewers :)

maksfb accepted this revision.Jan 27 2022, 2:00 PM

Looks great!

This revision was landed with ongoing or failed builds.Jan 27 2022, 2:25 PM
This revision was automatically updated to reflect the committed changes.

Looks good, thanks! What are the practical implications of this for AArch64? Which pass is relying on ::getAliases()?

yota9 added a comment.Jan 28 2022, 6:24 AM

Looks good, thanks! What are the practical implications of this for AArch64? Which pass is relying on ::getAliases()?

Hello @rafaelauler ! I've found out the problem while investigating the analyzeIndirectBranchFragment for aarch64..