Loading the code workspace…
Implement a peephole optimizer for x86 assembly or TAC.
Implement pattern matching for:
Create a pattern database:
Handle these specific patterns (minimum):
mov X, X → removeadd X, 0 → removemul X, 1 → removemul X, 0 → mov X, 0mul X, 2^n → shl X, njmp L; L: → remove jumpRun until fixed point (no more matches)
Peephole passes — deleting push/pop pairs, folding add 0, combining moves — run late in GCC, LLVM, and every JIT; V8 applies them to bytecode and WebAssembly modules get them from Binaryen's wasm-opt. Small and local, they are collectively worth several percent on real workloads and are historically the first optimization new compiler engineers write.
Sample case for Run. Submit grades this sample plus all hidden tests.