-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Add assume intrinsic #18080
Add assume intrinsic #18080
Conversation
Adds an `assume` intrinsic that gets translated to llvm.assume. It is used on a boolean expression and allows the optimizer to assume that the expression is true. This implements rust-lang#18051.
@@ -256,6 +256,13 @@ extern "rust-intrinsic" { | |||
/// NB: This is very different from the `unreachable!()` macro! | |||
pub fn unreachable() -> !; | |||
|
|||
/// Inform the optimizer that a condition is always true. |
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 would be nice to point out that the optimizer will try to preserve the information, so it may hurt performance rather than improving it if not used carefully.
Do we have places were we intend to use this and know that it provides a worthwhile performance improvement? I do not want to add features to Rust just because LLVM has them. |
I currently have some code that includes a loop containing slice operations whose checks won't get properly optimized away, even if I use the |
assert!(SRC_MULT * div <= src_buf.len());
assert!(DST_MULT * div <= dst_buf.len());
for i in range(0, div) {
let x = src_buf.slice(SRC_MULT * i, SRC_MULT * (i + 1));
let chars = [(x[0] & 0xFC) >> 2,
(x[0] & 0x03) << 4 | (x[1] & 0xF0) >> 4,
(x[1] & 0x0F) << 2 | (x[2] & 0xC0) >> 6,
(x[2] & 0x3F)];
let y = dst_buf.slice_mut(DST_MULT * i, DST_MULT * (i + 1));
for i in range(0, chars.len()) {
y[i] = unsafe { *char_set.unsafe_get(chars[i] as uint) };
}
} This is the loop in question which contains 4 unnecessary branches right now. |
Adds an `assume` intrinsic that gets translated to llvm.assume. It is used on a boolean expression and allows the optimizer to assume that the expression is true. This implements #18051.
Remove crate graph deduplication logic Fixes rust-lang/rust-analyzer#17748
Adds an
assume
intrinsic that gets translated to llvm.assume. It isused on a boolean expression and allows the optimizer to assume that
the expression is true.
This implements #18051.