File tree Expand file tree Collapse file tree 3 files changed +63
-0
lines changed Expand file tree Collapse file tree 3 files changed +63
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments