forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#122610 - saethlin:assume-const, r=<try>
Lower assume(false) to an unreachable terminator This turns the IR pattern: ``` call void `@llvm.assume(i1` false) call void `@core::hint::unreachable_unchecked::precondition_check()` rust-lang#7 br label %bb3 ``` Into just: ``` unreachable ``` I'm not sure why LLVM needs its hand held like this, but also this is a chance to emit less IR so even if the optimization is fixed in LLVM we still come out ahead. The only part of this PR I'm not happy with is the complexity in the loop that iterates over the MIR blocks. The structure of it was a bit subtle before, and now it's just out of control. Please help?
- Loading branch information
Showing
3 changed files
with
52 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//@ compile-flags: -O | ||
|
||
#![crate_type = "lib"] | ||
|
||
use std::hint::unreachable_unchecked; | ||
use std::ptr::{read, write}; | ||
|
||
type T = [u8; 753]; | ||
|
||
pub enum State { | ||
A(T), | ||
B(T), | ||
} | ||
|
||
// CHECK-LABEL: @init(ptr {{.*}}s) | ||
// CHECK-NEXT: start | ||
// CHECK-NEXT: store i8 1, ptr %s, align 1 | ||
// CHECK-NEXT: ret void | ||
#[no_mangle] | ||
unsafe fn init(s: *mut State) { | ||
let State::A(v) = read(s) else { unreachable_unchecked() }; | ||
write(s, State::B(v)); | ||
} |