Skip to content

At opt-levels <= 1 the arithmetic operation methods do not get inlined, preventing other optimisations #75598

Closed
@nagisa

Description

@nagisa

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)
}

compiler explorer

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-slowIssue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions