Skip to content

Fixes -o:size - #7440

Merged
gingerBill merged 1 commit into
odin-lang:masterfrom
corleypc:osize-fix
Aug 24, 2026
Merged

Fixes -o:size#7440
gingerBill merged 1 commit into
odin-lang:masterfrom
corleypc:osize-fix

Conversation

@corleypc

Copy link
Copy Markdown
Contributor

The -o:size optimization level currently doesn't work, it occasionally produces code bigger than o:speed.

This PR fixes it by adding the optsize attribute per procedure at this optimization level. Optsize is then consulted by most of the passes.

On Linux, x64, default target, -o:size, LLVM 22, compiling examples/demo.odin I get

demo.odin code section .rodata filesize
before 331350 29248 540200
after 240342 26736 447832

or around 27% smaller code and around 17% smaller binary.

Note that one of the tests (union_in_aggregates in tests/internal/test_union_const.odin) segfaults at -o:size (Linux, x64, default target (SSE), LLVM 22) due to hitting one of the compiler's alignment bugs. On my pc the test is working by accident at o:speed, -o:minimal and -o:none (an align-1 alloca's (u in the test) field happens to land at alignment 16 (type alignment required and assumed for indirect args), which satisfies the movdqa instruction issued, but -o:size happens to change the stack layout and the same align-1alloca lands at alignment 8, causing the segfault). This bug is fixed in #7382 by copying underaligned indirect args to aligned temp before passing.

@corleypc

corleypc commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Looks like Intel based CI test failures are unrelated and come from #7434

@gingerBill
gingerBill merged commit 125ae35 into odin-lang:master Aug 24, 2026
3 of 8 checks passed
@corleypc
corleypc deleted the osize-fix branch August 24, 2026 13:25
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.

2 participants