Skip to content

Optimizer: code generator's CPU for the cost model, --size_level at every level, inlining of functions with a try off Windows - #804

Merged
ASDAlexander77 merged 1 commit into
mainfrom
claude/vigilant-brahmagupta-9oymny
Nov 10, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
claude/vigilant-brahmagupta-9oymny

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Four fixes from a review of how the MLIR and LLVM optimization passes are scheduled.

This has not been compiled or run locally (no LLVM 22 build was available where it was written), so CI is the first build and test of it.

Changes

  1. The optimizer uses the code generator's target machine. getTransformer takes a TargetMachine. The JIT, the JIT cache and object emission pass the one they generate code with; --emit=llvm / --emit=bc still build one from the module triple and -mcpu / -mattr. Before, every caller passed null, and under the JIT the cost model described a generic CPU while the code was generated for the host.

  2. A function with a personality is noinline only on Windows. That is where Win32ExceptionPass rewrites landing pads into funclets. Elsewhere a function with a try or a using can now be inlined by LLVM. The MLIR inliner still refuses these functions.

  3. --size_level works at any --opt_level above 0. 1 selects -Os, 2 selects -Oz; functions are marked optsize / minsize as clang does, and object code is generated at the -O2 level. It was read only beside --opt_level=2, and the default level is 3.

  4. The MLIR loop-invariant code motion pass is no longer scheduled. While, DoWhile and For are lowered to branches before it ran, so it had nothing to act on. LLVM's LICM is unaffected.

What to look at

  • Change 2 is the risky one. It relies on LLVM's inliner handling the Itanium landing pads this compiler emits. The exception tests (try/catch/finally, using, the rc/own cleanup cases) under --opt on Linux are the ones that would show a problem. Reverting it is the one if in lib/TypeScript/LowerToLLVM.cpp.
  • Behaviour change in 3: --opt_level=1 --size_level=1 meant -O1 and now means -Os; a size level above 2 is now an error at every opt level.
  • JIT cache: the cache key is unchanged, so objects cached before change 1 are reused until the cache is cleared.

Generated by Claude Code

…at every level, inlining of functions with a try off Windows

- The LLVM optimizer is handed the TargetMachine the code is generated with
  (the JIT's host machine, the object file's) instead of building one from
  -mcpu/-mattr, which under the JIT described a generic CPU while the code
  was generated for the host.
- --size_level selects -Os/-Oz at any --opt_level above 0 (it was read only
  beside --opt_level=2, and the default is 3), marks functions optsize /
  minsize as clang does, and generates code at the -O2 level.
- A function with a personality is noinline only on Windows, where
  Win32ExceptionPass rewrites its landing pads into funclets.
- The MLIR loop-invariant code motion pass is no longer scheduled: loops
  are lowered to branches before it ran, so it had nothing to act on.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8KRfVk4FT2FALW47Ux2Fp
@ASDAlexander77
ASDAlexander77 merged commit d78c735 into main Nov 10, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the claude/vigilant-brahmagupta-9oymny branch November 10, 2026 12:27
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