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

Turns out that all uses were effectively equivalent to using
sess.opts.optimize.
@rust-bors

rust-bors Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #165597) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants