Skip to content

add llvm.assume bounds hints, full fast-math flags on all fp ops#492

Merged
cs01 merged 1 commit intomainfrom
feat/llvm-assume-bounds
Mar 20, 2026
Merged

add llvm.assume bounds hints, full fast-math flags on all fp ops#492
cs01 merged 1 commit intomainfrom
feat/llvm-assume-bounds

Conversation

@cs01
Copy link
Owner

@cs01 cs01 commented Mar 20, 2026

Summary

  • @llvm.assume after bounds checks — after a successful bounds check, emit call void @llvm.assume(i1 %in_bounds) to explicitly tell LLVM's optimizer that the index is valid. Zero runtime cost (assume generates no machine code). Enables SCEV to potentially eliminate redundant bounds checks in loops with monotonic access patterns.
  • Full fast-math flags on all floating-point operations — add nnan ninf to the existing nsz arcp contract reassoc afn flags on fadd, fsub, fmul, fdiv, frem, fneg. This tells LLVM it can assume no NaN/Infinity values, enabling more aggressive loop transforms and FP optimizations.
  • IR builder consistency — the emitFAdd/emitFSub/emitFMul/emitFDiv/emitFRem/emitFNeg builder functions now emit the same fast-math flags as the binary operator codegen path.

These are foundational optimizations that give LLVM's optimizer more information to work with. They don't produce measurable speedups on current benchmarks alone, but they're prerequisites for future optimizations (loop bounds check elimination, auto-vectorization) and ensure consistent optimization across all FP code paths.

Test plan

  • npm run verify:quick passes (tests + self-hosting Stage 1)
  • All existing tests pass unchanged (fast-math and assume are purely optimizer hints)

@github-actions
Copy link
Contributor

Benchmark Results (Linux x86-64)

Benchmark C ChadScript Go Node Bun Place
Binary Trees 1.390s 1.239s 2.710s 1.201s 0.934s 🥉
Cold Start 0.8ms 0.8ms 1.2ms 24.1ms 9.3ms 🥇
Fibonacci 0.818s 1.469s 1.561s 3.186s 1.943s 🥈
File I/O 0.119s 0.090s 0.088s 0.203s 0.174s 🥈
JSON Parse/Stringify 0.004s 0.005s 0.018s 0.015s 0.007s 🥈
Matrix Multiply 0.457s 0.699s 0.634s 0.365s 0.329s #5
Monte Carlo Pi 0.389s 0.410s 0.404s 2.247s 6.028s 🥉
N-Body Simulation 1.669s 2.119s 2.202s 2.386s 3.260s 🥈
Quicksort 0.214s 0.245s 0.213s 0.262s 0.226s #4
SQLite 0.350s 0.400s 0.431s 0.401s 🥈
Sieve of Eratosthenes 0.015s 0.027s 0.020s 0.039s 0.035s 🥉
String Manipulation 0.008s 0.045s 0.016s 0.037s 0.027s #5

CLI Tool Benchmarks

Benchmark ChadScript grep node xxd Place
Hex Dump 0.430s 1.018s 0.128s 🥈
Recursive Grep 0.019s 0.009s 0.094s 🥈

@cs01 cs01 merged commit 438c2c3 into main Mar 20, 2026
13 checks passed
@cs01 cs01 deleted the feat/llvm-assume-bounds branch March 20, 2026 22:55
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