Skip to content

Commit 69b380d

Browse files
committed
Auto merge of #128584 - DianQK:tests-for-llvm-19, r=nikic
Add a set of tests for LLVM 19 Close #107681. Close #118306. Close #126585. r? compiler
2 parents 68d2e8a + b5c453d commit 69b380d

File tree

3 files changed

+67
-0
lines changed

3 files changed

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

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

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)