Unable to collect llvm statistics with `-C llvm-args=--stats`
Open
Nobody has claimed this yet.
A-LLVM
C-bug
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I'd like Rust to dump standard LLVM compiler statistics via
$ cat test.rs
#[no_mangle]
pub fn foo(v: &[i32], n: usize) -> i32 {
let mut ans = 0;
for i in 0..n {
ans += v[i];
}
ans
}
$ rustc --crate-type=rlib -O -C target-cpu=native -C llvm-args=--stats test.rs
but this does not work (output is empty).
This
$ rustc --crate-type=rlib -O -C target-cpu=native --emit=llvm-ir test.rs
$ ~/rust/build/x86_64-unknown-linux-gnu/ci-llvm/bin/opt test.ll --stats -O2 -o test.bc
===-------------------------------------------------------------------------===
... Statistics Collected ...
===-------------------------------------------------------------------------===
6 aa - Number of NoAlias results
12 basicaa - Number of times a GEP is decomposed
1 count-visits - Max number of times we visited a function
4 globalsmodref-aa - Number of functions that do not access memory
...
works but of course is irrelevant because opt's pipeline is unrelated to rustc.
I tried both stable:
$ rustc --version
rustc 1.87.0 (17067e9ac 2025-05-09)
and nightly
$ rustc --version
rustc 1.89.0-nightly (6ccd44760 2025-06-08)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the shown rustc commands using test.rs, then compare the empty output from -C llvm-args=--stats with the statistics produced by opt on test.ll. Trace rustc's LLVM compilation entry point and determine where the statistics flag is lost or suppressed. Done means rustc emits LLVM statistics for its own compilation pipeline.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100