LLVM-EXEGESIS(1)

๐Ÿ’– NAME

llvm-exegesis(1) โ€” LLVM Machine Instruction Benchmark. Bestie, this is the tool that measures what your CPU is actually doing at the instruction level, and she is so powerful. โœจ

โœจ SYNOPSIS โœจ

llvm-exegesis [options]

๐ŸŒธ DESCRIPTION ๐ŸŒธ

Okay so llvm-exegesis is a benchmarking tool that uses info available in LLVM to measure host machine instruction characteristics like latency, throughput, or port decomposition. No cap, that's the whole vibe.

Given an LLVM opcode name and a benchmarking mode, llvm-exegesis generates a code snippet that makes execution as serial (or as parallel, respectively) as possible so we can measure the latency (or inverse throughput/uop decomposition) of the instruction. The snippet is jitted and, unless you request otherwise, executed on the host subtarget. The time taken (or resource usage, respectively) is measured using hardware performance counters. The result is printed out as YAML to the standard output. ๐Ÿ’…

The main goal of this tool is to automatically (in)validate LLVM's TableDef scheduling models. To that end, we also provide analysis of the results. Obsessed, honestly.

llvm-exegesis can also benchmark arbitrary user-provided code snippets. Main character energy fr fr.

๐Ÿฆ‹ SUPPORTED PLATFORMS ๐Ÿฆ‹

llvm-exegesis currently only supports X86 (64-bit only), ARM (AArch64 only, snippet generation is sparse), MIPS, PowerPC (PowerPC64LE only) and RISC-V (RV64I/E and RV32I/E) on Linux for benchmarking. Not all benchmarking functionality is guaranteed to work on every platform. llvm-exegesis also has a separate analysis mode that is supported on every platform that LLVM is.

To enable benchmarking in llvm-exegesis, LLVM must be configured and built with LLVM_ENABLE_LIBPFM enabled, because llvm-exegesis depends on libpfm4 for accessing performance counters. Benchmarking may fail if the target CPU is unsupported by libpfm. This can be verified by setting LIBPFM_VERBOSE and LIBPFM_DEBUG environment variables to enable verbose or debug mode for libpfm. If libpfm is installed in a non-standard directory, LLVM can be configured to locate the necessary library and header files by setting LIBRARY_PATH, C_INCLUDE_PATH, and CPLUS_INCLUDE_PATH environment variables. Additionally, LD_LIBRARY_PATH should be set so that llvm-exegesis can locate the libpfm library during execution. ๐Ÿซถ

๐ŸŽ€ SNIPPET ANNOTATIONS ๐ŸŽ€

llvm-exegesis supports benchmarking arbitrary snippets of assembly. However, benchmarking these snippets often requires some setup so that they can execute properly. llvm-exegesis has five annotations and some additional utilities to help with setup so that snippets can be benchmarked properly. Here's the whole cast, bestie:

  • LLVM-EXEGESIS-DEFREG <register name> โ€” Adding this annotation to the text assembly snippet to be benchmarked marks the register as requiring a definition. A value will automatically be provided unless a second parameter, a hex value, is passed in. This is done with the LLVM-EXEGESIS-DEFREG <register name> <hex value> format. <hex value> is a bit pattern used to fill the register. If it is a value smaller than the register, it is sign extended to match the size of the register.
  • LLVM-EXEGESIS-LIVEIN <register name> โ€” This annotation allows specifying registers that should keep their value upon starting the benchmark. Values can be passed through registers from the benchmarking setup in some cases. The registers and the values assigned to them that can be utilized in the benchmarking script with a LLVM-EXEGESIS-LIVEIN are as follows:
    • Scratch memory register โ€” The specific register that this value is put in is platform dependent (e.g., it is the RDI register on X86 Linux). Setting this register as a live in ensures that a pointer to a block of memory (1MB) is placed within this register that can be used by the snippet.
  • LLVM-EXEGESIS-MEM-DEF <value name> <size> <value> โ€” This annotation allows specifying memory definitions that can later be mapped into the execution process of a snippet with the LLVM-EXEGESIS-MEM-MAP annotation. Each value is named using the <value name> argument so that it can be referenced later within a map annotation. The size is specified in a decimal number of bytes and the value is given in hexadecimal. If the size of the value is less than the specified size, the value will be repeated until it fills the entire section of memory. Using this annotation requires using the subprocess execution mode.
  • LLVM-EXEGESIS-MEM-MAP <value name> <address> โ€” This annotation allows for mapping previously defined memory definitions into the execution context of a process. The value name refers to a previously defined memory definition and the address is a decimal number that specifies the address the memory definition should start at. Note that a single memory definition can be mapped multiple times. Using this annotation requires the subprocess execution mode.
  • LLVM-EXEGESIS-SNIPPET-ADDRESS <address> โ€” This annotation allows for setting the address where the beginning of the snippet to be executed will be mapped in at. The address is given in hexadecimal. Note that the snippet also includes setup code, so the instruction exactly at the specified address will not be the first instruction in the snippet. Using this annotation requires the subprocess execution mode. This is useful in cases where the memory accessed by the snippet depends on the location of the snippet, like RIP-relative addressing.
  • LLVM-EXEGESIS-LOOP-REGISTER <register name> โ€” This annotation specifies the loop register to use for keeping track of the current iteration when using the loop repetition mode. llvm-exegesis needs to keep track of the current loop iteration within the loop repetition mode in a performant manner (i.e., no memory accesses), and uses a register to do this. This register has an architecture-specific default (e.g., R8 on X86), but this might conflict with some snippets. This annotation allows changing the register to prevent interference between the loop index register and the snippet.

๐Ÿ”ฅ EXAMPLE 1: BENCHMARKING INSTRUCTIONS ๐Ÿ”ฅ

Assume you have an X86-64 machine. To measure the latency of a single instruction, run:

$ llvm-exegesis --mode=latency --opcode-name=ADD64rr

Measuring the uop decomposition or inverse throughput of an instruction works similarly:

$ llvm-exegesis --mode=uops --opcode-name=ADD64rr
$ llvm-exegesis --mode=inverse_throughput --opcode-name=ADD64rr

The output is a YAML document (the default is to write to stdout, but you can redirect the output to a file using --benchmarks-file):

---
key:
  opcode_name:     ADD64rr
  mode:            latency
  config:          ''
cpu_name:        haswell
llvm_triple:     x86_64-unknown-linux-gnu
num_repetitions: 10000
measurements:
  - { key: latency, value: 1.0058, debug_string: '' }
error:           ''
info:            'explicit self cycles, selecting one aliasing configuration.
Snippet:
ADD64rr R8, R8, R10
'
...

To measure the latency of all instructions for the host architecture, run:

$ llvm-exegesis --mode=latency --opcode-index=-1

๐Ÿ’… EXAMPLE 2: BENCHMARKING A CUSTOM CODE SNIPPET ๐Ÿ’…

To measure the latency/uops of a custom piece of code, you can specify the snippets-file option (- reads from standard input).

$ echo "vzeroupper" | llvm-exegesis --mode=uops --snippets-file=-

Real-life code snippets typically depend on registers or memory. llvm-exegesis checks the liveliness of registers (i.e. any register use has a corresponding def or is a "live in"). If your code depends on the value of some registers, you need to use snippet annotations to ensure setup is performed properly.

For example, the following code snippet depends on the values of XMM1 (which will be set by the tool) and the memory buffer passed in RDI (live in).

# LLVM-EXEGESIS-LIVEIN RDI
# LLVM-EXEGESIS-DEFREG XMM1 42
vmulps        (%rdi), %xmm1, %xmm2
vhaddps       %xmm2, %xmm2, %xmm3
addq $0x10, %rdi

๐Ÿ“ EXAMPLE 3: BENCHMARKING WITH MEMORY ANNOTATIONS ๐Ÿ“

Some snippets require memory setup in specific places to execute without crashing. Setting up memory can be accomplished with the LLVM-EXEGESIS-MEM-DEF and LLVM-EXEGESIS-MEM-MAP annotations. To execute the following snippet:

movq $8192, %rax
movq (%rax), %rdi

We need to have at least eight bytes of memory allocated starting 0x2000. We can create the necessary execution environment with the following annotations added to the snippet:

# LLVM-EXEGESIS-MEM-DEF test1 4096 7fffffff
# LLVM-EXEGESIS-MEM-MAP test1 8192

movq $8192, %rax
movq (%rax), %rdi

๐Ÿ‘‘ EXAMPLE 4: ANALYSIS ๐Ÿ‘‘

Assuming you have a set of benchmarked instructions (either latency or uops) as YAML in file /tmp/benchmarks.yaml, you can analyze the results using the following command:

            $ llvm-exegesis --mode=analysis \
          --benchmarks-file=/tmp/benchmarks.yaml \
          --analysis-clusters-output-file=/tmp/clusters.csv \
          --analysis-inconsistencies-output-file=/tmp/inconsistencies.html

This will group the instructions into clusters with the same performance characteristics. The clusters will be written out to /tmp/clusters.csv in the following format:

cluster_id,opcode_name,config,sched_class
...
2,ADD32ri8_DB,,WriteALU,1.00
2,ADD32ri_DB,,WriteALU,1.01
2,ADD32rr,,WriteALU,1.01
2,ADD32rr_DB,,WriteALU,1.00
2,ADD32rr_REV,,WriteALU,1.00
2,ADD64i32,,WriteALU,1.01
2,ADD64ri32,,WriteALU,1.01
2,MOVSX64rr32,,BSWAP32r_BSWAP64r_MOVSX64rr32,1.00
2,VPADDQYrr,,VPADDBYrr_VPADDDYrr_VPADDQYrr_VPADDWYrr_VPSUBBYrr_VPSUBDYrr_VPSUBQYrr_VPSUBWYrr,1.02
2,VPSUBQYrr,,VPADDBYrr_VPADDDYrr_VPADDQYrr_VPADDWYrr_VPSUBBYrr_VPSUBDYrr_VPSUBQYrr_VPSUBWYrr,1.01
2,ADD64ri8,,WriteALU,1.00
2,SETBr,,WriteSETCC,1.01
...

llvm-exegesis will also analyze the clusters to point out inconsistencies in the scheduling information. The output is an html file. For example, /tmp/inconsistencies.html will contain messages like the following: [image].

Note that the scheduling class names will be resolved only when llvm-exegesis is compiled in debug mode, else only the class id will be shown. This does not invalidate any of the analysis results though. ๐Ÿ’–

โญ OPTIONS โญ

  • --help โ€” Print a summary of command line options.
  • --opcode-index=<LLVM opcode index> โ€” Specify the opcode to measure, by index. Specifying -1 will result in measuring every existing opcode. See example 1 for details. Either opcode-index, opcode-name or snippets-file must be set.

okay bestie we're deep in the options now โ€” hydrate, stretch, and stay with me, because these are the ones that actually control how the measurement goes down ๐Ÿ’…

  • --opcode-name=<opcode name 1>,<opcode name 2>,... โ€” tells llvm-exegesis which opcode to measure, by name. You can stack several of them in one comma-separated list, no cap. Peep example 1 if you want the tea. Also, quick vibe check: either opcode-index, opcode-name or snippets-file must be set โ€” you can't just show up with nothing ๐Ÿซถ
  • --snippets-file=<filename> โ€” points at a custom code snippet you want measured. Example 2 has the details, bestie. And again the rule: either opcode-index, opcode-name or snippets-file must be set.
  • --mode=[latency|uops|inverse_throughput|analysis] โ€” picks the run mode. Heads up though, some modes come with extra requirements and options, so read the fine print ๐Ÿ‘€
    • latency mode can make use of either RDTSC or LBR. But latency[LBR] is only available on X86 (at least Skylake, not sorry). To actually run in latency mode you must specify a positive value for x86-lbr-sample-period and --repetition-mode=loop.
    • In analysis mode you also need to specify at least one of -analysis-clusters-output-file= and -analysis-inconsistencies-output-file=. No output file, no analysis, periodt.
  • --benchmark-phase=[prepare-snippet|prepare-and-assemble-snippet|assemble-measured-code|measure] โ€” this is your "how far do we go" dial. By default, when -mode= is specified, the generated snippet gets executed and measured โ€” which means you gotta be running on the hardware the snippet was generated for, and that hardware has to support performance measurements. But you can stop at an earlier stage before measuring. The choices are:
    • prepare-snippet โ€” only generates the minimal instruction sequence.
    • prepare-and-assemble-snippet โ€” same as prepare-snippet, but it also dumps an excerpt of the sequence (hex encoded). Cute AND useful โœจ
    • assemble-measured-code โ€” same as prepare-and-assemble-snippet, but also creates the full sequence that can be dumped to a file using --dump-object-to-disk.
    • measure โ€” same as assemble-measured-code, but also actually runs the measurement. The whole point, honestly.
  • --x86-lbr-sample-period=<nBranches/sample> โ€” sets the LBR sampling period, aka how many branches happen before we take a sample. When you give this a positive value and the mode is latency, we'll use LBRs for measuring. On picking the "right" sampling period: smaller is preferred, but if you sample too frequently you can get throttling. Also use a prime number so you don't consistently skip certain blocks โ€” that would be so embarrassing for us ๐Ÿ™ˆ
  • --x86-disable-upper-sse-registers โ€” using the upper xmm registers (xmm8-xmm15) forces a longer instruction encoding, which can put greater pressure on the frontend fetch and decode stages, potentially reducing the rate instructions get dispatched to the backend โ€” especially on older hardware. Comparing baseline results with this mode enabled helps you figure out the effects of the frontend, and can be used to improve latency and throughput estimates. Lowkey a diagnostic icon ๐Ÿ”ฅ
  • --repetition-mode=[duplicate|loop|min|middle-half-duplicate|middle-half-loop] โ€” picks the repetition mode, and each one has main character energy:
    • duplicate creates a large, straight-line basic block with min-instructions instructions (repeating the snippet min-instructions/snippet size times).
    • loop will, optionally, duplicate the snippet until the loop body contains at least loop-body-size instructions, then wrap the result in a loop which executes min-instructions instructions (thus, again, repeating the snippet min-instructions/snippet size times). The loop mode, especially with loop unrolling, tends to better hide the effects of the CPU frontend on architectures that cache decoded instructions โ€” but it consumes a register for counting iterations. Trade-offs, bestie.
    • If you're performing an analysis over many opcodes, it may be best to use the min mode instead, which will run each other mode and produce the minimal measured result. Slay, efficient queen ๐Ÿ‘‘
    • The middle-half repetition modes will either duplicate or run the snippet in a loop depending upon the specific mode. They'll run two benchmarks, one twice the length of the first one, and then subtract the difference between them to get values without overhead. Math ate, honestly ๐Ÿงฎ
  • --min-instructions=<Number of instructions> โ€” sets the target number of executed instructions. Fair warning: the actual repetition count of the snippet will be min-instructions/snippet size. Higher values = more accurate measurements, but the benchmark gets longer. Accuracy costs time, always ๐Ÿ’€
  • --loop-body-size=<Preferred loop body size> โ€” only effective for -repetition-mode=[loop|min]. Instead of looping over the snippet directly, it first duplicates it so the loop body contains at least this many instructions. This can result in the loop body being cached in the CPU Op Cache / Loop Cache, which may have higher throughput than the CPU decoders. The cache said "I'll take it from here" โœจ
  • --max-configs-per-opcode=<value> โ€” sets the maximum configurations that can be generated for each opcode. By default this is 1, meaning we assume a single measurement is enough to characterize an opcode. That assumption is not always true: for example, the performance characteristics of the LEA instruction on X86 depend on the value of assigned registers and immediates. Setting -max-configs-per-opcode larger than 1 lets llvm-exegesis explore more configurations and discover whether some register or immediate assignments lead to different performance characteristics. Detective mode activated ๐Ÿ•ต๏ธ
  • --benchmarks-file=</path/to/file> โ€” the file to read (in analysis mode) or write (in latency/uops/inverse_throughput modes) benchmark results to. Passing - uses stdin/stdout, classic.
  • --analysis-clusters-output-file=</path/to/file> โ€” if provided, writes the analysis clusters as CSV to this file. - prints to stdout. And by default, this analysis is not run at all.
  • --analysis-inconsistencies-output-file=</path/to/file> โ€” if non-empty, writes inconsistencies found during analysis to this file. - prints to stdout. Also by default not run. You literally have to opt in, bestie.
  • --analysis-filter=[all|reg-only|mem-only] โ€” by default all benchmark results are analysed. But sometimes it's useful to only look at the ones that don't involve memory, or vice versa. This option lets you either keep all benchmarks, or filter out (ignore) all the ones that do involve memory (so, instructions that may read or write to memory), or the opposite โ€” only keep those memory-y benchmarks. Choose your fighter ๐Ÿ’…
  • --analysis-clustering=[dbscan,naive] โ€” picks the clustering algorithm. DBSCAN is the default, obviously. The naive clustering algorithm is better for doing further work on the -analysis-inconsistencies-output-file= output โ€” it creates one cluster per opcode, and then checks that the cluster is stable (meaning all points are neighbours). Neighbourly behaviour ๐Ÿซถ
  • --analysis-numpoints=<dbscan numPoints parameter> โ€” sets the numPoints parameter used for DBSCAN clustering (analysis mode, DBSCAN only โ€” don't try it with naive, it's not for her).
  • --analysis-clustering-epsilon=<dbscan epsilon parameter> โ€” sets the epsilon parameter used for clustering of benchmark points (analysis mode).
  • --analysis-inconsistency-epsilon=<epsilon> โ€” sets the epsilon parameter used for detecting when the cluster is different from the LLVM schedule profile values (analysis mode).
  • --analysis-display-unstable-clusters โ€” if there's more than one benchmark for an opcode, those benchmarks may end up not being clustered into the same cluster when their measured performance characteristics differ. By default, all such opcodes are filtered out. This flag flips it: instead it shows only such unstable opcodes. Unstable? Iconic. Shown? Only with this flag ๐Ÿ˜ญ
  • --ignore-invalid-sched-class=false โ€” if set, it ignores instructions that do not have a sched class (class idx = 0). Unbothered, unphased.
  • --mtriple=<triple name> โ€” the target triple. Peep -version for the available targets.
  • --mcpu=<cpu name> โ€” if set, it measures the cpu characteristics using the counters for this CPU. Super useful when you're creating new sched models (like when the host CPU is unknown to LLVM). Oh and -mcpu=help for details, you're welcome ๐Ÿ’œ
  • --analysis-override-benchmark-triple-and-cpu โ€” by default, llvm-exegesis analyses the benchmarks for the triple/CPU they were measured for. But if you want to analyse them for some other combination (specified via -mtriple/-mcpu), pass this flag. Recontextualize your data, queen.
  • --dump-object-to-disk=<filename> โ€” if set, llvm-exegesis dumps the generated code to a temporary file so you can actually inspect it. Disabled by default. Code inspection era ๐Ÿ”
  • --use-dummy-perf-counters โ€” if set, llvm-exegesis won't read any real performance counters and will return a dummy value instead. Useful to make sure a snippet doesn't crash when hardware performance counters aren't available, and also for debugging llvm-exegesis itself. Fake numbers, real peace of mind ๐Ÿ™ˆ
  • --execution-mode=[inprocess,subprocess] โ€” picks the execution mode. inprocess is the default. subprocess unlocks extra features like memory annotations, but is currently restricted to X86-64 on Linux. Read the room before you try it elsewhere ๐Ÿ’€
  • --benchmark-repeat-count=<repeat-count> โ€” lets you specify how many times to repeat the measurement when doing latency measurements. By default, llvm-exegesis repeats a latency measurement enough times to balance run-time and noise reduction. It's giving "we already did the math for you" ๐ŸŽ€
  • --validation-counter=[instructions-retired,l1d-cache-load-misses,l1d-cache-store-misses,l1i-cache-load-misses,data-tlb-load-misses,data-tld-store-misses,instruction-tlb-load-misses] โ€” turns on validation counters, which measure additional microarchitectural events (like cache misses) to validate snippet execution conditions. These events get measured using the perf subsystem, in a group with the performance counter used to measure the value of interest. You can specify this flag multiple times to measure multiple events, and the maximum number of validation counters is platform dependent. There's one line here holding a whole squad of events, so respect the comma-separated roster ๐ŸŒˆ
  • --benchmark-process-cpu=<cpu id> โ€” specifies the number of the CPU that should be used to run the benchmarking subprocess. When starting the subprocess, llvm-exegesis sets the affinity of the subprocess to only include the specified CPU. And this option only works in the subprocess execution mode โ€” no subprocess, no CPU pinning, no exceptions. Stay on your assigned core, bestie ๐Ÿซถ

โœจ EXIT STATUS โœจ

Okay bestie, here's the vibe check on how llvm-exegesis says goodbye ๐Ÿ‘‹

  • 0 โ€” slay, it worked, everything succeeded ๐Ÿ’…
  • any non-0 value โ€” not it ๐Ÿ˜ญ. When that happens, an error message gets printed to standard error, and the tool hands back a non 0 value. So like, if you see a nonzero exit, check your stderr โ€” that's where the tea is ๐Ÿซ–.
Fr fr, don't ignore that stderr output โ€” it's literally the tool telling you what went wrong. Read it before you spiral ๐Ÿ™ˆ.

๐Ÿ‘‘ Author

Maintained by the LLVM Team (<https://llvm.org/>)

2003-2026, LLVM Project


And that's a wrap, bestie ๐Ÿฆ‹ This page is from the LLVM Project, version 23, dated 2026-10-20 โ€” go forth and benchmark iconic-ly ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from
  • arch rolling: llvm 23.1.4-1 ยท Apache-2.0 WITH LLVM-exception
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms