This is an archive of the discontinued LLVM Phabricator instance.

Remove if-else to make branch predictor happy
ClosedPublic

Authored by prehistoric-penguin on Apr 20 2021, 1:51 AM.

Diff Detail

Event Timeline

prehistoric-penguin requested review of this revision.Apr 20 2021, 1:51 AM
prehistoric-penguin created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2021, 1:51 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
curdeius added inline comments.
libcxx/include/bitset
777–778

When here, please update this part too.

803

I assume that there's no subtle difference between _Traits::eq(__c, __one) and !_Traits::eq(__c, __zero), right?

Updating D100828: Remove if-else to make branch predictor happy

prehistoric-penguin marked an inline comment as done.

Updating D100828: Remove if-else to make branch predictor happy

libcxx/include/bitset
777–778

I have fixed this part. The CI fail is caused by the clang-format checking, it has nothing to do with my change.

803

Yes, there are only two possible values __one and __zero

ldionne accepted this revision.Apr 20 2021, 5:39 AM
ldionne added a subscriber: ldionne.

This LGTM but can you please rebase onto main and update the review? That will run the CI again, which failed in the format checks (but those should not be a hard error).

Ship it when CI is green.

This revision is now accepted and ready to land.Apr 20 2021, 5:39 AM
Quuxplusone accepted this revision.Apr 20 2021, 6:17 AM
Quuxplusone added a subscriber: Quuxplusone.

Also LGTM. To clarify @ldionne's comment: Normally buildkite runs a clang-format check, which is allowed to "soft-fail" (it'll tell you that clang-format disagrees with the patch's style, but it won't break the build, and you'll still end up with a green light from buildkite). In this PR, though, you caught main at a bad time: the clang-format check was "hard-failing" because of a misconfiguration. The misconfiguration was fixed in ff0ada4e1607385be30b2b38885cea2127568e04. So, if you rebase, then you should see buildkite (either soft-fail or pass) the clang-format check as intended, and then it'll run the rest of the tests. If the rest of the tests are green, then ship it!

prehistoric-penguin marked an inline comment as done.Apr 20 2021, 7:40 AM

Thanks for all the detailed reviewed messages. I am a newcomer here. This rebased patch is updated by manually create. If anything wrong please notify me.

Mordante accepted this revision.Apr 20 2021, 10:06 AM
Mordante added a subscriber: Mordante.

Nice patch, LGTM! Note it seems the build bot acted strange, can you rebase to start a new CI job?

The CI fails is caused by my mistake, for the previous function, we can't call the _Traits::eq since the _Traits doesn't exist in the function signature. Now the CI should pass, but the code change (*this)[__i] = (__c == __one); needs to be reviewed again, I don't know if it violates the code style.

Quuxplusone accepted this revision.Apr 20 2021, 7:41 PM
Quuxplusone added inline comments.
libcxx/include/bitset
777–778

Here you could use char_traits<_CharT>::eq(__c, __one) if you like. I don't think it matters which expression you use, in that they all do the same thing in practice and the Standard doesn't seem to tell us which to pick in theory. I have the weakest of preferences for the idea of using == directly and saving a template instantiation, which is exactly what you're doing, so, LGTM.

prehistoric-penguin marked an inline comment as done.Apr 20 2021, 8:33 PM
libcxx/include/bitset
777–778

Thank you for clarify!

The CI is green, I don't have the commit access, could you reviewers please commit it?

The CI is green, I don't have the commit access, could you reviewers please commit it?

Can you provide the git author string you'd want the commit attributed to, i.e. Real Name <email@address>?

The CI is green, I don't have the commit access, could you reviewers please commit it?

Can you provide the git author string you'd want the commit attributed to, i.e. Real Name <email@address>?

The author string: Shu Tian <invalid_ms_user@live.com>

Thank you very much!