This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Stop using __builtin_assume in _LIBCPP_ASSERT
ClosedPublic

Authored by ldionne on Jun 28 2023, 6:25 AM.

Details

Summary

__builtin_assume can sometimes worsen code generation. For now, the
guideline seems to be to avoid adding assumptions without a clear
optimization intent. Since _LIBCPP_ASSERT is very general, we can't
have a clear optimization intent at this level, which makes
__builtin_assume the wrong tool for the job -- at least until
__builtin_assume is changed.

See https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609
for a discussion of this.

Diff Detail

Event Timeline

ldionne created this revision.Jun 28 2023, 6:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2023, 6:25 AM
ldionne requested review of this revision.Jun 28 2023, 6:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2023, 6:25 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Mordante accepted this revision.Jun 28 2023, 8:22 AM
Mordante added a subscriber: Mordante.

I'm a bit surprised by the information in the discourse thread; I too assumed it was safe to use.
I agree we should disable it, so LGTM!

This revision is now accepted and ready to land.Jun 28 2023, 8:22 AM
var-const edited the summary of this revision. (Show Details)Jun 28 2023, 3:02 PM
var-const accepted this revision.Jun 28 2023, 3:06 PM
var-const added a subscriber: var-const.

FWIW, I also found the information in the thread completely counterintuitive. I guess I'll be thinking of the "assume" attribute kinda like "inline", only beneficial in certain circumstances (at least for now). But given the thread, this patch looks like the right thing to do, so LGTM.

ldionne updated this revision to Diff 535777.Jun 29 2023, 7:04 AM

Fix [[maybe_unused]] issue on Windows.

This revision was automatically updated to reflect the committed changes.