LoongLint (also stylized as "loonglint" and "LOONGLINT" in the source code) checks LoongArch binaries for common optimizable peephole patterns.
This is a peephole linter for LoongArch{32S,64} ELF and raw binaries. It scans the input binary, linearly, for pre-defined patterns that are often optimizable. For example, the following two-instruction sequences can be fused into one:
addi.d $t0, $t0, 8
ld.d $t0, $t0, 0
# ->
ld.d $t0, $t0, 8For a list of implemented peephole rules, please refer to RULES.md.
Note that due to the intrinsic limitation of linear scan, there might be false positives due to unrecognized entries. Please take the lint results with a grain of salt.
This project is inspired by gaul/armlint. The disassembly and analysis infrastructure is provided by LLVM. Matching is done by a BOLT-inspired DSL.
The following is a list of optimization opportunities found with the help of LoongLint. Note that this list is not complete and will be amended from time to time.
- Bug 2066681: Stop generating no-op self addi.d
- Bug 2066686: Fuse or32+not32 into NOR in EmitInitDependentStringBase
- Bug 2067472: Refactor to use a more idiomatic
move-ing pattern - Bug 2067473: Optimize BaseIndex-shaped ma_{load,store} with offset == 0 and scale == 1
Get a modern C++ toolchain that supports C++20. If your compiler can build modern LLVM, it's likely usable here as well.
Set the variable LLVM_PROJECT to a source clone of https://github.com/llvm/llvm-project/. At the time of writing, the developing LLVM version is 24.0.0. LoongLint should also compile with not-too-older trees, like LLVM 23 and 22.
cd loonglint
cmake \
-S "$LLVM_PROJECT"/llvm \
-B build \
-G Ninja \
-DLLVM_EXTERNAL_PROJECTS='loonglint' \
-DLLVM_EXTERNAL_LOONGLINT_SOURCE_DIR="$(pwd)" \
-DLLVM_TARGETS_TO_BUILD='LoongArch' \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
ninja -C buildCopyright (c) 2026 Rong Bao <rong.bao@csmantle.top>.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
Some parts of the program are Derivative Works of the LLVM source. Each of such source is indicated by special comment headers. Please see LICENSE-LLVM for licensing information of such content.
The icon for this project ("the LoongLint logo") is a Modified Version of the Noto Emoji Fonts (https://github.com/googlefonts/noto-emoji). Noto Emoji Fonts are authored by Google LLC and licensed under the SIL Open Font License Version 1.1. Thus, the LoongLint logo is also licensed under the OFL v1.1. Other files under assets/icon/ are the Original Version of Noto Emoji Fonts to preserve provenance.