Skip to content

Commit 245cc23

Browse files
committed
add codegen test
The test confirms that when val < base, we do not divide or multiply.
1 parent 3b2436c commit 245cc23

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Diff for: tests/codegen/checked_ilog.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ compile-flags: -O
2+
3+
#![crate_type = "lib"]
4+
5+
// Ensure that when val < base, we do not divide or multiply.
6+
7+
// CHECK-LABEL: @checked_ilog
8+
// CHECK-SAME: (i16 noundef %val, i16 noundef %base)
9+
#[no_mangle]
10+
pub fn checked_ilog(val: u16, base: u16) -> Option<u32> {
11+
// CHECK-NOT: udiv
12+
// CHECK-NOT: mul
13+
// CHECK: %[[IS_LESS:.+]] = icmp ult i16 %val, %base
14+
// CHECK-NEXT: br i1 %[[IS_LESS]], label %[[TRUE:.+]], label %[[FALSE:.+]]
15+
// CHECK: [[TRUE]]:
16+
// CHECK-NOT: udiv
17+
// CHECK-NOT: mul
18+
// CHECK: ret { i32, i32 }
19+
val.checked_ilog(base)
20+
}

0 commit comments

Comments
 (0)