Skip to content

IRGen: Switch LLVM pipeline optimization level from Os to O2#89632

Draft
AnthonyLatsis wants to merge 2 commits into
mainfrom
jepa-main2
Draft

IRGen: Switch LLVM pipeline optimization level from Os to O2#89632
AnthonyLatsis wants to merge 2 commits into
mainfrom
jepa-main2

Conversation

@AnthonyLatsis

@AnthonyLatsis AnthonyLatsis commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Os is gone upstream: llvm/llvm-project#191363. This change can only affect -O builds:

  • We always emit IR functions with the optsize and minsize attributes in -Osize mode:
    if (FuncOptMode == OptimizationMode::NotSet)
    FuncOptMode = IRGen.Opts.OptMode;
    if (FuncOptMode == OptimizationMode::ForSize) {
    Attrs.addAttribute(llvm::Attribute::OptimizeForSize);
    Attrs.addAttribute(llvm::Attribute::MinSize);
    } else {
    .
  • The only place in LLVM where pipeline Os matters is FunctionSpecializer, where we already skip functions with the optsize or minsize attribute.

@AnthonyLatsis

Copy link
Copy Markdown
Collaborator Author

@swift-ci please benchmark

@kavon kavon left a comment

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.

LGTM assuming no significant changes in the benchmark results

Comment thread lib/IRGen/IRGen.cpp Outdated
// Splitting trades code size to enhance memory locality, avoid in -Osize.
DoHotColdSplit = Opts.EnableHotColdSplit && !Opts.optimizeForSize();
level = llvm::OptimizationLevel::Os;
level = llvm::OptimizationLevel::O2;

@hamishknight hamishknight Jun 2, 2026

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.

Can you add a comment here covering what you have in the PR description? Just so it's obvious for future folks reading the code

@AnthonyLatsis AnthonyLatsis changed the title [IRGen: Switch LLVM pipeline optimization level from Os to O2 IRGen: Switch LLVM pipeline optimization level from Os to O2 Jun 4, 2026
@AnthonyLatsis

Copy link
Copy Markdown
Collaborator Author

@swift-ci please benchmark

@AnthonyLatsis

Copy link
Copy Markdown
Collaborator Author

We got improvements and regressions. Now trying Os → O2 plus adding the optsize attribute in -O mode, not just in -Osize mode.

Os is gone upstream: llvm/llvm-project#191363.
This can only affect `-O` builds:
* We always emit IR functions with the `optsize` and `minsize`
  attributes in `-Osize` mode.
* The only place in LLVM where pipeline Os matters is
  `FunctionSpecializer`, where we already skip functions with the
  `optsize` or `minsize` attribute.
@AnthonyLatsis

Copy link
Copy Markdown
Collaborator Author

@swift-ci please benchmark

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants