LLVM-EXEGESIS(1)

๐Ÿ“ฆ version 23.1.3, in centos-stream 9

๐Ÿ’… llvm-exegesis โ€” LLVM Machine Instruction Benchmark ๐Ÿ’…

okay so this is llvm-exegesis(1), straight out of the LLVM manual, and bestieโ€ฆ it's a whole vibe. It's a benchmarking tool, it's a little unhinged, and it's genuinely iconic. Let's get into it ๐Ÿซถ


โœจ NAME โœจ

llvm-exegesis โ€” LLVM Machine Instruction Benchmark ๐Ÿ”ฅ (yes that's the whole name, it's giving main character energy)


โœจ SYNOPSIS โœจ

llvm-exegesis [options]

That's it. That's the whole synopsis. Iconic minimalism ๐Ÿ’…


โœจ DESCRIPTION โœจ

okay so llvm-exegesis is a benchmarking tool โ€” and no cap, it uses the info that's just sitting there inside LLVM to measure characteristics of your host machine's instructions, like latency, throughput, or port decomposition. It's literally built different.

Here's the tea โ˜•: you hand it an LLVM opcode name plus a benchmarking mode, and it generates a code snippet that makes execution as serial as possible (or, depending on the mode, as parallel as possible) โ€” so we can measure the latency (resp. the inverse throughput / uop decomposition) of that instruction. The snippet gets jitted, and then โ€” unless you specifically asked it not to โ€” it gets executed on the host subtarget. The time taken (resp. resource usage) is measured using hardware performance counters. Then the result gets printed out as YAML to standard output. slay ๐Ÿ’…

The main goal of this whole tool, fr fr, is to automatically (in)validate LLVM's TableDef scheduling models. And because we're extra like that, we also provide analysis of the results โœจ

Also: llvm-exegesis can benchmark arbitrary user-provided code snippets too. Not me being flexible ๐Ÿ˜ญ


๐ŸŒˆ SUPPORTED PLATFORMS ๐ŸŒˆ

llvm-exegesis currently only supports these, and only on Linux for benchmarking:

  • X86 โ€” 64-bit only
  • ARM โ€” AArch64 only, and just so you know, snippet generation is sparse
  • MIPS
  • PowerPC โ€” PowerPC64LE only
  • RISC-V โ€” RV64I/E and RV32I/E
Not all benchmarking functionality is guaranteed to work on every platform. Read that again, bestie. Guaranteed is doing a lot of heavy lifting there ๐Ÿ’€

Good news though: llvm-exegesis also has a separate analysis mode, and that one is supported on every platform that LLVM is. So you're never fully left on read ๐Ÿซถ

To actually 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. You can verify this by setting the 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 the 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. Don't skip that last one, she's important ๐ŸŽ€


๐Ÿฆ‹ SNIPPET ANNOTATIONS ๐Ÿฆ‹

llvm-exegesis supports benchmarking arbitrary snippets of assembly โ€” yes, your assembly, go off ๐Ÿ‘‘. However! Benchmarking these snippets often requires some setup so that they can execute properly (because a snippet just floating there with no registers defined is gonna crash, and that's not the vibe). llvm-exegesis has five annotations and some additional utilities to help with setup so that snippets can be benchmarked properly.

  • LLVM-EXEGESIS-DEFREG <register name> โ€” drop this annotation into the text assembly snippet you're benchmarking and it marks that register as requiring a definition. A value will automatically be provided unless a second parameter, a hex value, is passed in. That second form looks like LLVM-EXEGESIS-DEFREG <register name> <hex value>. The <hex value> is a bit pattern used to fill the register. And if it's a value smaller than the register, it gets sign extended to match the size of the register. math, but make it cute ๐Ÿงฎโœจ
  • LLVM-EXEGESIS-LIVEIN <register name> โ€” this annotation lets you specify 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 an 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. one whole megabyte, bestie, use it wisely ๐Ÿ’–
  • LLVM-EXEGESIS-MEM-DEF <value name> <size> <value> โ€” this annotation lets you specify 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 (she loops, she repeats, she fills the whole block ๐ŸŒ€). Using this annotation requires using the subprocess execution mode.
  • LLVM-EXEGESIS-MEM-MAP <value name> <address> โ€” this one lets you map 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 (reuse queen ๐Ÿ’…). Using this annotation requires the subprocess execution mode.
  • LLVM-EXEGESIS-SNIPPET-ADDRESS <address> โ€” this annotation lets you set 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 โ€” careful, it's a whole ensemble cast, not a solo ๐ŸŽญ. 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 โ€” we stay in registers, we stay fast โšก), 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 lets you change the register to prevent interference between the loop index register and the snippet. no drama in the register file, periodt ๐Ÿซถ

๐ŸŒธ 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 โ€” very demure, very mindful ๐Ÿ“:

---
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

(that -1 is not a typo, it literally means "every existing opcode", she's doing the most ๐Ÿ’€)


๐ŸŒธ 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 โ€” otherwise the vibe check fails and everything explodes ๐Ÿซ 

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

look at those annotations just sitting there being gorgeous ๐Ÿ’œ


๐ŸŒธ EXAMPLE 3: BENCHMARKING WITH MEMORY ANNOTATIONS ๐ŸŒธ

Some snippets require memory setup in specific places to execute without crashing โ€” we love a snippet with needs ๐Ÿ™ˆ. 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

easy. setup performed. snippet slayed โœจ


๐ŸŒธ 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. so don't panic, the numbers are still correct, it's just showing you the class id instead of the class name ๐Ÿ’–

โœจ OPTIONS โœจ

  • --help โ€” Print a summary of command line options. the "help me help you" of flags ๐Ÿซถ
  • --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. (pick one, bestie, you gotta pick at least one ๐Ÿ’…)
  • --opcode-name=<opcode name 1>,<opcode name 2>,... โ€” tells it which opcode to measure, by name bestie, by name ๐Ÿ’… and yeah you can flex several at once, just comma-separate them. Example 1 has the receipts. Real talk: you must set exactly one of opcode-index, opcode-name or snippets-file, no cap.
  • --snippets-file=<filename> โ€” this is where you hand over your very own custom code snippet to measure ๐ŸŽ€ see example 2 if you're like "wait how". And again: either opcode-index, opcode-name or snippets-file must be set, pick your fighter.
  • --mode=[latency|uops|inverse_throughput|analysis] โ€” the run mode, aka the vibe check of the whole operation โœจ heads up though, some modes come with extra requirements and extra options, they're not all low-maintenance:
    • latency mode can make use of either RDTSC or LBR. latency[LBR] is only available on X86 (at least Skylake) โ€” sorry bestie, X86 only, no gatecrashing. To 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=. Not optional, it's giving mandatory.
  • --benchmark-phase=[prepare-snippet|prepare-and-assemble-snippet|assemble-measured-code|measure] โ€” so by default, when -mode= is specified, the generated snippet gets executed and measured, which requires that we're running on the exact hardware the snippet was generated for, and that said hardware supports performance measurements ๐Ÿ˜ญ but you can stop early at some stage before measuring, choices are:
    • prepare-snippet: only generate the minimal instruction sequence, that's it, that's the whole stage.
    • prepare-and-assemble-snippet: same as prepare-snippet, but also dumps an excerpt of the sequence (hex encoded) ๐Ÿฆ‹
    • 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 runs the measurement. The full send ๐Ÿ”ฅ
  • --x86-lbr-sample-period=<nBranches/sample> โ€” sets the LBR sampling period, meaning how many branches before we take a sample ๐ŸŒธ when a positive value is specified here and the mode is latency, we use LBRs for measuring. On choosing the "right" sampling period: a small value is preferred, but throttling could occur if the sampling is too frequent ๐Ÿ’€ a prime number should be used to avoid consistently skipping certain blocks. Math ate, honestly ๐Ÿ‘‘
  • --x86-disable-upper-sse-registers โ€” using the upper xmm registers (xmm8-xmm15) forces a longer instruction encoding, which may put greater pressure on the frontend fetch and decode stages, potentially reducing the rate that instructions are dispatched to the backend โ€” particularly on older hardware ๐Ÿซถ comparing baseline results with this mode enabled can help determine the effects of the frontend, and can be used to improve latency and throughput estimates. Iconic little diagnostic flag tbh.
  • --repetition-mode=[duplicate|loop|min|middle-half-duplicate|middle-half-loop] โ€” the repetition mode, and oof she has lore:
    • 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, and then wrap the result in a loop which will execute 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 ๐Ÿ™ˆ
    • If you're performing an analysis over many opcodes, it may be best to instead use the min mode, which will run each other mode, and produce the minimal measured result โญ
    • 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. Big brain energy fr fr ๐Ÿ’…
  • --min-instructions=<Number of instructions> โ€” the target number of executed instructions ๐ŸŽฏ note that the actual repetition count of the snippet will be min-instructions/snippet size. Higher values lead to more accurate measurements but lengthen the benchmark โ€” accuracy costs time, as 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 that the loop body contains at least this many instructions. This potentially results in the loop body being cached in the CPU Op Cache / Loop Cache, which may have higher throughput than the CPU decoders. Lowkey the loop cache is that girl.
  • --max-configs-per-opcode=<value> โ€” the max number of 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. This might not be true of all instructions: for example, the performance characteristics of the LEA instruction on X86 depends on the value of assigned registers and immediates ๐Ÿ‘€ setting a value of -max-configs-per-opcode larger than 1 lets llvm-exegesis explore more configurations to discover if some register or immediate assignments lead to different performance characteristics. Detective mode: activated ๐Ÿ’œ
  • --benchmarks-file=</path/to/file> โ€” file to read (in analysis mode) or write (in latency/uops/inverse_throughput modes) benchmark results ๐ŸŽ€ "-" uses stdin/stdout, cute and pipe-friendly.
  • --analysis-clusters-output-file=</path/to/file> โ€” if provided, writes the analysis clusters as CSV to this file. "-" prints to stdout. By default, this analysis is not run ๐Ÿ™ˆ
  • --analysis-inconsistencies-output-file=</path/to/file> โ€” if non-empty, writes the inconsistencies found during analysis to this file. - prints to stdout. By default, this analysis is not run either ๐ŸŒธ
  • --analysis-filter=[all|reg-only|mem-only] โ€” by default all benchmark results are analysed, but sometimes it may be useful to only look at those that don't involve memory, or vice versa ๐Ÿ’… this option lets you either keep all benchmarks, or filter out (ignore) either all the ones that do involve memory (involve instructions that may read or write to memory), or the opposite โ€” only keep such benchmarks. Choose your lane bestie.
  • --analysis-clustering=[dbscan,naive] โ€” which clustering algorithm to use, default is DBSCAN โญ the naive clustering algorithm is better for doing further work on the -analysis-inconsistencies-output-file= output โ€” it will create one cluster per opcode, and check that the cluster is stable (all points are neighbours). Neighbourhood watch but make it performance analysis ๐Ÿซถ
  • --analysis-numpoints=<dbscan numPoints parameter> โ€” sets the numPoints parameter used for DBSCAN clustering (analysis mode, DBSCAN only). DBSCAN only, don't come here with your naive agenda ๐Ÿ’€
  • --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 detection of 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, said benchmarks may end up not being clustered into the same cluster if the measured performance characteristics are different ๐Ÿ˜ญ by default all such opcodes are filtered out. This flag instead shows only such unstable opcodes. Chaos mode: show me the mess ๐Ÿ”ฅ
  • --ignore-invalid-sched-class=false โ€” if set, ignore instructions that do not have a sched class (class idx = 0). Making problems disappear, respectfully ๐Ÿ™ˆ
  • --mtriple=<triple name> โ€” target triple. See -version for available targets ๐Ÿฆ‹
  • --mcpu=<cpu name> โ€” if set, measure the CPU characteristics using the counters for this CPU. This is useful when creating new sched models (the host CPU is unknown to LLVM) ๐Ÿ‘€ (-mcpu=help for details)
  • --analysis-override-benchmark-triple-and-cpu โ€” by default, llvm-exegesis will analyze the benchmarks for the triple/CPU they were measured for, but if you want to analyze them for some other combination (specified via -mtriple/-mcpu), you can pass this flag. Remix the analysis, no cap ๐Ÿ’œ
  • --dump-object-to-disk=<filename> โ€” if set, llvm-exegesis will dump the generated code to a temporary file to enable code inspection ๐ŸŽ€ disabled by default.
  • --use-dummy-perf-counters โ€” if set, llvm-exegesis will not read any real performance counters and return a dummy value instead ๐Ÿซถ this can be used to ensure a snippet doesn't crash when hardware performance counters are unavailable, and for debugging llvm-exegesis itself. Fake it till you make it, but for counters โœจ
  • --execution-mode=[inprocess,subprocess] โ€” specifies what execution mode to use. inprocess is the default ๐Ÿ’… subprocess allows for additional features such as memory annotations, but is currently restricted to X86-64 on Linux โ€” very exclusive, very VIP ๐ŸŒธ
  • --benchmark-repeat-count=<repeat-count> โ€” lets you specify the number of times to repeat the measurement when performing latency measurements โญ by default, llvm-exegesis will repeat a latency measurement enough times to balance run-time and noise reduction. She's self-regulating like that ๐Ÿ’œ
  • --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] โ€” enables the use of validation counters, which measure additional microarchitectural events like cache misses to validate snippet execution conditions ๐Ÿ‘‘ these events are measured using the perf subsystem in a group with the performance counter used to measure the value of interest. This flag can be specified multiple times to measure multiple events ๐Ÿ”ฅ the maximum number of validation counters is platform dependent.
  • --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 will set the affinity of the subprocess to only include the specified CPU. This option only works in the subprocess execution mode. No inprocess cheating allowed ๐Ÿ˜ญ

๐Ÿšฆ EXIT STATUS ๐Ÿšฆ

okay bestie, this part is short but like, lowkey important? here's the whole vibe:

  • llvm-exegesis returns 0 on success. that's the good ending, the slay ending, the everything worked ending โœจ
  • otherwise (aka the not-slaying timeline): an error message gets printed to standard error, and the tool returns a non 0 value. so if your script is checking exit codes, it's gonna know something went sideways ๐Ÿ’€
fr fr, always check your exit status before you celebrate. a non 0 means the vibe check failed and there's an error message waiting for you on stderr ๐Ÿ™ˆ

๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

maintained by the LLVM Team (https://llvm.org/) ๐Ÿซถ

like, they're the ones keeping this whole thing alive. iconic behavior honestly ๐Ÿ’…


2003-2026, LLVM Project โญ

that's the whole legal moment, bestie. two decades and change of LLVM energy ๐Ÿฆ‹


and that's a wrap on the whole page!! ๐Ÿฅณ you made it through all of it, every option, every annotation, every example. main character energy behavior tbh ๐Ÿ’–

so real quick on the receipts: this was page LLVM-EXEGESIS(1), section 23, dated 2026-10-06 โ€” that's the source/version and date the manpage itself signs off with, and now you know it ๐ŸŽ€ go benchmark something cute and remember: exit status 0 is the goal, stderr is where the drama lives, and the LLVM Team has been holding it down since 2003 ๐ŸŒธ๐Ÿ’œ

๐Ÿ“ฆ where this page comes from