-
Couldn't load subscription status.
- Fork 13.9k
Emit assume(false) as store i1 true, ptr poison, align 1
#127740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| //@ compile-flags: -Cno-prepopulate-passes -Zmir-opt-level=0 -O -Zinline-mir | ||
|
|
||
| #![crate_type = "lib"] | ||
|
|
||
| #[no_mangle] | ||
| pub fn unwrap_unchecked(x: Option<i32>) -> i32 { | ||
| // CHECK-LABEL: define{{.*}} i32 @unwrap_unchecked | ||
| // CHECK-NOT: call void @llvm.assume(i1 false) | ||
| // CHECK: store i1 true, ptr poison, align 1 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for reference: https://rust.godbolt.org/z/813oEoxso There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This basically only occurs when ubchecks is enabled. |
||
| // CHECK-NOT: call void @llvm.assume(i1 false) | ||
| // CHECK: ret | ||
| // CHECK } | ||
| unsafe { x.unwrap_unchecked() } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request: can you please include a comment here linking to something in LLVM about why this is worth doing? Otherwise someone like me would probably come along later and go "well,
llvm.assumeisn't a terminator so we can just emit that all the time instead" and try to "clean it up".(Ideally there'd be something in https://llvm.org/docs/ with a bunch of these preferred forms that we could just link to, but no need to block this PR on that.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like this is documented. I'll find it or add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this PR if it ends up just being to a link to a comment from nikic or something that's fine -- wouldn't be the first time we have one of those in cg_llvm :P
But if you were able to get an official place in LLVM with these kinds of things, that'd be wonderful. I'd love to have a place to reference for all the "don't emit the unsigned checked math intrinsics directly" and such advice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See llvm/llvm-project#98910.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing this is what you want? https://releases.llvm.org/18.1.0/docs/Frontend/PerformanceTips.html#id10