This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Make getPreferredAlignment honor section markings.
ClosedPublic

Authored by efriedma on Aug 28 2018, 12:46 PM.

Details

Summary

This should more accurately reflect what the AsmPrinter will actually do.

This is NFC, as far as I can tell; all the places that might be affected already have an extra check to avoid using the result of getPreferredAlignment in this situation.

Diff Detail

Repository
rL LLVM

Event Timeline

efriedma created this revision.Aug 28 2018, 12:46 PM
echristo accepted this revision.Aug 28 2018, 12:52 PM

Yeah, that works for me. If we start getting something wrong it's an edge case we should probably document :)

This revision is now accepted and ready to land.Aug 28 2018, 12:52 PM

Thanks for this.

lib/IR/DataLayout.cpp
834 ↗(On Diff #162934)

About this, it keeps adding very visible codesize (technially datasize) to our images, which because our linker reports all the padding is very visible to customers, and unnecissarily bloats the images.

I ran some benchmarks and couldn't find any places it was improving performance, at least on ARM/AArch64. Remove this actually improved things in a few places.

The over-aligning globals dates back to a long time ago, I'm just not sure it's worth doing on many architectures. From what I remember, removing it does fail some X86 tests though, with worse looking code.

We may need be smarter than that and come up with some way to remove it for targets (or a way to mark globals as optsize :-/ )

efriedma added inline comments.Aug 28 2018, 3:27 PM
lib/IR/DataLayout.cpp
834 ↗(On Diff #162934)

Are you sure it's this code, specifically, causing the bloat? As far as I know, clang explicitly marks the alignment of all globals it creates, which makes this code irrelevant.

dmgreen added inline comments.Aug 29 2018, 3:54 AM
lib/IR/DataLayout.cpp
834 ↗(On Diff #162934)

Yes but...

The customer reported case I remember is the RTTI string are not aligned. Something like this:

class MyNormalClass {
    public:
            virtual int foo() const { return 1; };
};

class OveralignClass {
    public:
            virtual int foo() const { return 1; };
};

MyNormalClass a;
OveralignClass b;

"14OveralignClass", being 17 characters long, gets over aligned.

The other I found from looking around is the printf->puts conversion doesn't put and alignment on the strings it creates. I've just created D51410 for that one.

Anyway, none of that is really related to this patch. +1 from me, thanks for making this less easy to get wrong.

This revision was automatically updated to reflect the committed changes.