Skip to content

Does inlining work through the __rust_alloc symbol? #45831

Closed
@SimonSapin

Description

@SimonSapin

https://github.com/rust-lang/rust/blob/1.21.0/src/liballoc_system/lib.rs#L24-L26 defines a MIN_ALLOC constant with this comment:

// The minimum alignment guaranteed by the architecture. This value is used to
// add fast paths for low alignment values. In practice, the alignment is a
// constant at the call site and the branch will be optimized out.

However, System.alloc() and friends are typically not used directly but from std::heap::Heap.alloc() and through symbols like:

extern "Rust" {
    fn __rust_alloc(size: usize, align: usize, err: *mut u8) -> *mut u8;
}

This indirection allows #[global_allocator] to change which allocator Heap uses. Doesn’t it also prevent inlining, constant-propagation of the alignment value, and elimination of the branch on comparing with MIN_ALIGN? Or can (Thin)LTO “see through” that indirection?

If the branch is not eliminated that’s probably OK, its cost is probably small compared to the total cost of performing allocation. But if the second sentence of that comment is wrong we might want to remove it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions