Closed
Description
Consider code like this:
#![feature(core_intrinsics)]
pub fn method(a: usize, b: usize) -> usize {
a.wrapping_sub(b)
}
pub fn intrinsic(a: usize, b: usize) -> usize {
std::intrinsics::wrapping_sub(a, b)
}
at -Copt-level=1
and lower, the generated assembly for versions with the method call will generate a function call, rather than direct operation. Once the inlining fails, other optimisations that could be done are inhibited, especially at -Copt-level=1`.
More generally speaking, I wonder if we might want to make these methods have a special annotation that would make the compiler generate the instructions directly much like it does for intrinsics right now. These seem like basic enough that #[inline(always)]
might not be good enough (it being just a hint) and also possibly more expensive than necessary (something needs to do the inlining still).