Skip to content

Remove backend_optimization_level. - #165586

Open
veluca93 wants to merge 1 commit into
rust-lang:mainfrom
veluca93:cleanup-opt-speed
Open

veluca93 wants to merge 1 commit into
rust-lang:mainfrom
veluca93:cleanup-opt-speed

Conversation

@veluca93

@veluca93 veluca93 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Turns out that all uses were effectively equivalent to using sess.opts.optimize.

In particular, the output of that function was only ever passed to target_machine_factory, which ignores it on anything but llvm, and on llvm it only passed it to to_llvm_opt_settings, where the difference between Size/SizeMin/More is only the second return value, which is immediately dropped. So replacing all uses of backend_optimization_level with sess.opts.optimize is effectively equivalent.

LLM usage: I asked $LLM to review the commit, and it didn't complain about anything. Also $LLM initially figured out (and I confirmed) that backend_optimization_level was effectively a no-op.

@rustbot

rustbot commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

rustc_codegen_gcc is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_gcc instead.

cc @antoyo, @GuillaumeGomez

rustc_codegen_cranelift is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_cranelift instead.

cc @bjorn3

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 7, 2026
@rustbot

rustbot commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: codegen, compiler
  • codegen, compiler expanded to 79 candidates
  • Random selection from 23 candidates

@RalfJung

RalfJung commented Nov 7, 2026

Copy link
Copy Markdown
Member

Cc @nikic

) -> TargetMachineFactoryFn<Self> {
back::write::target_machine_factory(sess, optlvl)
fn target_machine_factory(&self, sess: &Session) -> TargetMachineFactoryFn<Self> {
back::write::target_machine_factory(sess, sess.opts.optimize)

@bjorn3 bjorn3 Nov 7, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be changed to only accept sess?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was considering that, but there is a "create_informational_machine" (or thereabouts) function that passes OptLevel::No, and I was unsure whether passing the opt level there would cause perf regressions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That function is only used for fetching information from LLVM, not for any actual compilation, so I think it would't affect performance at all, but I don't know if LLVM does some work on creating the optimization pipeline in advance when creating a target machine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's exactly my doubt too :-)

@nikic nikic left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original intent was presumably to hook this up to the PassBuilder opt level, but given that this didn't actually happen and would not do anything on current LLVM anymore, dropping it entirely makes sense.

View changes since this review

@rust-bors

This comment has been minimized.

@JohnTitor JohnTitor added the llm-assisted An LLM-assisted PR as defined by the LLM policy. Requires ahead-of-time consent by assignee. label Nov 7, 2026
@JohnTitor

Copy link
Copy Markdown
Member

r? nikic

@rustbot rustbot assigned nikic and unassigned JohnTitor Nov 7, 2026
@rustbot

rustbot commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer

This comment has been minimized.

Turns out that all uses were effectively equivalent to using
sess.opts.optimize.
@nikic

nikic commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-bors Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

📌 Commit b52077c has been approved by nikic

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 10, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 10, 2026
Remove `backend_optimization_level`.

Turns out that all uses were effectively equivalent to using sess.opts.optimize.

In particular, the output of that function was only ever passed to target_machine_factory, which ignores it on anything but llvm, and on llvm it only passed it to to_llvm_opt_settings, where the difference between Size/SizeMin/More is only the second return value, which is immediately dropped. So replacing all uses of backend_optimization_level with sess.opts.optimize is effectively equivalent.

LLM usage: I asked $LLM to review the commit, and it didn't complain about anything. Also $LLM initially figured out (and I confirmed) that backend_optimization_level was effectively a no-op.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 10, 2026
Remove `backend_optimization_level`.

Turns out that all uses were effectively equivalent to using sess.opts.optimize.

In particular, the output of that function was only ever passed to target_machine_factory, which ignores it on anything but llvm, and on llvm it only passed it to to_llvm_opt_settings, where the difference between Size/SizeMin/More is only the second return value, which is immediately dropped. So replacing all uses of backend_optimization_level with sess.opts.optimize is effectively equivalent.

LLM usage: I asked $LLM to review the commit, and it didn't complain about anything. Also $LLM initially figured out (and I confirmed) that backend_optimization_level was effectively a no-op.
rust-bors Bot pushed a commit that referenced this pull request Nov 10, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - #165575 (Upgrade bundled musl to 1.2.6)
 - #163992 (add `core::arch::{x86, x86_64}::x87_f80`)
 - #165117 (std: use skip_unsupported_miri_tests to control when tests should be skipped in Miri due to missing shims)
 - #165458 (fix incorrect byte count suffix on MSVC)
 - #165487 (Migrate built-in macros `pattern_type` & `view_type` to macros 2.0 that expand to internal syntax)
 - #165490 (Mark the compile unit for `-Zdebuginfo-for-profiling`)
 - #165586 (Remove `backend_optimization_level`.)
 - #165646 (fix NumScalableVectors::from_field_count)
 - #165655 (Unignore passing GCC backend tests)
 - #165740 (miri subtree update)
 - #164559 (Windows: fix Dir::remove and Dir::rename following symlinks)
 - #165682 (interpret: ensure newly created unions have uninit in their padding)
 - #165693 (Move `check_attr` to attribute parsing)
 - #165715 (windows: check for null before wide encoding)
 - #165717 (mpsc_sync::stream_send_recv_stress: wait for all threads to finish)
 - #165733 (docs(num): remove needless whitespaces)

Failed merges:

 - #165727 (Normalize "beta release channel" in `const-supertrait-unstable` test)
 - #153261 (Partially stabilize `ptr_alignment_type` as `alignment_type`)
 - #164218 (Tweak private re-export errors to point at correct span and have more context)
 - #165709 (remove 'x miri' smoke test from PR CI)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. llm-assisted An LLM-assisted PR as defined by the LLM policy. Requires ahead-of-time consent by assignee. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants