LLVM-REDUCE(1)

πŸ’… LLVM-REDUCE β€” the llvm-reduce manual, but make it make sense

okay so bestie, welcome to LLVM-REDUCE(1) from the LLVM manual set ✨ this is the page for llvm-reduce, and by the end you're gonna be obsessed, trust.

🌸 NAME 🌸

llvm-reduce β€” the LLVM automatic testcase reducer. yes, that's her whole job. iconic.

πŸ¦‹ SYNOPSIS πŸ¦‹

llvm-reduce [options] [input...]

✨ DESCRIPTION ✨

so llvm-reduce is this tool that shrinks your LLVM test cases down to size πŸ’– it does it by yeeting redundant or unnecessary code out of your test cases, while still preserving their ability to detect bugs. like, the whole point is that the bug stays caught. no cap.

if input is -, llvm-reduce reads from standard input. otherwise it reads from the filenames you gave it. simple as that.

basically it's the useful tool for reducing the size and complexity of LLVM test cases, which makes it way easier to identify and debug issues in the LLVM compiler infrastructure. it's giving "less is more" and honestly? slay.


πŸŽ€ GENERIC OPTIONS πŸŽ€

  • --help β€” display available options. there's also --help-hidden for more, if you're nosy like me πŸ™ˆ
  • --abort-on-invalid-reduction β€” abort if any reduction results in invalid IR
  • --in-place β€” ⚠️ WARNING: this option will replace your input file with the reduced version! like she will literally eat your original file. back it up first bestie, i'm begging 😭
  • --ir-passes=<string> β€” a textual description of the pass pipeline, same as what's passed to opt -passes
  • -j <uint> β€” maximum number of threads to use to process chunks. set it to 1 to disable parallelism
  • --max-pass-iterations=<int> β€” maximum number of times to run the full set of delta passes (default=5)
  • --mtriple=<string> β€” set the target triple
  • --preserve-debug-environment β€” don't disable features used for crash debugging (crash reports, llvm-symbolizer and core dumps)
  • --print-delta-passes β€” print the list of delta passes, passable to --delta-passes as a comma separated liste (that's their spelling, not mine πŸ’…)
  • --skip-delta-passes=<string> β€” delta passes to not run, separated by commas. by default, run all delta passes
  • --starting-granularity-level=<uint> β€” number of times to divide chunks prior to first test.
note: granularity refers to the level of detail at which the reduction process operates. a lower granularity means the reduction process operates at a more coarse-grained level, while a higher granularity means it operates at a more fine-grained level. iykyk 🧚
  • --test=<string> β€” name of the interesting-ness test to be run
  • --test-arg=<string> β€” arguments passed onto the interesting-ness test
  • --verbose β€” print extra debugging information
  • --write-tmp-files-as-bitcode β€” always write temporary files as bitcode instead of textual IR
  • -x={ir|mir} β€” input language, as ir or mir

⭐ EXIT STATUS ⭐

llvm-reduce returns 0 under normal operation. it returns a non-zero exit code if there were any errors. that's the whole vibe check πŸ’€

πŸ”₯ EXAMPLE πŸ”₯

llvm-reduce can be used to simplify a test that causes a compiler crash. (yes, this is the good part, stay with me 🫢)

for example, let's assume that opt is crashing on the IR file test.ll with error message Assertion failed at line 1234 of WhateverFile.cpp, when running at -O2.

the test case of test.ll can be reduced by invoking the following command:

$(LLVM_BUILD_FOLDER)/bin/llvm-reduce --test=script.sh <path to>/test.ll

the shell script passed to the option test consists of the following:

$(LLVM_BUILD_FOLDER)/bin/opt -O2 -disable-output $1 \
  |& grep "Assertion failed at line 1234 of WhateverFile.cpp"

(in this script, grep exits with 0 if it finds the string and that becomes the whole script's status.)

this example can be generalized to other tools that process IR files, for example llc. main character energy, honestly πŸ‘‘


πŸ‘‘ AUTHOR πŸ‘‘

maintained by the LLVM Team (https://llvm.org/).

2003-2025, LLVM Project


k that's the whole page, you ate that πŸ“ and just so you have the receipts: this was LLVM's LLVM-REDUCE(1) page, LLVM version 19, dated 2025-01-17. go forth and reduce, bestie πŸ’œ

πŸ“¦ where this page comes from