This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Set preferred function alignment
ClosedPublic

Authored by NickGuy on Aug 9 2023, 8:08 AM.

Details

Summary

Aligning functions yields small performance gains on embedded cores, moreso with numerous small function calls. Similar to aligning loops, if the function can fit within a single cache line then the performance overhead of fetching more instructions can be limited.

Diff Detail

Event Timeline

NickGuy created this revision.Aug 9 2023, 8:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 9 2023, 8:08 AM
NickGuy requested review of this revision.Aug 9 2023, 8:08 AM

Can you add a test? Thanks.

NickGuy updated this revision to Diff 548931.Aug 10 2023, 2:07 AM

Can you add a test? Thanks.

Done and precommitted.

Can you improve the summary to explain why this is being done? Its the same reasons as we align loops.

Should this be done for all cpus? I can see how that would make sense, but as far as I understand you are only really aiming for M-class devices. And we haven't in the past aligned loops for v6m devices (or some of the higher end v7m devices).

llvm/test/CodeGen/ARM/preferred-function-alignment.ll
1 ↗(On Diff #548931)

It might be better to make this an Arm CPU deliberately (as opposed to thumb), as opposed to generic. I believe that is what this is testing.

NickGuy updated this revision to Diff 550727.Aug 16 2023, 6:54 AM
NickGuy edited the summary of this revision. (Show Details)

I've assigned the function alignment to the same as the loop alignment, as in my testing I'd seen that the values are "best" when they are equal.

Can you improve the summary to explain why this is being done? Its the same reasons as we align loops.

Words seem to be failing me today. Hopefully the new summary makes sense.

dmgreen accepted this revision.Aug 16 2023, 7:47 AM

I agree it makes sense to use the same alignments, especially for cortex-m cpus. Can you update the LoopAlignment. Maybe call it "CodeAlignment" now? I'm not sure that's better or not to change the name. The documentation can be changed to: "/// What alignment is preferred for loop bodies <and functions>, in log2(bytes)."

Otherwise LGTM. Thanks

This revision is now accepted and ready to land.Aug 16 2023, 7:47 AM
This revision was landed with ongoing or failed builds.Aug 16 2023, 9:33 AM
This revision was automatically updated to reflect the committed changes.