Skip to content

cmd/compile: run FullLTO pre-link optimization before bitcode emission - #356

Merged
zhouguangyuan0718 merged 1 commit into
go1.27.masterfrom
codex/full-lto-prelink
Oct 31, 2026
Merged

zhouguangyuan0718 merged 1 commit into
go1.27.masterfrom
codex/full-lto-prelink

Conversation

@zhouguangyuan0718

Copy link
Copy Markdown

LTO package compilation currently serializes prepared but unoptimized IR. Run LLVM's lto-pre-link<O2> pipeline before writing the package bitcode, leaving whole-program lto<O2> and late pre-codegen lowering to the linker. Ordinary object compilation keeps its existing O0/O2 selection.

The change reuses the compiler's existing optimization path. With -llvm-keep-ir, .raw.ll remains the frontend snapshot, .ll remains prepared IR, and .opt.ll now records the pre-link optimized LTO input. Verify the optimized module before serialization. Existing unsupported-flag checks remain unchanged.

The amd64/arm64 archive regression disables inlining and verifies that LLVM constant propagation removes a pure package-local call before bitcode serialization, while both definitions retain their original package symbol indices and the archive's export data remains usable. This regression fails against #355 before the change. Focused emission, early IR, optimization-mode and flag-rejection tests pass; ordinary CPU/FMV runtime behavior also passes.

End-to-end validation uses a separate checkout combining this patch with #347; the production PR remains based directly on the merged #355 commit 8053408d154c. The FullLTO CPU/FMV runtime and complete integration suite pass (265.422s), including content hashing, assembly, cache reuse, GC/stack growth, reflection, traceback, logical DWARF packages, linkname positive/negative cases, mixed ordinary objects, PIE and cgo automatic/external linking.

Performance qualification is still open. One macOS arm64 sample of the 45-package runtime fixture, with package caches warmed and the link forced fresh, gave:

Measurement Prepared IR only Pre-link O2
Input bitcode 16,095,200 B 18,193,840 B
Combined optimized bitcode 16,570,944 B 17,744,944 B
Executable 2,676,642 B 2,741,842 B
Warm-cache build wall time 16.39 s 17.05 s
Maximum RSS reported by time 1,531,494,400 B 1,567,326,208 B

This is a single sample, not a statistical benchmark or a measured general speedup. The size increase is a reason to keep this PR in draft for review. There are no custom LLVM pass lists or relaxed Go symbol-identity checks.

Builds on #355; companion to #347. Do not merge automatically.

@zhouguangyuan0718
zhouguangyuan0718 marked this pull request as ready for review October 31, 2026 12:30
@zhouguangyuan0718
zhouguangyuan0718 merged commit 42dc37c into go1.27.master Oct 31, 2026
11 checks passed
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.

1 participant