RE: https://hachyderm.io/@folkertdev/117637096813697288
In light of this, I'm looking for code bases (that compile to binaries) that make serious use of `dyn Trait` to benchmark the LLVM changes with.
So, if you have any of those, let me know
RE: https://hachyderm.io/@folkertdev/117637096813697288
In light of this, I'm looking for code bases (that compile to binaries) that make serious use of `dyn Trait` to benchmark the LLVM changes with.
So, if you have any of those, let me know
I wrote up an update on the virtual function elimination feature
https://github.com/rust-lang/rust/issues/68262#issuecomment-6930708339
When using `&dyn Trait`, this feature removes virtual functions that never get called, and may turn virtual calls back into direct calls if there is only one possible option. The idea is that you get the upsides of `dyn Trait` with less of the downsides.
But, rustc currently gives incomplete information to LLVM, causing it to miscompile. The LLVM implementation is also clearly meant for C++, and doesn't handle what rust gives it well in all cases.
So, let's fix that!
Finally, it's done! C-variadic function definitions will be in rust 1.99.0
https://github.com/rust-lang/rust/pull/155697
I started working on this ~ a year ago, it tooks dozens of PRs and many hours of staring at Clang/LLVM source and assembly. The tracking issue is from 2017, and now it's finally here.
Zlib-rs is now used for gzip en/decoding in Firefox:
https://trifectatech.org/blog/zlib-rs-in-firefox/
This has safety and performance advantages. We also ran into a CPU bug that the Mozilla engineers ultimately found a workaround for.
I too will be at #RustWeek
Come watch my talk on stabilizing features:
https://2026.rustweek.org/talks/folkert/
And I'm happy to chat about my work on c-variadic functions, guaranteed tail calls, zlib-rs, SIMD, and any other low-level shenanigans
The `cfg_select` macro is finally stable in today's rust 1.95 release
https://blog.rust-lang.org/2026/04/16/Rust-1.95.0/
It's a flexible way of picking an implementation based on information known at compile time, like the current target or a cargo feature.
I worked on the implementation of this macro in the compiler and pushing for its stabilization (updating tests, docs, the reference, etc.)
On rust nightly you can now cfg on the current object format
https://github.com/rust-lang/rust/pull/155126
This is useful for e.g. selecting the right section name for #[link_section = "..."] and more generally for inline assembly and linker shenanigans.
The rust flate2 crate will make zlib-rs the default soon
https://github.com/rust-lang/flate2-rs/pull/542
Making zlib-rs the default is a free performance boost for the rust ecosystem. You can always switch back to the old default of miniz_oxide if you do encounter issues (though please let us know if you do, we should fix those!)
The message on an invalid target feature now suggests the most similar valid target feature names, for when it's been a while and you can't quite remember the exact target feature name.
https://github.com/rust-lang/rust/pull/153966
You can often make improvements like this by pattern matching on the surrounding code, you should give it a go when there are errors you run into that could be more helpful.
Miri and const-eval can now execute c-variadic functions
https://github.com/rust-lang/rust/pull/150601
That's the last major technical hurdle for c-variadic functions. Time to stabilize this thing!
I've implemented a `simd_splat` intrinsic, a function that puts the same value in each SIMD lane. LLVM wasn't handling the previous workaround (a manual shuffle) very well.
https://github.com/rust-lang/rust/pull/151346
the intrinsic is now used by stdarch and portable_simd:
- https://github.com/rust-lang/stdarch/pull/2003
- https://github.com/rust-lang/portable-simd/pull/501
This intrinsic fixes a bunch of long-standing optimization issues, and appears to have sped up compile times for some crates too.
TIL that cargo nextest has partitioning, no idea how I missed that so far. It's a total game changer for Miri tests (useful, but so slow). For portable_simd it reduced CI times from 75 minutes to 20
Neat, `cfg_asm` made it to stable.
I implemented this somewhere last year. It's a niche feature, but useful when writing assembly with some subtle target-specific variations. The cortex-m crate ran into this and currently uses a hack with a custom macro that duplicates the full assembly call on each condition.
With x86 support merged I believe the only commonly-used backend that does not support byval arguments in tail calls is RISC-V.
https://github.com/llvm/llvm-project/pull/170547
I've been keeping track of tail call support here:
https://github.com/rust-lang/rust/issues/148748#issuecomment-3508853168
I fixed x86 tail calls in LLVM
https://github.com/llvm/llvm-project/pull/168956
Tail calls passing structs had been broken since forever, and it made me mad enough to write C++.
It's a little tricky because sometimes it requires shuffling values around on the stack and you have to make sure to not overwrite values you'll need later. This was fixed in the arm backend a while ago, and I was able to port that approach to the x86 backend. The plan is to include this in LLVM 22.
Together with some other changes it seems like guaranteed tail calls in rust might actually, finally happen.
I made a small improvement so that deprecated messages now render intra-doc links (for when you suggest some other function to use)
The adler32 checksum algorithm introduces a (seemingly useless) multiplication by 1 so that it can use a VPMADDWD widening multiply + add instruction.
After a recent change to stdarch, the multiplication got optimized out before that instruction could be selected, leading to much worse performance.
So I added some logic that adds the multiplication if that is the only thing stopping the more optimal instruction from being selected.
https://github.com/llvm/llvm-project/pull/174149/changes
(the stdarch change was reverted for now, but with LLVM 22 we can re-land it without regressing performance)
Another massive step towards stabilizing c-variadic functions got merged:
https://github.com/rust-lang/rust/pull/141980
The rust `VaList` is actually ABI-compatible with C now.
I made another fun LLVM fix
https://github.com/llvm/llvm-project/pull/169591
Making these changes is hard but the reviewers have been extremely helpful in polishing the implementation.
Fixing small missed optimizations like this is useful for rust because it allows e.g. miri to handle more SIMD code automatically.