|
1 |
| -// skip-filecheck |
2 | 1 | //@ compile-flags: -O -Zmir-opt-level=2
|
3 | 2 | // EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
4 | 3 |
|
|
8 | 7 | // EMIT_MIR checked_ops.step_forward.PreCodegen.after.mir
|
9 | 8 | pub fn step_forward(x: u16, n: usize) -> u16 {
|
10 | 9 | // This uses `u16` so that the conversion to usize is always widening.
|
| 10 | + |
| 11 | + // CHECK-LABEL: fn step_forward |
| 12 | + // CHECK: inlined{{.+}}forward |
11 | 13 | std::iter::Step::forward(x, n)
|
12 | 14 | }
|
13 | 15 |
|
14 | 16 | // EMIT_MIR checked_ops.checked_shl.PreCodegen.after.mir
|
15 | 17 | pub fn checked_shl(x: u32, rhs: u32) -> Option<u32> {
|
| 18 | + // CHECK-LABEL: fn checked_shl |
| 19 | + // CHECK: [[TEMP:_[0-9]+]] = ShlUnchecked(copy _1, copy _2) |
| 20 | + // CHECK: _0 = Option::<u32>::Some({{move|copy}} [[TEMP]]) |
16 | 21 | x.checked_shl(rhs)
|
17 | 22 | }
|
| 23 | + |
| 24 | +// EMIT_MIR checked_ops.use_checked_sub.PreCodegen.after.mir |
| 25 | +pub fn use_checked_sub(x: u32, rhs: u32) { |
| 26 | + // We want this to be equivalent to open-coding it, leaving no `Option`s around. |
| 27 | + // FIXME(#138544): It's not yet. |
| 28 | + |
| 29 | + // CHECK-LABEL: fn use_checked_sub |
| 30 | + // CHECK: inlined{{.+}}u32{{.+}}checked_sub |
| 31 | + // CHECK: [[DELTA:_[0-9]+]] = SubUnchecked(copy _1, copy _2) |
| 32 | + // CHECK: [[TEMP1:_.+]] = Option::<u32>::Some(move [[DELTA]]); |
| 33 | + // CHECK: [[TEMP2:_.+]] = {{move|copy}} (([[TEMP1]] as Some).0: u32); |
| 34 | + // CHECK: do_something({{move|copy}} [[TEMP2]]) |
| 35 | + if let Some(delta) = x.checked_sub(rhs) { |
| 36 | + do_something(delta); |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +// EMIT_MIR checked_ops.saturating_sub_at_home.PreCodegen.after.mir |
| 41 | +pub fn saturating_sub_at_home(lhs: u32, rhs: u32) -> u32 { |
| 42 | + // FIXME(#138544): Similarly here, the `Option` ought to optimize away |
| 43 | + |
| 44 | + // CHECK-LABEL: fn saturating_sub_at_home |
| 45 | + // CHECK: [[DELTA:_[0-9]+]] = SubUnchecked(copy _1, copy _2) |
| 46 | + // CHECK: [[TEMP1:_.+]] = Option::<u32>::Some({{move|copy}} [[DELTA]]); |
| 47 | + // CHECK: [[TEMP2:_.+]] = {{move|copy}} (([[TEMP1]] as Some).0: u32); |
| 48 | + // CHECK: _0 = {{move|copy}} [[TEMP2]]; |
| 49 | + u32::checked_sub(lhs, rhs).unwrap_or(0) |
| 50 | +} |
| 51 | + |
| 52 | +unsafe extern "Rust" { |
| 53 | + safe fn do_something(_: u32); |
| 54 | +} |
0 commit comments