LLVM-EXEGESIS(1)
๐ 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 likeLLVM-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 anLLVM-EXEGESIS-LIVEINare as follows:- Scratch memory register โ the specific register that this value is put in is platform dependent (e.g., it is the
RDIregister 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 ๐
- Scratch memory register โ the specific register that this value is put in is platform dependent (e.g., it is the
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 theLLVM-EXEGESIS-MEM-MAPannotation. 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-exegesisneeds 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.,R8on 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-1will result in measuring every existing opcode. See example 1 for details. Eitheropcode-index,opcode-nameorsnippets-filemust 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 ofopcode-index,opcode-nameorsnippets-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: eitheropcode-index,opcode-nameorsnippets-filemust 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:latencymode 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 forx86-lbr-sample-periodand--repetition-mode=loop.- In
analysismode 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 asprepare-snippet, but also dumps an excerpt of the sequence (hex encoded) ๐ฆassemble-measured-code: same asprepare-and-assemble-snippet, but also creates the full sequence that can be dumped to a file using--dump-object-to-disk.measure: same asassemble-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 islatency, 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:duplicatecreates a large, straight line basic block withmin-instructionsinstructions (repeating the snippetmin-instructions/snippet sizetimes).loopwill, optionally, duplicate the snippet until the loop body contains at leastloop-body-sizeinstructions, and then wrap the result in a loop which will executemin-instructionsinstructions (thus, again, repeating the snippetmin-instructions/snippet sizetimes). Theloopmode, 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
minmode, 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 bemin-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 is1, 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 theLEAinstruction on X86 depends on the value of assigned registers and immediates ๐ setting a value of-max-configs-per-opcodelarger than1letsllvm-exegesisexplore 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 (inanalysismode) or write (inlatency/uops/inverse_throughputmodes) 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 thenumPointsparameter 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-versionfor 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=helpfor details)--analysis-override-benchmark-triple-and-cpuโ by default,llvm-exegesiswill 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-exegesiswill dump the generated code to a temporary file to enable code inspection ๐ disabled by default.--use-dummy-perf-countersโ if set,llvm-exegesiswill 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 debuggingllvm-exegesisitself. Fake it till you make it, but for counters โจ--execution-mode=[inprocess,subprocess]โ specifies what execution mode to use.inprocessis the default ๐subprocessallows 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-exegesiswill 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-exegesiswill set the affinity of the subprocess to only include the specified CPU. This option only works in thesubprocessexecution mode. No inprocess cheating allowed ๐ญ
๐ฆ EXIT STATUS ๐ฆ
okay bestie, this part is short but like, lowkey important? here's the whole vibe:
llvm-exegesisreturns0on 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
0value. 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 ๐
๐ COPYRIGHT ๐
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
- centos-stream 9: llvm 23.1.3-1.el9 ยท Apache-2.0 WITH LLVM-exception OR NCSA
- centos-stream 9: llvm 23.1.3-1.el9 ยท Apache-2.0 WITH LLVM-exception OR NCSA
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms