#optimization-passes #llvm-ir #diff #display #pager

app optdiff

A CLI tool that displays diffs of LLVM IR changes between optimization passes

1 unstable release

0.8.0 Dec 20, 2025

#13 in #optimization-passes

BSD-2-Clause

60KB
853 lines

optdiff

optdiff is a CLI tool that displays differences in LLVM IR between optimization passes. It's a standalone port of the Compiler Explorer optpipeline feature.

For the best experience, install one of these diff visualization tools:

Usage

Consider this example square.c file:

int square(int x) {
    return x * x;
}

You can run optdiff directly with the compiler output:

clang square.c -O2 -mllvm -print-before-all -mllvm -print-after-all -c -o /dev/null 2>&1 | optdiff

Alternatively, you can save the pass dump to a file and process it later:

clang square.c -O2 -mllvm -print-before-all -mllvm -print-after-all -c -o /dev/null &> dump.txt
optdiff dump.txt

By default, optdiff will try to use delta, then riff, then fall back to less as the pager. You can configure the pager:

  • Use the --pager or -p option: optdiff dump.txt -p bat
  • Set the OPTDIFF_PAGER environment variable: OPTDIFF_PAGER=bat optdiff dump.txt

To skip passes that don't modify the IR, use the --skip-unchanged or -s option:

optdiff dump.txt -s

For a complete list of available options:

optdiff --help

Dependencies

~11–18MB
~355K SLoC