Skip to content

Set optsize and minsize fun attributes for the -Os and -Oz optimization modes#16983

Open
ysbaddaden wants to merge 2 commits into
crystal-lang:masterfrom
ysbaddaden:fix/llvm-optsize-and-minsize-optimization-modes
Open

Set optsize and minsize fun attributes for the -Os and -Oz optimization modes#16983
ysbaddaden wants to merge 2 commits into
crystal-lang:masterfrom
ysbaddaden:fix/llvm-optsize-and-minsize-optimization-modes

Conversation

@ysbaddaden
Copy link
Copy Markdown
Collaborator

LLVM 23 removes the PassBuilder support for default<Os> and default<Oz> that was introduced in LLVM 17.

Instead, we shall use the default<O2> optimization level, and set the optsize (-Os) or minsize (-Oz) function attribute to every functions, which has the same behavior. This in turn enables support for -Oz and -Oz for LLVM 13 to 16.

I manually tested against different LLVM versions (15, 18, 21 and 23): -Os is smaller than any -O0 to -O3 level, and -Oz is even smaller.

closes #16895
related to #14463

…on modes

LLVM 23 removed the PassBuilder support for default<Os> and default<Oz>
that was introduced in LLVM 17.

We now use the default<O2> optimization level, and set the optsize (Os)
or minsize (Oz) function attribute to every functions, which has the
same behavior.

Bonus: this enables support for -Oz and -Oz for LLVM 13-16.
@ysbaddaden ysbaddaden self-assigned this May 19, 2026
@ysbaddaden ysbaddaden changed the title Set optsize and minsize fun attributes for the -Os and -Oz optimization modes Set optsize and minsize fun attributes for the -Os and -Oz optimization modes May 19, 2026
Comment thread src/compiler/crystal/program.cr Outdated
@straight-shoota straight-shoota added this to the 1.21.0 milestone May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-Os and -Oz will be removed in LLVM 23

3 participants