Skip to content

Commit 1987f15

Browse files
authored
Rollup merge of rust-lang#128584 - DianQK:tests-for-llvm-19, r=nikic
Add a set of tests for LLVM 19 Close rust-lang#107681. Close rust-lang#118306. Close rust-lang#126585. r? compiler
2 parents cbe04ac + d432330 commit 1987f15

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ compile-flags: -O
2+
//@ min-llvm-version: 19
3+
4+
// Test for #107681.
5+
// Make sure we don't create `br` or `select` instructions.
6+
7+
#![crate_type = "lib"]
8+
9+
use std::iter::Copied;
10+
use std::slice::Iter;
11+
12+
#[no_mangle]
13+
pub unsafe fn foo(x: &mut Copied<Iter<'_, u32>>) -> u32 {
14+
// CHECK-LABEL: @foo(
15+
// CHECK-NOT: br
16+
// CHECK-NOT: select
17+
// CHECK: [[RET:%.*]] = load i32, ptr
18+
// CHECK-NEXT: ret i32 [[RET]]
19+
x.next().unwrap_unchecked()
20+
}

tests/codegen/issues/issue-118306.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ compile-flags: -O -Zno-jump-tables
2+
//@ min-llvm-version: 19
3+
4+
// Test for #118306.
5+
// Ensure that the default branch is optimized to be unreachable.
6+
7+
#![crate_type = "lib"]
8+
9+
#[no_mangle]
10+
pub fn foo(input: u64) -> u64 {
11+
// CHECK-LABEL: @foo(
12+
// CHECK: switch {{.*}}, label %[[UNREACHABLE:.*]] [
13+
// CHECK: [[UNREACHABLE]]:
14+
// CHECK-NEXT: unreachable
15+
match input % 4 {
16+
1 | 2 => 1,
17+
3 => 2,
18+
_ => 0,
19+
}
20+
}

tests/codegen/issues/issue-126585.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ compile-flags: -Copt-level=s
2+
//@ min-llvm-version: 19
3+
4+
// Test for #126585.
5+
// Ensure that this IR doesn't have extra undef phi input, which also guarantees that this asm
6+
// doesn't have subsequent labels and unnecessary `jmp` instructions.
7+
8+
#![crate_type = "lib"]
9+
10+
#[no_mangle]
11+
fn checked_div_round(a: u64, b: u64) -> Option<u64> {
12+
// CHECK-LABEL: @checked_div_round
13+
// CHECK: phi
14+
// CHECK-NOT: undef
15+
// CHECK: phi
16+
// CHECK-NOT: undef
17+
match b {
18+
0 => None,
19+
1 => Some(a),
20+
// `a / b` is computable and `(a % b) * 2` can not overflow since `b >= 2`.
21+
b => Some(a / b + if (a % b) * 2 >= b { 1 } else { 0 }),
22+
}
23+
}

0 commit comments

Comments
 (0)