This is an archive of the discontinued LLVM Phabricator instance.

[IR][AutoUpgrade] Drop align attribute from void return types
ClosedPublic

Authored by steven_wu on May 10 2021, 3:26 PM.

Details

Summary

Since D87304, align become an invalid attribute on none pointer types and
verifier will reject bitcode that has invalid align attribute.

The problem is before the change, DeadArgumentElimination can easily
turn a pointer return type into a void return type without removing
align attribute. Teach Autograde to remove invalid align attribute
from return types to maintain bitcode compatibility.

rdar://77022993

Diff Detail

Event Timeline

steven_wu created this revision.May 10 2021, 3:26 PM
steven_wu requested review of this revision.May 10 2021, 3:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2021, 3:26 PM
dexonsmith accepted this revision.May 10 2021, 3:35 PM

LGTM with a couple of nits about the test.

llvm/test/Bitcode/upgrade-void-ret-attr.ll
1 ↗(On Diff #344219)

Please add a period at the end of the sentence. Also, I'm not sure we need the ;;, one is probably fine.

3 ↗(On Diff #344219)

For the bitcode file, I suggest using %s.bc (meaning the extension is .ll.bc), to simplify this.

Also, please rename the .ll file to end with the released version of LLVM used to generate the bitcode (e.g., -10.0.ll).

This revision is now accepted and ready to land.May 10 2021, 3:35 PM
steven_wu updated this revision to Diff 344231.May 10 2021, 4:14 PM

Address review feedback.

This revision was landed with ongoing or failed builds.May 11 2021, 8:24 AM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.May 14 2021, 8:02 PM

We bisected a +153kB binary size increase for chrome/android to this (https://bugs.chromium.org/p/chromium/issues/detail?id=1208513#c4). Is that expected? (That build config uses -Oz for many TUs.)

We bisected a +153kB binary size increase for chrome/android to this (https://bugs.chromium.org/p/chromium/issues/detail?id=1208513#c4). Is that expected? (That build config uses -Oz for many TUs.)

Hmm, that seems pretty weird — this commit fixes a compiler crash introduced by a missing bitcode upgrade from https://reviews.llvm.org/D87304, they should be reverted together if we need to revert something.

@jdoerfert, any thoughts on why removing the align attribute causes a regression here?

@thakis, is it possible the Chromium build is skipping the bitcode verifier when reading bitcode?

We bisected a +153kB binary size increase for chrome/android to this (https://bugs.chromium.org/p/chromium/issues/detail?id=1208513#c4). Is that expected? (That build config uses -Oz for many TUs.)

Hmm, that seems pretty weird — this commit fixes a compiler crash introduced by a missing bitcode upgrade from https://reviews.llvm.org/D87304, they should be reverted together if we need to revert something.

@jdoerfert, any thoughts on why removing the align attribute causes a regression here?

@thakis, is it possible the Chromium build is skipping the bitcode verifier when reading bitcode?

As far as I can tell we don't do anything clever in this area. We build clang without assertions and then use -flto=thin. What would cause clang to skip the bitcode verifier?

I can see how this increases IR size but I'm not sure about binary size. If you have your IR in the binary, then that is probably it. If not, I would assume it's some secondary effect that should not exist.

FWIW, IR size increase:

declare align 8 void @f() willreturn;
declare align 8 int *@g() willreturn;

share the same attribute set but if you remove align 8 from @f we have two distinct attribute sets in the IR.


I would not revert D87304 and this one to undo the binary size increase. Both patches fix assertions that can hit in practice.
We need to understand what caused the increase and target that part. Allowing align X void on returns is not a fix.

I don’t understand code size increase as well and have no guess about what might happen. This should be noop on bitcode that can pass the verifier.

Are you able to reduce it further to a TU and have a reproducer?

The size regression disappeared in our latest Clang roll
Reverting this patch at Clang head doesn't seem to cause any size changes, and yeah this doesn't seem like it should cause a difference.
So I'm not sure why the bisection ended up here (each step takes ~1hr so it's painful to reproduce). Sorry for the noise.