LLVM-EXEGESIS(1)
β¨ LLVM-EXEGESIS(1) β¨ β the LLVM Machine Instruction Benchmark π
okay bestie, buckle up, because we're reading a page straight out of the LLVM manual and it's genuinely iconic π
πΈ NAME πΈ
llvm-exegesis β literally the LLVM Machine Instruction Benchmark, no cap π₯
π¦ SYNOPSIS π¦
llvm-exegesis [options]
π DESCRIPTION π
so llvm-exegesis is this benchmarking tool that uses the info chillin' inside LLVM to measure host machine instruction characteristics β think latency, throughput, and port decomposition. obsessed π
here's the vibe: you give it an LLVM opcode name plus 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 that instruction. that snippet gets jitted and β unless you asked it not to β executed on the host subtarget. then the time taken (resp. resource usage) gets measured using hardware performance counters, and the result is printed out as YAML to standard output. slay β¨
the main goal of this tool is to automatically (in)validate LLVM's TableDef scheduling models. and yeah, to that end, we also provide analysis of the results π«Ά
bonus: llvm-exegesis can also benchmark arbitrary user-provided code snippets. main character energy fr π
π SUPPORTED PLATFORMS π
rn llvm-exegesis only supports X86 (64-bit only), ARM (AArch64 only), MIPS, and PowerPC (PowerPC64LE only) on Linux for benchmarking. π not all benchmarking functionality is guaranteed to work on every platform, just so you know. but!! llvm-exegesis also has a separate analysis mode that is supported on every platform that LLVM is, so that's a win π
β SNIPPET ANNOTATIONS β
llvm-exegesis supports benchmarking arbitrary snippets of assembly. iconic. BUT β benchmarking these snippets often requires some setup so that they execute properly. so llvm-exegesis has five annotations plus some additional utilities to help with setup so snippets can be benchmarked properly π§
LLVM-EXEGESIS-DEFREG <register name>β adding this annotation to the text assembly snippet you wanna benchmark marks the register as requiring a definition. a value will automatically be provided unless you pass a second parameter, a hex value. you do that with theLLVM-EXEGESIS-DEFREG <register name> <hex value>format.<hex value>is a bit pattern used to fill the register. if it's a value smaller than the register, it gets sign extended to match the size of the register π«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 you can use in the benchmarking script with aLLVM-EXEGESIS-LIVEINare as follows: π«Ά- Scratch memory register β the specific register that this value gets put in is platform dependent (e.g., it's 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 gets put in is platform dependent (e.g., it's 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 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 gets 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 π
π₯ EXAMPLE 1: BENCHMARKING INSTRUCTIONS π₯
say you've got 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 basically the same way, no cap:
$ llvm-exegesis --mode=uops --opcode-name=ADD64rr
$ llvm-exegesis --mode=inverse_throughput --opcode-name=ADD64rr
the output is a YAML document (default is writing 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, fr fr πΈ
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 β¨
Okay bestie, this is the big one β every flag, every value, no skips. Buckle up π
--helpβ prints a lil summary of all the command line options. That's it, that's the whole thing π--opcode-index=<LLVM opcode index>β picks the opcode you wanna measure, by its index. If you pass-1it literally measures every existing opcode (iconic behavior honestly). See example 1 for the deets. Heads up: you must set eitheropcode-index,opcode-nameorsnippets-fileβ pick at least one, no cap.--opcode-name=<opcode name 1>,<opcode name 2>,...β same vibe but you pick the opcode(s) by name instead. You can list several as a comma-separated list. See example 1. And yeah β eitheropcode-index,opcode-nameorsnippets-filemust be set. One of the three, fr.--snippets-file=<filename>β here's where you hand it your own custom code snippet to measure. See example 2 for the whole rundown. And once again bestie: eitheropcode-index,opcode-nameorsnippets-filemust be set. π«Ά--mode=[latency|uops|inverse_throughput|analysis]β picks the run mode. Ngl, some modes come with extra requirements and options, so read the fine print:latencymode can make use of either RDTSC or LBR.latency[LBR]is only available on X86 (at least Skylake). To run in latency mode, you gotta 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=.
--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β¦ and that means we have to actually be running on the hardware the snippet was generated for, and that hardware has to support performance measurements π. But! You can stop at some stage before measuring. The choices:prepare-snippetβ only generates the minimal instruction sequence.prepare-and-assemble-snippetβ same asprepare-snippet, but it also dumps an excerpt of the sequence (hex encoded).assemble-measured-codeβ same asprepare-and-assemble-snippet, but it also creates the full sequence that can be dumped to a file using--dump-object-to-disk.measureβ same asassemble-measured-code, but it also runs the measurement.
--x86-lbr-sample-period=<nBranches/sample>β sets the LBR sampling period, aka how many branches go by before we take a sample. When you give this a positive value and the mode islatency, we'll use LBRs for measuring β¨. On picking the "right" sampling period: small values are preferred, but throttling can happen if the sampling is too frequent. Use a prime number so you don't consistently skip certain blocks π--x86-disable-upper-sse-registersβ using the upper xmm registers (xmm8-xmm15) forces a longer instruction encoding, which can put more pressure on the frontend fetch and decode stages, potentially lowering the rate instructions get dispatched to the backend β especially on older hardware. Comparing baseline results with this mode enabled helps you figure out the frontend's effects, and it can be used to improve latency and throughput estimates π--repetition-mode=[duplicate|loop|min]β picks the repetition mode:duplicatecreates a large, straight-line basic block withnum-repetitionsinstructions (repeating the snippetnum-repetitions/snippet sizetimes).loopoptionally duplicates the snippet until the loop body contains at leastloop-body-sizeinstructions, then wraps the result in a loop that executesnum-repetitionsinstructions (so again, repeating the snippetnum-repetitions/snippet sizetimes). Loop mode, especially with loop unrolling, tends to hide the effects of the CPU frontend better on architectures that cache decoded instructions β but it eats a register for counting iterations.- If you're doing analysis over many opcodes, it may be best to use
minmode instead, which runs each other mode and gives you the minimal measured result.
--num-repetitions=<Number of repetitions>β sets the target number of executed instructions. Real talk though: the actual repetition count of the snippet will benum-repetitions/snippet size. Higher values = more accurate measurements, but the benchmark gets longer π°οΈ--loop-body-size=<Preferred loop body size>β only does anything with-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 get the loop body cached in the CPU Op Cache / Loop Cache, which may have higher throughput than the CPU decoders β--max-configs-per-opcode=<value>β caps how many configurations can be generated for each opcode. Default is1, meaning we assume a single measurement is enough to characterize an opcode. That assumption isn't true for every instruction β for example, the performance characteristics of theLEAinstruction on X86 depend on the value of assigned registers and immediates. Setting-max-configs-per-opcodelarger than1lets llvm-exegesis explore more configurations and discover whether some register or immediate assignments lead to different performance characteristics π¦--benchmarks-file=</path/to/file>β the file to read (analysis mode) or write (latency/uops/inverse_throughputmodes) benchmark results."-"uses stdin/stdout π«Ά--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 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 get analysed, but sometimes you only wanna look at the ones that don't involve memory, or the other way around. This option lets you keep everything, or filter out (ignore) all the ones that do involve memory (instructions that may read or write to memory), or the opposite β keep only those benchmarks π--analysis-clustering=[dbscan,naive]β picks the clustering algorithm. DBSCAN is the default. The naive clustering algorithm is better if you're gonna do further work on the-analysis-inconsistencies-output-file=output β it creates one cluster per opcode and checks that the cluster is stable (all points are neighbours) β¨--analysis-numpoints=<dbscan numPoints parameter>β sets the numPoints parameter used for DBSCAN clustering (analysis mode, DBSCAN only).--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 to detect when the cluster differs 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 clustered together when their measured performance characteristics differ. By default all such opcodes get filtered out. This flag instead shows only those unstable opcodes π--ignore-invalid-sched-class=falseβ if set, ignore instructions that don't have a sched class (class idx = 0).--mtriple=<triple name>β the target triple. Check-versionfor the available targets π--mcpu=<cpu name>β if set, measures the cpu characteristics using the counters for this CPU. Super useful when you're creating new sched models (aka when the host CPU is unknown to LLVM). (-mcpu=helpfor details) π§--analysis-override-benchmark-triple-and-cpuβ by default, llvm-exegesis analyses the benchmarks for the triple/CPU they were measured for. But if you wanna analyse them for some other combination (specified via-mtriple/-mcpu), just pass this flag π--dump-object-to-disk=trueβ if set, llvm-exegesis dumps the generated code to a temporary file so you can inspect it. Disabled by default.--use-dummy-perf-countersβ if set, llvm-exegesis won't read any real performance counters and returns a dummy value instead. Use it to make sure a snippet doesn't crash when hardware performance counters aren't available, and for debugging llvm-exegesis itself π--execution-mode=[inprocess,subprocess]β specifies which execution mode to use.inprocessis the default. Thesubprocessexecution mode allows extra features like memory annotations, but it's currently restricted to X86-64 on Linux π₯--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 π
π¦ EXIT STATUS π¦
llvm-exegesis returns 0 on success. Otherwise, an error message gets printed to standard error, and the tool returns a non 0 value. Simple as that, bestie π
π Author π
Maintained by the LLVM Team (https://llvm.org/). Slay.
π Copyright π
2003-2026, LLVM Project
And that's a wrap on LLVM-EXEGESIS(1) π¦ β this page is from the LLVM source, version 15, dated 2026-09-09, and honestly? She ate. Go benchmark something iconic, bestie. Periodt. πβ¨
π¦ where this page comes from
- ubuntu stonking: llvm-18 1:18.1.8-20ubuntu11 Β· 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