NewsCrawler.org

AI agent rewrites machine code faster than -O3, with equivalence proven in Lean 4

AIに直接バイナリを編集させたら、コンパイラの-O3よりも早くなり、その正しさもLean 4で証明できた話
Image: zenn.dev

The article describes an extension of NoCompiler[1], a tool that applies a Rust-like type system to assembly code to check memory safety, with the soundness of that checker proven in Lean 4. The new feature checks functional equivalence between two machine-code programs, and an AI agent was asked to optimize machine code that a compiler had generated.

The agent makes the optimizations, but a separate formal verifier checks that they are correct, not the agent itself. In experiments on functions from TensorFlow Lite Micro, libfixmath and ESP-DSP, the optimized code reduced the estimated CPU cycle count by up to 66% compared with code compiled with -O3, and the equivalence of the before and after versions is proven in Lean 4. Equivalence is defined as observational equivalence[2]: the return registers, memory outside the function's stack, the jump target, the exit state and external events must match, while temporary registers and instruction counts may differ. For a pair of programs the article uses partial equivalence[3]: if the precondition holds and both programs finish, their observable results must match.

To check equivalence on straight-line code, the tool uses symbolic execution[4], replacing register values with symbols and formulas, then normalizing the formulas into a common linear form and treating carries from additions wider than a register as overflow terms. As an example, multiplying by 9 is rewritten as a single sh3add instruction from the RISC-V Zba extension, and both versions are shown to compute 9x mod 2^64.

Read the original zenn.dev

Sources

  • Zenn JA

    AIに直接バイナリを編集させたら、コンパイラの-O3よりも早くなり、その正しさもLean 4で証明できた話

    4 likes1 bookmark0 comments

Published: First seen: Читать по-русски

Open as a page