This is an archive of the discontinued LLVM Phabricator instance.

[APInt] Reorder fields to avoid a hole in the middle of the class
ClosedPublic

Authored by craig.topper on Apr 12 2017, 9:20 PM.

Details

Summary

APInt is currently implemented with an unsigned BitWidth field first and then a uint_64/pointer union. Due to the 64-bit size of the union there is a hole after the bitwidth.

Putting the union first allows the class to be packed. Making it 12 bytes instead of 16 bytes. An APSInt goes from 20 bytes to 16 bytes.

This shows a 4k reduction on the size of the opt binary on my local x86-64 build. So this enables some other improvement to the code as well.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Apr 12 2017, 9:20 PM
davide accepted this revision.Apr 12 2017, 9:33 PM
davide added a subscriber: davide.

Nice.

This revision is now accepted and ready to land.Apr 12 2017, 9:33 PM

I wonder if there's an easy way of testing this so that it doesn't break in the future? Maybe an unit test checking sizeof(). Thoughts?

This revision was automatically updated to reflect the committed changes.
hans edited edge metadata.Apr 13 2017, 8:38 AM

I wonder if there's an easy way of testing this so that it doesn't break in the future? Maybe an unit test checking sizeof(). Thoughts?

Clang (and GCC too I think) has a -Wpadded parning. Maybe we could #pragma enable it around this class? We have a lot of classes that are supposed to be carefully packed though.

In D32001#726060, @hans wrote:

I wonder if there's an easy way of testing this so that it doesn't break in the future? Maybe an unit test checking sizeof(). Thoughts?

Clang (and GCC too I think) has a -Wpadded parning. Maybe we could #pragma enable it around this class? We have a lot of classes that are supposed to be carefully packed though.

Maybe, I still prefer a static_assert<> but I don't have a strong preference.

Turns out MSVC has different packing than gcc/clang. So APSInt doesn't use the padding from APInt for storage. So the static_assert failed on windows.