forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//@ compile-flags: -O | ||
//@ min-llvm-version: 19 | ||
|
||
// Test for #107681. | ||
// Make sure we don't create `br` or `select` instructions. | ||
|
||
#![crate_type = "lib"] | ||
|
||
use std::iter::Copied; | ||
use std::slice::Iter; | ||
|
||
#[no_mangle] | ||
pub unsafe fn foo(x: &mut Copied<Iter<'_, u32>>) -> u32 { | ||
// CHECK-LABEL: @foo( | ||
// CHECK-NOT: br | ||
// CHECK-NOT: select | ||
// CHECK: [[RET:%.*]] = load i32, ptr | ||
// CHECK-NEXT: ret i32 [[RET]] | ||
x.next().unwrap_unchecked() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//@ compile-flags: -O | ||
//@ min-llvm-version: 19 | ||
|
||
// Test for #118306. | ||
// Make sure we don't create `br` or `select` instructions. | ||
|
||
#![crate_type = "lib"] | ||
|
||
#[no_mangle] | ||
pub fn branchy(input: u64) -> u64 { | ||
// CHECK-LABEL: @branchy( | ||
// CHECK-NEXT: start: | ||
// CHECK-NEXT: [[_2:%.*]] = and i64 [[INPUT:%.*]], 3 | ||
// CHECK-NEXT: [[SWITCH_GEP:%.*]] = getelementptr inbounds [4 x i64], ptr @switch.table.branchy, i64 0, i64 [[_2]] | ||
// CHECK-NEXT: [[SWITCH_LOAD:%.*]] = load i64, ptr [[SWITCH_GEP]] | ||
// CHECK-NEXT: ret i64 [[SWITCH_LOAD]] | ||
match input % 4 { | ||
1 | 2 => 1, | ||
3 => 2, | ||
_ => 0, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//@ compile-flags: -Copt-level=s | ||
//@ min-llvm-version: 19 | ||
|
||
// Test for #126585. | ||
// Ensure that this IR doesn't have extra undef phi input, which also guarantees that this asm | ||
// doesn't have subsequent labels and unnecessary `jmp` instructions. | ||
|
||
#![crate_type = "lib"] | ||
|
||
#[no_mangle] | ||
fn checked_div_round(a: u64, b: u64) -> Option<u64> { | ||
// CHECK-LABEL: @checked_div_round | ||
// CHECK: phi | ||
// CHECK-NOT: undef | ||
// CHECK: phi | ||
// CHECK-NOT: undef | ||
match b { | ||
0 => None, | ||
1 => Some(a), | ||
// `a / b` is computable and `(a % b) * 2` can not overflow since `b >= 2`. | ||
b => Some(a / b + if (a % b) * 2 >= b { 1 } else { 0 }), | ||
} | ||
} |