Skip to content

Commit

Permalink
add codegen test
Browse files Browse the repository at this point in the history
The test confirms that when val < base, we do not divide or multiply.
  • Loading branch information
tspiteri committed Apr 23, 2024
1 parent 3b2436c commit 749d307
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/codegen/checked_ilog.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//@ compile-flags: -O

#![crate_type = "lib"]

// Ensure that when val < base, we do not divide or multiply.

// CHECK-LABEL: @checked_ilog
// CHECK-SAME: (i16 noundef %val, i16 noundef %base)
#[no_mangle]
pub fn checked_ilog(val: u16, base: u16) -> Option<u32> {
// CHECK-NOT: udiv
// CHECK-NOT: mul
// CHECK: %[[IS_LESS:.+]] = icmp ult i16 %val, %base
// CHECK: br i1 %[[IS_LESS]], label %[[TRUE:.+]], label %[[FALSE:.+]]
// CHECK: [[TRUE]]:
// CHECK-NOT: udiv
// CHECK-NOT: mul
// CHECK: ret { i32, i32 }
val.checked_ilog(base)
}

0 comments on commit 749d307

Please sign in to comment.