I tried this code:
pub unsafe fn normal(x: &[u8]) -> bool {
if x.len() < 16 {
std::hint::cold_path();
slow();
return false;
}
x[..16] == [0; 16]
}
#[target_feature(enable = "sse2")]
pub unsafe fn with_feature(x: &[u8]) -> bool {
if x.len() < 16 {
std::hint::cold_path();
slow();
return false;
}
x[..16] == [0; 16]
}
unsafe extern "C" {
safe fn slow();
}
I expected to see this happen: I expected both to have identical code generation.
Instead, this happened: when target_feature is enabled it compiles as if the cold_path() isn't there. See this godbolt:
example[88559e5427b91048]::normal:
cmp rsi, 15
jbe .LBB1_1
mov rax, qword ptr [rdi]
or rax, qword ptr [rdi + 8]
sete al
ret
.LBB1_1:
push rax
call qword ptr [rip + slow@GOTPCREL]
xor eax, eax
add rsp, 8
ret
example[88559e5427b91048]::with_feature:
cmp rsi, 16
jae .LBB0_1
push rax
call qword ptr [rip + slow@GOTPCREL]
xor eax, eax
add rsp, 8
ret
.LBB0_1:
mov rax, qword ptr [rdi]
or rax, qword ptr [rdi + 8]
sete al
ret
Note that target_feature(enable = "sse2") should be a no-op, both functions are compiled with SSE2 support anyway.
Meta
Occurs on both latest nightly and 1.95.
I tried this code:
I expected to see this happen: I expected both to have identical code generation.
Instead, this happened: when
target_featureis enabled it compiles as if thecold_path()isn't there. See this godbolt:Note that
target_feature(enable = "sse2")should be a no-op, both functions are compiled with SSE2 support anyway.Meta
Occurs on both latest nightly and 1.95.