Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/attributes/codegen.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,6 @@ The *`optimize` [attribute]* suggests an optimization goal for the attributed fu
> pub fn example3() {}
> ```

> [!NOTE]
> For `rustc`, `-C opt-level=0` (the default) disables LLVM optimizations for the entire crate, and `optimize(size)` and `optimize(speed)` do not enable them for the attributed function. `rustc` still applies its own optimizations, other than inlining, to such a function.

r[attributes.codegen.optimize.syntax]
The syntax for the `optimize` attribute is:

Expand Down Expand Up @@ -368,6 +365,11 @@ The `optimize` attribute supports these modes:
>
> Settings that base their defaults on the optimization level, such as debug assertions and overflow checks, ignore this attribute and use the crate's optimization level.

> [!NOTE]
> For `rustc`, `#[optimize(size)]` and `#[optimize(speed)]` don't have much effect with `-C opt-level=0` (the default). This is because `-C opt-level=0` disables most of the LLVM optimization pipeline and these attributes do not enable it for attributed functions.
>
> Applying `#[optimize(size)]` to a function suggests you would prefer a smaller size over more speed for that function; applying `#[optimize(speed)]` suggests you would prefer more speed over a smaller size. Under optimization, `rustc` tries to give effect to these preferences.

r[attributes.codegen.optimize.inline]
`#[optimize(none)]` may not be used with `#[inline]` or `#[inline(always)]` on the same function. It may be used with `#[inline(never)]`. (See [attributes.codegen.inline.optimize].)

Expand Down
Loading