Open
Description
I assume the following two functions behave identically, and therefore should result in the same codegen. https://godbolt.org/z/vj9ornqbG
#[no_mangle]
pub fn cast(x: bool) -> f32 {
x as u8 as f32
}
#[no_mangle]
pub fn ifelse(x: bool) -> f32 {
if x { 1. } else { 0. }
}
However, ifelse
fails to be optimised to a cast.
cast:
cvtsi2ss xmm0, edi
ret
.LCPI1_0:
.long 0x3f800000
ifelse:
test edi, edi
jne .LBB1_1
xorps xmm0, xmm0
ret
.LBB1_1:
movss xmm0, dword ptr [rip + .LCPI1_0]
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment