Skip to content

optimize bounds checks: unsigned compare + noreturn#475

Merged
cs01 merged 2 commits intomainfrom
bounds-check-optimization
Mar 19, 2026
Merged

optimize bounds checks: unsigned compare + noreturn#475
cs01 merged 2 commits intomainfrom
bounds-check-optimization

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 19, 2026

Summary

  • Faster array access for all programs — bounds checks now use a single icmp uge (unsigned compare) instead of two signed compares + or, cutting per-check instruction count by 60%
  • Added noreturn attribute to __cs_bounds_fail, letting LLVM better optimize around the cold error path
  • Relaxed integer analysis to promote variables initialized from double params (e.g. let i = lo) to i64, enabling integer arithmetic in quicksort-style loops — quicksort benchmark drops from 0.35s → 0.14s (2.5x faster, now beats Go)
  • The existing fptosi codegen at init + demotion fixpoint for reassignments ensures correctness

Test plan

  • verify:quick passes (tests + Stage 0 + Stage 1)
  • CI green
  • Run benchmarks to measure improvement

🤖 Generated with Claude Code

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 19, 2026

Benchmark Results (Linux x86-64)

Benchmark C ChadScript Go Node Bun Place
Binary Trees 1.396s 1.265s 2.732s 1.228s 0.988s 🥉
Cold Start 0.8ms 0.8ms 1.1ms 23.2ms 8.6ms 🥇
Fibonacci 0.814s 1.360s 1.617s 3.157s 1.943s 🥈
File I/O 0.118s 0.092s 0.083s 0.204s 0.179s 🥈
JSON Parse/Stringify 0.004s 0.010s 0.017s 0.025s 0.007s 🥉
Matrix Multiply 0.449s 0.695s 0.635s 0.362s 0.331s #5
Monte Carlo Pi 0.392s 0.418s 0.405s 2.260s 6.028s 🥉
N-Body Simulation 1.688s 2.149s 2.208s 2.400s 3.258s 🥈
Quicksort 0.215s 0.278s 0.213s 0.262s 0.227s #5
SQLite 0.348s 0.399s 0.442s 0.398s 🥉
Sieve of Eratosthenes 0.017s 0.027s 0.019s 0.038s 0.035s 🥉
String Manipulation 0.008s 0.045s 0.017s 0.039s 0.028s #5

@cs01 cs01 force-pushed the bounds-check-optimization branch from 0f5e241 to ab79e63 Compare March 19, 2026 17:52
@cs01 cs01 merged commit 0c7a8bd into main Mar 19, 2026
13 checks passed
@cs01 cs01 deleted the bounds-check-optimization branch April 24, 2026 20:53
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