This is an archive of the discontinued LLVM Phabricator instance.

[GlobalMerge] Set the alignment on merged global structs
ClosedPublic

Authored by dmgreen on Jun 1 2018, 7:00 AM.

Details

Summary

If no alignment is set, the abi/preferred alignment of structs will be
used which may be higher than required. This can lead to extra padding
and in the end an increase in data size.

Diff Detail

Repository
rL LLVM

Event Timeline

dmgreen created this revision.Jun 1 2018, 7:00 AM
efriedma added inline comments.Jun 1 2018, 1:23 PM
lib/CodeGen/GlobalMerge.cpp
503 ↗(On Diff #149444)

The alignment of the output should be based on the alignment of the input globals, not the alignment of the type of the merged global.

Looking more, we reject globals with an explicit alignment higher than the ABI alignment of the type. So I guess this is technically equivalent, but that isn't obvious; please add a comment.

dmgreen updated this revision to Diff 149974.Jun 5 2018, 7:13 AM

Added a comment. I could change it to calculate the MaxAlignment from the alignment on the globals, if you think that's better in the long run.

efriedma accepted this revision.Jun 5 2018, 1:55 PM

LGTM

Long-term this code should be rewritten to do alignment computations itself, and insert padding as needed, but this is fine for now.

This revision is now accepted and ready to land.Jun 5 2018, 1:55 PM
This revision was automatically updated to reflect the committed changes.