986d9f104b
For things with easily pre-checked overflow conditions -- shifts and unsigned subtraction -- write then checked methods in such a way that we stop emitting wrapping versions of them. For example, today <https://rust.godbolt.org/z/qM9YK8Txb> neither ```rust a.checked_sub(b).unwrap() ``` nor ```rust a.checked_sub(b).unwrap_unchecked() ``` actually optimizes to `sub nuw`. After this PR they do.
41 lines
933 B
Rust
41 lines
933 B
Rust
// MIR for `checked_shl` after PreCodegen
|
|
|
|
fn checked_shl(_1: u32, _2: u32) -> Option<u32> {
|
|
debug x => _1;
|
|
debug rhs => _2;
|
|
let mut _0: std::option::Option<u32>;
|
|
scope 1 (inlined core::num::<impl u32>::checked_shl) {
|
|
let mut _3: bool;
|
|
let mut _4: u32;
|
|
scope 2 (inlined core::num::<impl u32>::unchecked_shl) {
|
|
}
|
|
}
|
|
|
|
bb0: {
|
|
StorageLive(_3);
|
|
_3 = Lt(_2, const core::num::<impl u32>::BITS);
|
|
switchInt(move _3) -> [0: bb1, otherwise: bb2];
|
|
}
|
|
|
|
bb1: {
|
|
_0 = const Option::<u32>::None;
|
|
goto -> bb3;
|
|
}
|
|
|
|
bb2: {
|
|
StorageLive(_4);
|
|
_4 = ShlUnchecked(_1, _2);
|
|
_0 = Option::<u32>::Some(move _4);
|
|
StorageDead(_4);
|
|
goto -> bb3;
|
|
}
|
|
|
|
bb3: {
|
|
StorageDead(_3);
|
|
return;
|
|
}
|
|
}
|
|
|
|
ALLOC0 (size: 8, align: 4) {
|
|
00 00 00 00 __ __ __ __ │ ....░░░░
|
|
}
|