Skip to content

Commit 6251df7

Browse files
committed
Add a set of tests for LLVM 19
1 parent 1df0458 commit 6251df7

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-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

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ compile-flags: -O
2+
//@ min-llvm-version: 19
3+
4+
// Test for #118306.
5+
// Make sure we don't create `br` or `select` instructions.
6+
7+
#![crate_type = "lib"]
8+
9+
#[no_mangle]
10+
pub fn branchy(input: u64) -> u64 {
11+
// CHECK-LABEL: @branchy(
12+
// CHECK-NEXT: start:
13+
// CHECK-NEXT: [[_2:%.*]] = and i64 [[INPUT:%.*]], 3
14+
// CHECK-NEXT: [[SWITCH_GEP:%.*]] = getelementptr inbounds [4 x i64], ptr @switch.table.branchy, i64 0, i64 [[_2]]
15+
// CHECK-NEXT: [[SWITCH_LOAD:%.*]] = load i64, ptr [[SWITCH_GEP]]
16+
// CHECK-NEXT: ret i64 [[SWITCH_LOAD]]
17+
match input % 4 {
18+
1 | 2 => 1,
19+
3 => 2,
20+
_ => 0,
21+
}
22+
}

tests/codegen/issues/issue-126585.rs

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

0 commit comments

Comments
 (0)