LLVM-EXEGESIS(1)
π LLVM-EXEGESIS(1) π
okay bestie, welcome to the LLVM manual page for llvm-exegesis, aka LLVM Machine Instruction Benchmark β yes that's the whole name section, we're folding it in up top like a cute little intro card β¨
β¨ SYNOPSIS β¨
llvm-exegesis [options]
that's it. that's the whole thing. iconic. π
πΈ DESCRIPTION πΈ
so llvm-exegesis is a benchmarking tool, right, and the way it works is chef's kiss β it uses information that's already chillin' inside LLVM to measure host machine instruction characteristics like latency, throughput, or port decomposition. π
here's the vibe: you give it an LLVM opcode name and a benchmarking mode, and llvm-exegesis generates a code snippet that makes execution as serial (resp. as parallel) as possible β so we can measure the latency (resp. inverse throughput/uop decomposition) of the instruction. the code snippet is jitted, and 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. and the result is printed out as YAML to the standard output. slay. π¦
the main goal of this tool? to automatically (in)validate the LLVM's TableDef scheduling models. to that end, we also provide analysis of the results. no cap, that's the whole point. π
also β and this is the fun part β llvm-exegesis can also benchmark arbitrary user-provided code snippets. yes, your snippets. main character energy fr fr. π
π«Ά SUPPORTED PLATFORMS π«Ά
okay so platform-wise, llvm-exegesis currently only supports X86 (64-bit only), ARM (AArch64 only), MIPS, and PowerPC (PowerPC64LE only) β and that's on Linux, for benchmarking. π
not all benchmarking functionality is guaranteed to work on every platform. just so you know. π
but here's the good news: llvm-exegesis also has a separate analysis mode that is supported on every platform that LLVM is. so you're never fully left out. π
π SNIPPET ANNOTATIONS π
llvm-exegesis supports benchmarking arbitrary snippets of assembly. however β and this is the tea β 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. π§
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 theLLVM-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 aLLVM-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. π
- 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 allows specifying 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. 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-exegesisneeds 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.,R8on 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
ate. π
π 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
yes bestie, it actually works. β¨
π 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. π
ngl that's a lot of info but you're doing amazing, keep going bestie ππ
β¨ OPTIONS β¨
okay so this is the big knob wall, bestie ποΈ β every flag, every default, no crumbs left behind. letβs get into it.
--helpβ prints a summary of command line options. thatβs it, thatβs the whole vibe.--opcode-index=<LLVM opcode index>β pick the opcode you wanna measure by index. set it to-1and youβre measuring every existing opcode β main character energy, honestly. example 1 has the deets. you must set eitheropcode-index,opcode-name, orsnippets-file.--opcode-name=<opcode name 1>,<opcode name 2>,...β pick the opcode to measure by name. you can list several opcodes as a comma-separated list. example 1 has the deets. you must set eitheropcode-index,opcode-name, orsnippets-file.--snippets-file=<filename>β point at the custom code snippet you wanna measure. example 2 has the deets. you must set eitheropcode-index,opcode-name, orsnippets-file.--mode=[latency|uops|inverse_throughput|analysis]β tells it what run mode to use. note that some modes have extra requirements and options π.
latency mode can make use of either RDTSC or LBR. latency[LBR] is only available on X86 (at least Skylake). to run in latency mode, a positive value must be specified for x86-lbr-sample-period and you need --repetition-mode=loop.
in analysis mode, you also need to specify at least one of -analysis-clusters-output-file= and -analysis-inconsistencies-output-file=.
--benchmark-phase=[prepare-snippet|prepare-and-assemble-snippet|assemble-measured-code|measure]β by default, when-mode=is specified, the generated snippet gets executed and measured. that requires weβre running on the hardware the snippet was generated for, and that the hardware supports performance measurements. but you can stop at some stage before measuring. choices are:prepare-snippet: only generate the minimal instruction sequence.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.
--x86-lbr-sample-period=<nBranches/sample>β sets the LBR sampling period: how many branches before we take a sample. when a positive value is specified for this option and the mode islatency, we will 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 π₯.--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. that can potentially reduce the rate 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.--repetition-mode=[duplicate|loop|min|middle-half-duplicate|middle-half-loop]β specifies the repetition mode.
duplicate will create 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 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. the middle half repetition modes will run two benchmarks, one twice the length of the first one, and then subtract the difference between them to get values without overhead.
--min-instructions=<Number of instructions>β specifies 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.--loop-body-size=<Preferred loop body size>β only effective for-repetition-mode=[loop|min]. instead of looping over the snippet directly, first duplicate 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.--max-configs-per-opcode=<value>β specifies the maximum configurations that can be generated for each opcode. by default this is1, meaning we assume a single measurement is enough to characterize an opcode. that might not be true of all instructions: for example, the performance characteristics of theLEAinstruction on X86 depend on the value of assigned registers and immediates. setting a value of-max-configs-per-opcodelarger than1allowsllvm-exegesisto explore more configurations and discover if some register or immediate assignments lead to different performance characteristics.--benchmarks-file=</path/to/file>β file to read (analysismode) or write (latency/uops/inverse_throughputmodes) benchmark results."-"uses stdin/stdout.--analysis-clusters-output-file=</path/to/file>β if provided, write 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, write inconsistencies found during analysis to this file.-prints to stdout. by default, this analysis is not run.--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 do not involve memory, or vice versa. this option allows you to 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.--analysis-clustering=[dbscan,naive]β specifies the clustering algorithm to use. by default DBSCAN will be used. 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).--analysis-numpoints=<dbscan numPoints parameter>β specifies thenumPointsparameters to be used for DBSCAN clustering (analysismode, DBSCAN only).--analysis-clustering-epsilon=<dbscan epsilon parameter>β specifies the epsilon parameter used for clustering of benchmark points (analysismode).--analysis-inconsistency-epsilon=<epsilon>β specifies the epsilon parameter used for detection of when the cluster is different from the LLVM schedule profile values (analysismode).--analysis-display-unstable-clustersβ if there is 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 will instead show only such unstable opcodes.--ignore-invalid-sched-class=falseβ if set, ignore instructions that do not have a sched class (class idx = 0).--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.--dump-object-to-disk=trueβ 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.--execution-mode=[inprocess,subprocess]β specifies what execution mode to use. theinprocessexecution mode is the default. thesubprocessexecution mode allows for additional features such as memory annotations, but is currently restricted to X86-64 on Linux.--benchmark-repeat-count=<repeat-count>β this option enables specifying 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.--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]β this option 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.
π EXIT STATUS π
Okay bestie, this is the part every shell script is lowkey refreshing for β the vibe check at the end of the run. β¨
llvm-exegesis returns 0 on success. That's the slay. Green flag, confetti emoji, your pipeline moves tf on. π’
Otherwise? Not so much. An error message is printed to standard error, and the tool returns a non 0 value. So the whole deal is:
0β it worked, we ate, no notes π- non-
0β something went sideways, and it told you about it on standard error
And notice the page says βa non 0 valueβ, not β1β. It's giving unspecified on purpose, so don't go hardcoding which non-zero number you're gonna catch, iykyk. π
π Author π
Maintained by the LLVM Team (https://llvm.org/). They're the ones keeping this whole thing alive, so likeβ¦ respect. π
πΈ Copyright πΈ
2003-2026, LLVM Project β that's the whole copyright line, bestie, right there, no cap. π
And that's the whole page, fr fr. This gorgeous little manpage is LLVM-EXEGESIS(1), version 15, dated 2026-09-09 β so if you're reading it in some other year, blame the docs gremlins, not me. π§ Go benchmark something iconic, bestie. Periodt. ππ¦β
π¦ where this page comes from
- ubuntu stonking: llvm-19 1:19.1.7-20ubuntu8 Β· APACHE-2-LLVM-EXCEPTIONS
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms