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.
https://github.com/rust-lang/rust/blob/1.21.0/src/liballoc_system/lib.rs#L24-L26 defines a
MIN_ALLOCconstant with this comment:However,
System.alloc()and friends are typically not used directly but fromstd::heap::Heap.alloc()and through symbols like:This indirection allows
#[global_allocator]to change which allocatorHeapuses. Doesn’t it also prevent inlining, constant-propagation of the alignment value, and elimination of the branch on comparing withMIN_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.