mirror of
https://github.com/rust-lang/rust.git
synced 2026-07-20 22:56:57 -04:00
7139a2b071
This optimisation is currently broken on s390x[^1]. It looks like a big-endian issue in general. but as we only know about the test fails on s390x we only disable it there. Should be reenabled when the problem is fixed and llvm backend is updated. [^1]: https://github.com/llvm/llvm-project/issues/208712
45 lines
1.4 KiB
Rust
45 lines
1.4 KiB
Rust
// `0..slice.len()` should propagate the same upper bound as
|
|
// `slice.iter().enumerate()`, allowing the checked index conversion to be
|
|
// removed inside the loop.
|
|
|
|
//@ compile-flags: -Copt-level=3
|
|
//@ only-64bit
|
|
//@ ignore-s390x OPT missing on s390x https://github.com/llvm/llvm-project/issues/208712
|
|
|
|
#![crate_type = "lib"]
|
|
|
|
use std::convert::TryFrom;
|
|
use std::hint::black_box;
|
|
|
|
// CHECK-LABEL: @score_round_enumerate
|
|
#[no_mangle]
|
|
pub fn score_round_enumerate(candidates: &[bool]) {
|
|
// The length check itself can still fail.
|
|
// CHECK: call void {{.*}}unwrap_failed
|
|
// But the checked conversion inside the loop should not add another panic path.
|
|
// CHECK-NOT: call void {{.*}}unwrap_failed
|
|
// CHECK: ret void
|
|
u32::try_from(candidates.len()).unwrap();
|
|
|
|
for (i, _) in candidates.iter().enumerate() {
|
|
u32::try_from(i).unwrap();
|
|
black_box(42);
|
|
}
|
|
}
|
|
|
|
// CHECK-LABEL: @score_round_range
|
|
#[no_mangle]
|
|
pub fn score_round_range(candidates: &[bool]) {
|
|
// The length check itself can still fail.
|
|
// CHECK: call void {{.*}}unwrap_failed
|
|
// But the checked conversion inside the loop should not add another panic path.
|
|
// CHECK-NOT: call void {{.*}}unwrap_failed
|
|
// CHECK: ret void
|
|
u32::try_from(candidates.len()).unwrap();
|
|
|
|
for i in 0..candidates.len() {
|
|
u32::try_from(i).unwrap();
|
|
black_box(42);
|
|
}
|
|
}
|