Page MenuHomePhabricator

[Bitcode] Drop invalid branch_weight in BitcodeReader

Authored by steven_wu on Jul 13 2020, 10:50 AM.



If bitcode reader gets an invalid branch weight, drop that from the
inputs. This allows us to read the broken modules we generated before
the verifier was able to catch this.


Diff Detail

Event Timeline

steven_wu created this revision.Jul 13 2020, 10:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 13 2020, 10:50 AM

So this is a bitcode "upgrade" of sorts. An alternative would be to implement this in Verifier and strip invalid metadata similar to how invalid debug info is stripped, but treating this as an upgrade in the bitcode reader is probably fine too.


Can you add one positive CHECK, too, to make sure this doesn't just print nothing at all?

Address review feedback and also add a testcase to make sure good branch
weights are not stripped.

I don't think the debug info approach is good here since it is a lot of
information to pass through to only strip the bad branch weights. Also
not sure if it is really a good idea to run verifier in upgrader.

aprantl added inline comments.Jul 21 2020, 1:44 PM

Perhaps even more explicit:
// "Upgrade" older incorrect branch weights by dropping them.


Are the || operators correct here?

I feel like this should be

MD->getOperand(0) != nullptr && isa<MDString>(MD->getOperand(0) ?


if (!ProfName.equals("branch_weights"))



steven_wu updated this revision to Diff 279960.Jul 22 2020, 3:38 PM

Address review feedback

steven_wu marked 4 inline comments as done.Jul 22 2020, 3:39 PM
aprantl accepted this revision.Jul 22 2020, 5:23 PM
This revision is now accepted and ready to land.Jul 22 2020, 5:23 PM
This revision was automatically updated to reflect the committed changes.